lib/masterview/template_spec.rb in masterview-0.3.3 vs lib/masterview/template_spec.rb in masterview-0.3.4

- old
+ new

@@ -2,12 +2,24 @@ # TemplateSpec is a class which contains the information about how to build a # template. It contains the information on all the parts that make up the template # and the status of them (whether they are up to date or out of sync). class TemplateSpec + include Analyzer::Common + include DirectiveHelpers attr_accessor :path, :status, :message, :gen_parts, :build_list + # setup a class instance gen_partial_re that is created on use so that namespace is already setup + class << self + attr_accessor :gen_partial_regex_cached + + def gen_partial_re + self.gen_partial_regex_cached ||= Regexp.new( + "#{DirectiveRegistry.current.mv_namespace_prefix}gen_partial\\s*=\\s*((\")([^\"]*)\"|(')([^']*'))" ) + end + end + class Status OK = 'OK' ImportsOutdated = 'Imports(s) outdated' Conflicts = 'Conflict(s)' InvalidXHTML = 'Invalid XHTML' @@ -114,14 +126,41 @@ out = [] builder = MasterView::Analyzer::Builder.new(content_hash) @build_list.each do |li| #Log.debug { li.inspect } con = builder.data(li.name, li.index) + + unless li.page_attributes.empty? # if we have page_attributes, reinsert them now, currently only inserting for partials + gpmatch = TemplateSpec.gen_partial_re.match(con) + + if gpmatch + gen_partial_all = gpmatch[0] + gp_quote_char = gpmatch[2] || gpmatch[4] + gen_partial_fullattr = gpmatch[3] || gpmatch[5] + + # determine what partial page we are rendering to see if we have any page specific attributes + partial = find_string_val_in_string_hash(gen_partial_fullattr, :partial) + if partial + partial_pa = li.page_attributes[partial] # retrieve page specific attribute by file name + if partial_pa # if we have one, replace it in the text + mv_ns = DirectiveRegistry.current.mv_namespace_prefix + con.gsub! TemplateSpec.gen_partial_re, "#{mv_ns}gen_partial=#{gp_quote_char}#{partial_pa}#{gp_quote_char}" + end + end + end + +# sorted_page_att_arr = li.page_attributes.sort{ |a,b| a[0].to_s <=> b[0].to_s } #[[a, 2], [b, 1]] +# sorted_page_att = sorted_page_att_arr.collect{ |a| "#{a[0]}=\"#{a[1]}\"" } # a="2" +# pg_att_ins = sorted_page_att.join(' ') +# mv_ns = DirectiveRegistry.current.mv_namespace_prefix +# con.gsub! "#{mv_ns}gen_partial", "#{pg_att_ins} #{mv_ns}gen_partial" + + #Log.debug { con.inspect } + end + if li.import - mv_ns = DirectiveRegistry.current.mv_namespace_prefix - con = con.gsub mv_ns+'generate', mv_ns+'import' - con.gsub! mv_ns+'gen_partial', mv_ns+'import_render' + con = convert_non_import_to_import_dirs(con) #gsub mv:gen_partial to mv:import_render and mv:generate to mv:import end out << con end template = out.join if options[:write_to_file] @@ -174,10 +213,10 @@ to_spec = TemplateSpec.new to_spec.build_list = [] li = from_spec.build_list.first li.import = true to_spec.build_list << li - to_spec.build_list << MasterView::Analyzer::ListEntry.new('empty_shell_contents', -1, false) + to_spec.build_list << MasterView::Analyzer::ListEntry.new('empty_shell_contents', -1, false, {} ) li = from_spec.build_list.last li.import = true to_spec.build_list << li to_spec.rebuild_template(content_hash) end