我正在尝试将一些rake任务添加到Octopress Rakefile中,并且我想将这些任务放在另一个子rakefile中,但是当我导入子rakefiles时,他们无法访问顶部的常量。 rakefile。
我用以下内容导入子rakefile:
Dir.glob('rakefiles/*.rake').each { |r| import r }
这是我无法在子文件中读取的那种配置:
public_dir = "public" # compiled site directory
source_dir = "source" # source file directory
blog_index_dir = 'source' # directory for your blog's index page (if you put your index in source/blog/index.html, set this to 'source/blog')
这是错误:
耙子流产了!未定义的局部变量或方法`source_dir' 主:对象
答案 0 :(得分:2)
您需要使用类变量,如
@public_dir = "public" # compiled site directory
@source_dir = "source" # source file directory
@blog_index_dir = 'source' # directory for your blog's index page (if you put your index in source/blog/index.html, set this to 'source/blog')
或常量
PUBLIC_DIR = "public" # compiled site directory
SOURCE_DIR = "source" # source file directory
BLOG_INDEX_DIR = 'source' # directory for your blog's index page (if you put your index in source/blog/index.html, set this to 'source/blog')