macros/core.rb in glyph-0.3.0 vs macros/core.rb in glyph-0.4.0

- old
+ new

@@ -67,19 +67,21 @@ "" rescue Exception => e macro_warning e.message, e end else - if Glyph["filters.by_file_extension"] && !ext.in?(['rb','glyph']) then + if Glyph["options.filter_by_file_extension"] && !ext.in?(['rb','glyph']) then if Glyph::MACROS.include?(ext.to_sym) then contents = "#{ext}[#{contents}]" else macro_warning "Filter macro '#{ext}' not available" end end begin - update_source v + folder = Glyph.lite? ? "" : "text/" + topic = (attr(:topic) && Glyph.multiple_output_files?) ? folder+v : nil + update_source v, folder+v, topic interpret contents rescue Glyph::MutualInclusionError => e raise rescue Glyph::MacroError => e macro_warning e.message, e @@ -133,38 +135,43 @@ res = param(0) (res.blank? || res == "false") ? "" : param(1).to_s end macro :eq do + within :condition min_parameters 1 max_parameters 2 (param(0).to_s == param(1).to_s) ? true : nil end macro :not do + within :condition max_parameters 1 v = param(0).to_s (v.blank? || v == "false") ? true : nil end macro :and do + within :condition min_parameters 1 max_parameters 2 res_a = !param(0).blank? res_b = !param(1).blank? (res_a && res_b) ? true : nil end macro :or do + within :condition min_parameters 1 max_parameters 2 res_a = !param(0).blank? res_b = !param(1).blank? (res_a || res_b) ? true : nil end macro :match do + within :condition exact_parameters 2 val = param(0).to_s regexp = param(1).to_s macro_error "Invalid regular expression: #{regexp}" unless regexp.match /^\/.*\/[a-z]?$/ val.match(instance_eval(regexp)) ? true : nil @@ -182,22 +189,10 @@ @node.param(1).descend do |n, level| if n[:name] == macro_name then macro_error "Macro '#{macro_name}' cannot be defined by itself" end end - string = raw_param(1) - Glyph.macro macro_name do - s = string.dup - # Parameters - s.gsub!(/\{\{(\d+)\}\}/) do - raw_param($1.to_i).strip - end - # Attributes - s.gsub!(/\{\{([^\[\]\|\\\s]+)\}\}/) do - raw_attr($1.to_sym).strip - end - interpret s - end + Glyph.rewrite macro_name, raw_param(1).dup nil end macro_alias '--' => :comment macro_alias '&' => :snippet