Module: Nutils::Helpers::Rules
- Defined in:
- lib/nutils/helpers/rules.rb
Overview
Provides some helper functions to process Rules.
Instance Method Summary collapse
-
#load_rules(filepath) ⇒ Proc
Compiles the content as a set of Nanoc rules.
Instance Method Details
#load_rules(filepath) ⇒ Proc
Compiles the content as a set of Nanoc rules. Tries to use the rules_dir attribute from the Config.yaml. If rules_dir is not defined, it uses “.” as a base path.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/nutils/helpers/rules.rb', line 27 def load_rules(filepath) raise "You should upgrade to nanoc 3.2.1 to run the load_rules helper properly" if Gem.loaded_specs["nanoc3"].version == Gem::Version.create('3.2') rules_dir = if Gem.loaded_specs["nanoc3"].version >= Gem::Version.create('3.1') and Gem.loaded_specs["nanoc3"].version < Gem::Version.create('3.2') (@site.config[:rules_dir] || ['.']) else @config[:rules_dir] || ['.'] end path = rules_dir.map do |dir| Dir[File.join(dir, filepath)].each { |filename| filename } end.flatten if path.length > 1 puts "\e[1mwarning\e[0m Multiple matches for #{filepath}:", " #{path.join("\n ")}", " \e[1mused\e[0m #{path[0]}" elsif path.length == 0 raise Nutils::Errors::NoRulesFileFound.new(filepath) end instance_eval(File.read(path[0]), path[0]) end |