1

我正在尝试将一些 rake 任务添加到 Octopress Rakefile,并且我想将这些任务放在另一个子 rakefile 中,但是当我导入子 rakefile 时,它​​们无法访问 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')

这是错误:

耙中止!main:Object 的未定义局部变量或方法“source_dir”

4

1 回答 1

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')
于 2013-05-11T09:45:03.420 回答