macros/html/block.rb in glyph-0.2.0 vs macros/html/block.rb in glyph-0.3.0
- old
+ new
@@ -1,169 +1,107 @@
#!/usr/bin/env ruby
macro :note do
%{<div class="#{@name}">
-<span class="note-title">#{@name.to_s.capitalize}</span>#{@value}
+<span class="note-title">#{@name.to_s.capitalize}</span>#{value}
</div>}
end
macro :box do
- exact_parameters 2, :level => :warning
+ exact_parameters 2
%{<div class="box">
-<div class="box-title">#{params[0]}</div>
-#{params[1]}
+<div class="box-title">#{param(0)}</div>
+#{param(1)}
</div>}
end
-macro :code do
- min_parameters 1
+macro :codeblock do
+ exact_parameters 1
%{
<div class="code">
<pre>
<code>
-#{@value}
+#{value}
</code>
</pre>
</div>}
end
-macro :highlight do
- min_parameters 2
- lang = params[0]
- text = raw_params[1..raw_params.length-1].join '\\|'
- text.gsub!(/\\(.)/){$1}
- highlighter = Glyph["highlighters.current"].to_sym rescue nil
- if !highlighter then
- begin
- require 'coderay'
- highlighter = :coderay
- rescue LoadError
- begin
- require 'uv'
- highlighter = :ultraviolet
- rescue LoadError
- macro_error "No highlighter installed. Please run: gem install coderay"
- end
- end
- Glyph["highlighter.current"] = highlighter
- end
- target = Glyph["highlighters.target"]
- result = ""
- case highlighter.to_sym
- when :coderay
- begin
- require 'coderay'
- result = CodeRay.scan(text, lang).div(Glyph["highlighters.coderay"])
- rescue LoadError
- macro_error "CodeRay highlighter not installed. Please run: gem install coderay"
- rescue Exception => e
- macro_error e.message
- end
- when :ultraviolet
- begin
- require 'uv'
- target = 'xhtml' if target == 'html'
- result = Uv.parse(text.to_s, target.to_s, lang.to_s,
- Glyph["highlighters.ultraviolet.line_numbers"],
- Glyph["highlighters.ultraviolet.theme"].to_s)
- rescue LoadError
- macro_error "UltraViolet highlighter not installed. Please run: gem install ultraviolet"
- rescue Exception => e
- puts e.backtrace
- macro_error e.message
- end
- else
- macro_error "No highlighter installed. Please run: gem install coderay"
- end
- result
-end
-
-macro :title do
- no_parameters
- %{<h1>
- #{Glyph["document.title"]}
-</h1>}
-end
-
-macro :img do
+macro :image do
min_parameters 1
max_parameters 3
- image = params[0]
- width = params[1]
+ image = param(0)
+ alt = "@alt[-]" unless attr(:alt)
source_file = Glyph.lite? ? image : Glyph::PROJECT/"images/#{image}"
dest_file = Glyph.lite? ? image : "images/#{image}"
- w = (width) ? "width=\"#{width}\"" : ''
- height = params[2]
- h = (height) ? "height=\"#{height}\"" : ''
Glyph.warning "Image '#{image}' not found" unless Pathname.new(dest_file).exist?
- %{<img src="#{dest_file}" #{w} #{h} alt="-"/>}
+ interpret "img[#{alt}@src[#{dest_file}]#{@node.attrs.join}]"
end
-macro :fig do
+macro :figure do
min_parameters 1
max_parameters 2
- image = params[0]
- caption = params[1]
- caption ||= nil
- caption = %{<div class="caption">#{caption}</div>} if caption
+ image = param(0)
+ alt = "@alt[-]" unless attr(:alt)
+ caption = param(1) rescue nil
+ caption = "div[@class[caption]#{caption}]" if caption
source_file = Glyph.lite? ? image : Glyph::PROJECT/"images/#{image}"
dest_file = Glyph.lite? ? image : "images/#{image}"
Glyph.warning "Figure '#{image}' not found" unless Pathname.new(dest_file).exist?
- %{<div class="figure">
-<img src="#{dest_file}" alt="-"/>
+ interpret %{div[@class[figure]
+img[#{alt}@src[#{dest_file}]#{@node.attrs.join}]
#{caption}
-</div>}
+]}
end
+macro :title do
+ no_parameters
+ unless Glyph["document.title"].blank? then
+ %{<h1>
+ #{Glyph["document.title"]}
+</h1>}
+ else
+ ""
+ end
+end
macro :subtitle do
no_parameters
+ unless Glyph["document.subtitle"].blank? then
%{<h2>
#{Glyph["document.subtitle"]}
</h2>}
+ else
+ ""
+ end
end
macro :author do
no_parameters
+ unless Glyph['document.author'].blank? then
%{<div class="author">
by <em>#{Glyph["document.author"]}</em>
</div>}
+ else
+ ""
+ end
end
macro :pubdate do
no_parameters
%{<div class="pubdate">
#{Time.now.strftime("%B %Y")}
</div>}
end
-macro :table do
- exact_parameters 1
- %{<table>
-#{@value}
-</table>}
-end
-
-macro :tr do
- exact_parameters 1, :level => :warning
- %{<tr>
-#{@value}
-</tr>}
-end
-
-macro :td do
- exact_parameters 1, :level => :warning
- %{<td>
-#{@value}
-
-</td>}
-end
-
-macro :th do
- exact_parameters 1, :level => :warning
- %{<th>#{@value}</th>}
+macro :revision do
+ unless Glyph["document.revision"].blank? then
+ %{<div class="revision">#{Glyph['document.revision']}</div>}
+ else
+ ""
+ end
end
macro_alias :important => :note
macro_alias :tip => :note
macro_alias :caution => :note