Skip to content

Commit

Permalink
Added the possibility to force header level (3rd parameter).
Browse files Browse the repository at this point in the history
  • Loading branch information
h3rald committed Apr 26, 2010
1 parent 6a3aef3 commit 02f192c
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 36 deletions.
20 changes: 7 additions & 13 deletions book/output/html/glyph.html
Expand Up @@ -346,7 +346,7 @@
.CodeRay .del .del { color: #800; font-weight:bold }
.CodeRay .chg .chg { color: #66f; }
.CodeRay .head .head { color: #f4f; }



</style>
</head>
Expand Down Expand Up @@ -598,10 +598,9 @@ <h3 id="h_6">Resources</h3>
<h3 id="h_7">Changelog</h3>

<div class="section">
<h4 id="h_10">&ndash; Release 0.2.0</h4>
<div class="section">
<div class="section">
<h4 id="h_8">Implemented Features</h4>
<h5 id="h_10">&ndash; Release 0.2.0</h5>
<div class="section">
<h5 id="h_8">Implemented Features</h5>
<table>
<tr>
<th>
Expand Down Expand Up @@ -639,17 +638,12 @@ <h4 id="h_8">Implemented Features</h4>

</div>

</div>

</div>


<div class="section">
<h4 id="h_11">April 8th 2010 &ndash; Release 0.1.0</h4>
<div class="section">
Initial release.

</div>
<h5 id="h_11">April 8th 2010 &ndash; Release 0.1.0</h5>
Initial release.

</div>

Expand Down Expand Up @@ -1132,7 +1126,7 @@ <h4 id="h_23">Evaluating Ruby code and Configuration Settings</h4>
However, it is possible to evaluate simple ruby code snippets using the <code>ruby</code> macro (aliased to <code>%</code>), like this:</p>
<ul>
<li><code>%[2 + 2]</code> &rarr; 4</li>
<li><code>%[Time.now]</code> &rarr; Sun Apr 25 20:26:42 +0200 2010</li>
<li><code>%[Time.now]</code> &rarr; Mon Apr 26 11:06:36 +0200 2010</li>
<li><code>%[Glyph::VERSION]</code> &rarr; 0.1.0</li>
</ul>
<p>The scope for the code evaluation is the Kernel module, (with all inclusions required by Glyph itself).</p>
Expand Down
28 changes: 14 additions & 14 deletions glyph.gemspec
@@ -1,6 +1,6 @@
# Generated by jeweler
# DO NOT EDIT THIS FILE DIRECTLY
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
# Instead, edit Jeweler::Tasks in rakefile, and run the gemspec command
# -*- encoding: utf-8 -*-

Gem::Specification.new do |s|
Expand All @@ -9,7 +9,7 @@ Gem::Specification.new do |s|

s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Fabio Cevasco"]
s.date = %q{2010-04-25}
s.date = %q{2010-04-26}
s.default_executable = %q{glyph}
s.description = %q{Glyph is a framework for structured document authoring.}
s.email = %q{h3rald@h3rald.com}
Expand Down Expand Up @@ -117,24 +117,24 @@ Gem::Specification.new do |s|
s.homepage = %q{http://www.h3rald.com/glyph/}
s.rdoc_options = ["--charset=UTF-8"]
s.require_paths = ["lib"]
s.rubygems_version = %q{1.3.6}
s.rubygems_version = %q{1.3.5}
s.summary = %q{Glyph -- A Ruby-powered Document Authoring Framework}
s.test_files = [
"spec/macros/filters_spec.rb",
"spec/macros/textile_spec.rb",
"spec/macros/macros_spec.rb",
"spec/lib/commands_spec.rb",
"spec/lib/config_spec.rb",
"spec/lib/document_spec.rb",
"spec/lib/glyph_spec.rb",
"spec/lib/interpreter_spec.rb",
"spec/lib/commands_spec.rb",
"spec/lib/node_spec.rb",
"spec/lib/macro_spec.rb",
"spec/lib/macro_validators_spec.rb",
"spec/lib/config_spec.rb",
"spec/lib/glyph_spec.rb",
"spec/lib/document_spec.rb",
"spec/tasks/load_spec.rb",
"spec/lib/node_spec.rb",
"spec/macros/filters_spec.rb",
"spec/macros/macros_spec.rb",
"spec/macros/textile_spec.rb",
"spec/spec_helper.rb",
"spec/tasks/generate_spec.rb",
"spec/tasks/project_spec.rb",
"spec/spec_helper.rb"
"spec/tasks/load_spec.rb",
"spec/tasks/project_spec.rb"
]

if s.respond_to? :specification_version then
Expand Down
8 changes: 6 additions & 2 deletions lib/glyph/macro.rb
Expand Up @@ -59,9 +59,13 @@ def macro_warning(message)
def interpret(string)
@node[:source] = "#@name[#@value]"
@node[:source_name] = "#{@name}[...]"
@node[:embedded] = true
macro_error "Mutual inclusion", Glyph::MutualInclusionError if @node.find_parent {|n| n[:source] == @node[:source] }
result = @node[:escape] ? string : Glyph::Interpreter.new(string, @node).document.output
if @node[:escape] then
result = string
else
@node[:embedded] = true
result = Glyph::Interpreter.new(string, @node).document.output
end
result.gsub(/\\*([\[\]])/){"\\#$1"}
end

Expand Down
16 changes: 10 additions & 6 deletions macros/html/structure.rb
Expand Up @@ -10,15 +10,19 @@

macro :header do
min_parameters 1
max_parameters 2
max_parameters 3
title = @params[0]
level = 1
@node.ascend do |n|
if Glyph["structure.headers"].include? n[:macro] then
level+=1
level = @params[2]
h_id = @params[1]
h_id = nil if h_id.blank?
unless level then
level = 1
@node.ascend do |n|
if Glyph["structure.headers"].include? n[:macro] then
level+=1
end
end
end
h_id = @params[1]
h_id ||= "h_#{@node[:document].headers.length+1}".to_sym
header :title => title, :level => level, :id => h_id
@node[:header] = h_id
Expand Down
28 changes: 28 additions & 0 deletions spec/macros/macros_spec.rb
Expand Up @@ -315,5 +315,33 @@
@p.document.output.should == "Test: OK!"
end

it "header should allow level override" do
Glyph.run! "load:all"
Glyph.macro :sec_1 do
interpret "section[header[Test1]\n#@value]"
end
Glyph.macro :sec_2 do
interpret "section[header[Test2||5]\n#@value]"
end
text = %{section[sec_1[section[sec_2[Test]]]]}
interpret text
@p.document.output.should == "<div class=\"section\">
<div class=\"section\">
<h3 id=\"h_2\">Test1</h3>
<div class=\"section\">
<div class=\"section\">
<h5 id=\"h_1\">Test2</h5>
Test
</div>
</div>
</div>
</div>".gsub(/\t/, '')
end



end
2 changes: 1 addition & 1 deletion styles/coderay.css
Expand Up @@ -118,4 +118,4 @@ table.CodeRay td { padding: 2px 4px; vertical-align: top; }
.CodeRay .del .del { color: #800; font-weight:bold }
.CodeRay .chg .chg { color: #66f; }
.CodeRay .head .head { color: #f4f; }

0 comments on commit 02f192c

Please sign in to comment.