lib/masterview/analyzer.rb in masterview-0.1.5 vs lib/masterview/analyzer.rb in masterview-0.2.0

- old
+ new

@@ -3,16 +3,16 @@ ExpandAlwaysElements = %w{ script textarea } module Common def calc_hash(data) - #data.gsub( /\s+/, '' ).hash - data.hash + #MasterView::Log.warn { 'hash= '+data.hash.to_s+' data='+data } + data.gsub( /\s+/, ' ' ).hash #collapse whitespace end def src_hash(data_orig) - data = data_orig.gsub MasterView::NamespacePrefix+'import_render', MasterView::NamespacePrefix+'gen_render' + data = data_orig.gsub MasterView::NamespacePrefix+'import_render', MasterView::NamespacePrefix+'gen_partial' data = data.gsub MasterView::NamespacePrefix+'import', MasterView::NamespacePrefix+'generate' calc_hash(data) end end @@ -77,13 +77,14 @@ end def data(name, index) content = '' content_parts = @content_hash[name] + content_parts_length = (content_parts) ? content_parts.length : 0 next_index_to_use = (nind = @builder_hash[name]) ? nind : 0 - next_index_to_use = 0 if (-1 == index) && (next_index_to_use+1 > content_parts.length) # allow -1 to rerequest part as needed (singlefile) - return '' if content_parts.nil? || (next_index_to_use+1 > content_parts.length) + next_index_to_use = 0 if (-1 == index) && (next_index_to_use+1 > content_parts_length) # allow -1 to rerequest part as needed (singlefile) + return '' if content_parts.nil? || (next_index_to_use+1 > content_parts_length) highest_index = content_parts.length - 1 requested_index = (index == -1) ? highest_index : index content = content_parts[next_index_to_use..requested_index].collect do |ce| (ce.data.gsub( /\s/, '' ).empty?) ? '' : ce.data # if only white space then get rid of it end.join @@ -104,10 +105,13 @@ @list = [] @content = options[:content_hash] || {} @options = options @only_check_hash = options[:only_check_hash] || false @builder = Builder.new(@content) + @default_extname = options[:default_extname] || ::MasterView::IOMgr.erb.default_extension + @keyword_expander = KeywordExpander.new + @keyword_expander.set_template_pathname( options[:template_pathname], @default_extname ) if options[:template_pathname] Log.debug { "only_check_hash => true" } if @only_check_hash end def only_check_hash? @only_check_hash @@ -129,36 +133,42 @@ unescape_attributes!(attributes) @depth += 1 import = false if attributes[::MasterView::NamespacePrefix+'generate'] - path = attributes[::MasterView::NamespacePrefix+'generate'] - elsif attributes[::MasterView::NamespacePrefix+'gen_render'] - partial = find_string_val_in_string_hash( attributes[::MasterView::NamespacePrefix+'gen_render'], :partial) - path = render_partial_name_to_file_name(partial) + path = @keyword_expander.expand_keywords(attributes[::MasterView::NamespacePrefix+'generate']) + attributes[::MasterView::NamespacePrefix+'generate'] = path # put back expanded version in case of rebuilding + elsif attributes[::MasterView::NamespacePrefix+'gen_partial'] + expanded_partial_attr = @keyword_expander.expand_keywords(attributes[::MasterView::NamespacePrefix+'gen_partial']) + attributes[::MasterView::NamespacePrefix+'gen_partial'] = expanded_partial_attr # put back expanded version in case of rebuilding + partial = find_string_val_in_string_hash( expanded_partial_attr, :partial) + path = render_partial_name_to_file_name(partial, @default_extname) elsif attributes[::MasterView::NamespacePrefix+'import'] - path = attributes[::MasterView::NamespacePrefix+'import'] + path = @keyword_expander.expand_keywords(attributes[::MasterView::NamespacePrefix+'import']) + attributes[::MasterView::NamespacePrefix+'import'] = path # put back expanded version in case of rebuilding import = true elsif attributes[::MasterView::NamespacePrefix+'import_render'] - partial = find_string_val_in_string_hash( attributes[::MasterView::NamespacePrefix+'import_render'], :partial) - path = render_partial_name_to_file_name(partial) + expanded_partial_attr = @keyword_expander.expand_keywords(attributes[::MasterView::NamespacePrefix+'import_render']) + attributes[::MasterView::NamespacePrefix+'import_render'] = expanded_partial_attr # put back expanded version in case of rebuilding + partial = find_string_val_in_string_hash( expanded_partial_attr, :partial) + path = render_partial_name_to_file_name(partial, @default_extname) import = true end if path store_last_buffer false @stack << StackEntry.new(path, @depth, import) end unless @stack.empty? @stack.last.buffer << "<#{qname}" - sorted_attributes = attributes.sort do |a,b| # sort import and import_render like generate and gen_render so hashs work + sorted_attributes = attributes.sort do |a,b| # sort import and import_render like generate and gen_partial so hashs work a_working = a[0] b_working = b[0] working_cmp = [a_working, b_working].collect do |working| if working == ::MasterView::NamespacePrefix+'import_render' - working = ::MasterView::NamespacePrefix+'gen_render' + working = ::MasterView::NamespacePrefix+'gen_partial' elsif working == ::MasterView::NamespacePrefix+'import' working = ::MasterView::NamespacePrefix+'generate' end working end @@ -191,10 +201,10 @@ else @stack.last.buffer << '</' << "#{qname}>" #must output </ as separate string so simplify_empty_elements can find it end end - if @depth == @stack.last.depth + if @stack.last && @depth == @stack.last.depth store_last_buffer true @stack.pop end @depth -= 1 end