Skip to content

Extend Rules DSL to support rules defined across files #65

@0x1eef

Description

@0x1eef

Hello! 👋

Is there an interest in having nanoc support the require of other files in the context of the Rules DSL ? To better organize the rules in one of my sites, I have organized them by file, and implemented require_rules to do that:

def require_rules(rules, locals = {}, target = binding)
  locals.each { target.local_variable_set(_1, _2) }
  path = File.join(Dir.getwd, rules)
  target.eval(
    if File.readable?(path)
      File.read(path)
    elsif File.readable?("#{path}.rb")
      File.read("#{path}.rb")
    elsif File.readable?("#{path}.rules")
      File.read("#{path}.rules")
    else
      raise LoadError, "#{path} is not readable"
    end
  )
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions