diff --git a/lib/glyph/document.rb b/lib/glyph/document.rb index bad3d56..e70e623 100644 --- a/lib/glyph/document.rb +++ b/lib/glyph/document.rb @@ -149,9 +149,8 @@ def finalize @topics.each do |t| t[:contents].gsub! key_s, value_s end - else - @output.gsub! key_s, value_s end + @output.gsub! key_s, value_s rescue Glyph::MacroError => e e.macro.macro_warning e.message, e rescue Exception => e diff --git a/lib/glyph/macro_helpers.rb b/lib/glyph/macro_helpers.rb index 52c11a6..5ee03d4 100644 --- a/lib/glyph/macro_helpers.rb +++ b/lib/glyph/macro_helpers.rb @@ -103,6 +103,7 @@ def toc_element_for(depth, title, procs={}) added_headers ||= [] n1.descend do |n2, level| if n2.is_a?(Glyph::MacroNode) && Glyph['system.structure.headers'].include?(n2[:name]) then + next if Glyph.multiple_output_files? && !n2.attribute(:src) # Only consider topics when building TOC for web/web5 next if n2.find_parent{|node| Glyph['system.structure.special'].include? node[:name] } header_hash = n2[:header] next if depth && header_hash && (header_hash.level-1 > depth.to_i) || header_hash && !header_hash.toc? @@ -141,7 +142,7 @@ def section_element_for(procs={}) end end ident = (attr(:id) || "h_#{@node[:document].headers.length+1}").to_sym - bmk = header :title => attr(:title), :level => level, :id => ident, :toc => !attr(:notoc), :file => @source_file + bmk = header :title => attr(:title), :level => level, :id => ident, :toc => !attr(:notoc), :file => attr(:src) || @source_file @node[:header] = bmk h = procs[:title].call level, bmk, attr(:title) end @@ -152,11 +153,10 @@ def section_element_for(procs={}) layout = attr(:layout) || Glyph['document.topic_layout'] || :topic layout_name = "layout:#{layout}".to_sym macro_error "Layout '#{layout}' not found" unless Glyph::MACROS[layout_name] - @node[:change_topic] = true result = interpret %{#{layout_name}[ @title[#{attr(:title)}] @id[#{topic_id}] - @contents[include[#{attr(:src)}]] + @contents[include[@topic[true]#{attr(:src)}]] ]} # Fix file for topic bookmark @node[:document].bookmark?(topic_id).file = attr(:src) diff --git a/macros/core.rb b/macros/core.rb index 18f42ee..0c3d517 100644 --- a/macros/core.rb +++ b/macros/core.rb @@ -78,7 +78,7 @@ end begin folder = Glyph.lite? ? "" : "text/" - topic = @node[:change_topic] ? folder+v : nil + topic = (attr(:topic) && Glyph.multiple_output_files?) ? folder+v : nil update_source v, folder+v, topic interpret contents rescue Glyph::MutualInclusionError => e diff --git a/macros/html/structure.rb b/macros/html/structure.rb index 2d12259..881069c 100644 --- a/macros/html/structure.rb +++ b/macros/html/structure.rb @@ -3,6 +3,7 @@ macro :section do max_parameters 1 level = (raw_attribute(:src) && Glyph.multiple_output_files?) ? :error : :warning + within :contents if Glyph.multiple_output_files? required_attribute :title, :level => level procs = {} procs[:title] = lambda do |level, ident, title| @@ -159,7 +160,7 @@ } end toc_item_proc = lambda do |classes, header| - "
  • #{header}
  • " + "
  • #{header}
  • " end toc_sublist_proc = lambda do |contents| "
    1. #{contents}
  • \n" @@ -172,15 +173,8 @@ end macro :contents do - interpret(@node.parameter(0).to_s) -end - -macro :topic do - within :contents - not_within :topic - required_attribute :src - required_attribute :title - interpret "include[#{attr(:src)}]" + result = interpret(@node.parameter(0).to_s) + Glyph.multiple_output_files? ? "" : result end # See: diff --git a/spec/files/web_doc.glyph b/spec/files/web_doc.glyph index e8f9b79..ab8b28c 100644 --- a/spec/files/web_doc.glyph +++ b/spec/files/web_doc.glyph @@ -4,6 +4,7 @@ document[ style[test.sass] ] body[ + toc[] contents[ section[ @title[Web Document] diff --git a/spec/lib/macro_validators_spec.rb b/spec/lib/macro_validators_spec.rb index 6238c04..a19e2b2 100644 --- a/spec/lib/macro_validators_spec.rb +++ b/spec/lib/macro_validators_spec.rb @@ -54,20 +54,25 @@ it "should validate required attributes" do Glyph['document.output'] = 'web' Glyph.run! 'load:macros' - lambda { output_for("contents[topic[test]]") }.should raise_error(Glyph::MacroError, "Macro 'topic' requires a 'src' attribute") + lambda { output_for("contents[section[@src[test]]]") }.should raise_error(Glyph::MacroError, "Macro 'section' requires a 'title' attribute") end it "should validate if a macro is within another one" do - Glyph['document.output'] = 'web' - Glyph.run! 'load:macros' - lambda { output_for("topic[@src[test]@title[test]]") }.should raise_error(Glyph::MacroError, "Macro 'topic' must be within a 'contents' macro") + define_em_macro + Glyph.macro :within_m do + within :em + "---" + end + lambda { output_for("within_m[test]") }.should raise_error(Glyph::MacroError, "Macro 'within_m' must be within a 'em' macro") end it "should validate if a macro is not within another one" do - Glyph['document.output'] = 'web' - Glyph.run! 'load:macros' - lambda { output_for("contents[topic[@src[test]@title[test]topic[@src[test]@title[test]]]]") }.should - raise_error(Glyph::MacroError, "Macro 'topic' must not be within a 'topic' macro") + define_em_macro + Glyph.macro :within_m do + not_within :em + "---" + end + lambda { output_for("em[within_m[test]]") }.should raise_error(Glyph::MacroError, "Macro 'within_m' must not be within a 'em' macro") end end diff --git a/spec/macros/macros_spec.rb b/spec/macros/macros_spec.rb index 2cf3d4a..43769ff 100644 --- a/spec/macros/macros_spec.rb +++ b/spec/macros/macros_spec.rb @@ -99,8 +99,8 @@

    Table of Contents

      -
    1. Container section
    2. -
    3. Markdown
    4. +
    5. Container section
    6. +
    7. Markdown
    }.gsub(/\n|\t/, '') diff --git a/spec/macros/web_spec.rb b/spec/macros/web_spec.rb index a9b7974..cb2691e 100644 --- a/spec/macros/web_spec.rb +++ b/spec/macros/web_spec.rb @@ -18,6 +18,7 @@ it "section (topic)" do lambda { output_for("contents[section[@src[test]]]") }.should raise_error(Glyph::MacroError, "Macro 'section' requires a 'title' attribute") + lambda { output_for("section[@src[test]]") }.should raise_error(Glyph::MacroError, "Macro 'section' must be within a 'contents' macro") interpret("contents[section[@src[a/web1.glyph]@title[Test]]]") topic = @p.document.topics[0] topic.blank?.should == false @@ -39,4 +40,23 @@ web2.match(%{}).blank?.should == false end + it "toc should only list topics" do + Glyph.run! 'generate:web' + index = Glyph.file_load(Glyph::PROJECT/'output/web/index.html') + index.match(%{
  • Web Document
  • }).blank?.should == true + index.match(%{href="a/web1.html#h_2"}).blank?.should == false + index.match(%{href="a/b/web2.html#h_6"}).blank?.should == false + delete_project + reset_quiet + create_web_project + Glyph['document.output'] = 'html' + Glyph.run! 'generate:html' + index = Glyph.file_load(Glyph::PROJECT/'output/html/test_project.html') + index.match(%{href="a/web1.html#h_2"}).blank?.should == true + index.match(%{href="a/b/web2.html#h_6"}).blank?.should == true + index.match(%{
  • Web Document
  • }).blank?.should == false + index.match(%{href="#h_2"}).blank?.should == false + index.match(%{href="#h_7"}).blank?.should == false # Header numbers are different... + end + end