【问题标题】:How to break up rakefile?如何分解 rakefile?
【发布时间】:2013-05-11 09:18:01
【问题描述】:

我正在尝试将一些 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')

这是错误:

rake 中止!未定义的局部变量或方法“source_dir” 主要:对象

【问题讨论】:

    标签: ruby octopress rakefile


    【解决方案1】:

    您需要使用类变量,例如

    @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')
    

    【讨论】:

    • 这破坏了我避免从 Octopress 修改 Rakefile 的目标。但我确实看到了它是如何工作的。导出局部变量的任何通用方法?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多