glyph 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (162) hide show
  1. data/.gitignore +7 -0
  2. data/AUTHORS.textile +8 -7
  3. data/CHANGELOG.textile +89 -8
  4. data/LICENSE.textile +1 -2
  5. data/README.textile +89 -61
  6. data/Rakefile +12 -10
  7. data/VERSION +1 -1
  8. data/benchmark.rb +1 -1
  9. data/book/config.yml +18 -4
  10. data/book/document.glyph +269 -45
  11. data/book/images/glyph/commands_tasks.png +0 -0
  12. data/book/images/{document_generation.png → glyph/document_generation.png} +0 -0
  13. data/book/images/glyph/glyph.eps +123 -0
  14. data/book/images/glyph/glyph.png +0 -0
  15. data/book/images/glyph/glyph.svg +29 -0
  16. data/book/lib/commands/commands.rb +11 -0
  17. data/book/lib/layouts/bookindex.glyph +127 -0
  18. data/book/lib/layouts/bookpage.glyph +129 -0
  19. data/book/lib/layouts/project.glyph +26 -0
  20. data/book/lib/macros/reference.rb +27 -7
  21. data/book/lib/tasks/tasks.rake +52 -0
  22. data/book/snippets.yml +1 -1
  23. data/book/text/{acknowledgement.glyph → acknowledgements.glyph} +4 -2
  24. data/book/text/changelog.glyph +29 -3
  25. data/book/text/compiling/compiling.glyph +44 -20
  26. data/book/text/compiling/lite_mode.glyph +0 -4
  27. data/book/text/compiling/programmatic_usage.glyph +1 -5
  28. data/book/text/config/document.glyph +35 -0
  29. data/book/text/config/filters.glyph +28 -0
  30. data/book/text/config/options.glyph +25 -0
  31. data/book/text/config/output.glyph +83 -0
  32. data/book/text/extending/bookmarks_headers.glyph +0 -5
  33. data/book/text/extending/command.glyph +56 -0
  34. data/book/text/extending/commands_tasks.glyph +39 -0
  35. data/book/text/extending/further_reading.glyph +0 -3
  36. data/book/text/extending/internals.glyph +3 -5
  37. data/book/text/extending/interpreting.glyph +0 -4
  38. data/book/text/extending/layouts.glyph +68 -0
  39. data/book/text/extending/macro_def.glyph +0 -5
  40. data/book/text/extending/output_format.glyph +78 -0
  41. data/book/text/extending/params_attrs.glyph +0 -3
  42. data/book/text/extending/placeholders.glyph +0 -4
  43. data/book/text/extending/task.glyph +46 -0
  44. data/book/text/extending/validators.glyph +5 -6
  45. data/book/text/getting_started/configuration.glyph +1 -5
  46. data/book/text/getting_started/create_project.glyph +1 -5
  47. data/book/text/getting_started/structure.glyph +0 -4
  48. data/book/text/introduction.glyph +100 -75
  49. data/book/text/license.glyph +1 -2
  50. data/book/text/macros/macros_block.glyph +8 -4
  51. data/book/text/macros/macros_core.glyph +0 -3
  52. data/book/text/macros/macros_filters.glyph +2 -7
  53. data/book/text/macros/macros_inline.glyph +0 -4
  54. data/book/text/macros/macros_structure.glyph +0 -4
  55. data/book/text/ref_commands.glyph +29 -7
  56. data/book/text/stats/bookmarks.glyph +49 -0
  57. data/book/text/stats/links.glyph +90 -0
  58. data/book/text/stats/macros.glyph +73 -0
  59. data/book/text/stats/snippets.glyph +50 -0
  60. data/book/text/stats/stats.glyph +79 -0
  61. data/book/text/text_editing/attribute_intro.glyph +22 -0
  62. data/book/text/text_editing/code.glyph +0 -5
  63. data/book/text/text_editing/conditionals.glyph +0 -4
  64. data/book/text/text_editing/esc_quot.glyph +64 -0
  65. data/book/text/text_editing/evaluation.glyph +0 -3
  66. data/book/text/text_editing/glyph_files.glyph +0 -3
  67. data/book/text/text_editing/images.glyph +0 -5
  68. data/book/text/text_editing/inclusions.glyph +0 -4
  69. data/book/text/text_editing/links.glyph +2 -7
  70. data/book/text/text_editing/macro_intro.glyph +1 -98
  71. data/book/text/text_editing/raw_html.glyph +0 -87
  72. data/book/text/text_editing/section_aliases.glyph +28 -0
  73. data/book/text/text_editing/sections.glyph +1 -32
  74. data/book/text/text_editing/stylesheets.glyph +3 -5
  75. data/book/text/text_editing/topics.glyph +33 -0
  76. data/book/text/text_editing/xml_fallback.glyph +73 -0
  77. data/book/text/troubleshooting/errors_command.glyph +0 -3
  78. data/book/text/troubleshooting/errors_generic.glyph +21 -6
  79. data/book/text/troubleshooting/errors_macro.glyph +11 -8
  80. data/book/text/troubleshooting/errors_parser.glyph +0 -3
  81. data/config.yml +60 -25
  82. data/glyph.gemspec +90 -36
  83. data/layouts/web/index.glyph +16 -0
  84. data/layouts/web/topic.glyph +15 -0
  85. data/layouts/web5/index.glyph +16 -0
  86. data/layouts/web5/topic.glyph +17 -0
  87. data/lib/glyph.rb +36 -49
  88. data/lib/glyph/analyzer.rb +253 -0
  89. data/lib/glyph/bookmark.rb +92 -0
  90. data/lib/glyph/commands.rb +9 -221
  91. data/lib/glyph/commands/add.rb +8 -0
  92. data/lib/glyph/commands/compile.rb +93 -0
  93. data/lib/glyph/commands/config.rb +38 -0
  94. data/lib/glyph/commands/init.rb +6 -0
  95. data/lib/glyph/commands/outline.rb +45 -0
  96. data/lib/glyph/commands/stats.rb +48 -0
  97. data/lib/glyph/commands/todo.rb +29 -0
  98. data/lib/glyph/config.rb +2 -0
  99. data/lib/glyph/document.rb +61 -30
  100. data/lib/glyph/interpreter.rb +2 -2
  101. data/lib/glyph/macro.rb +14 -5
  102. data/lib/glyph/macro_helpers.rb +280 -0
  103. data/lib/glyph/macro_validators.rb +37 -2
  104. data/lib/glyph/reporter.rb +182 -0
  105. data/lib/glyph/syntax_node.rb +37 -10
  106. data/lib/glyph/system_extensions.rb +8 -45
  107. data/lib/glyph/utils.rb +148 -0
  108. data/macros/core.rb +10 -15
  109. data/macros/filters.rb +4 -5
  110. data/macros/html/block.rb +46 -30
  111. data/macros/html/inline.rb +9 -35
  112. data/macros/html/structure.rb +59 -72
  113. data/macros/html5/block.rb +69 -0
  114. data/macros/html5/inline.rb +24 -0
  115. data/macros/html5/structure.rb +139 -0
  116. data/macros/xml.rb +1 -1
  117. data/spec/files/custom_command.rb +6 -0
  118. data/spec/files/custom_tasks.rake +6 -0
  119. data/spec/files/document_for_stats.glyph +12 -0
  120. data/spec/files/references.glyph +4 -0
  121. data/spec/files/web1.glyph +11 -0
  122. data/spec/files/web2.glyph +10 -0
  123. data/spec/files/web_doc.glyph +23 -0
  124. data/spec/lib/analyzer_spec.rb +137 -0
  125. data/spec/lib/bookmark_spec.rb +64 -0
  126. data/spec/lib/commands_spec.rb +30 -5
  127. data/spec/lib/document_spec.rb +49 -9
  128. data/spec/lib/glyph_spec.rb +21 -1
  129. data/spec/lib/macro_spec.rb +6 -6
  130. data/spec/lib/macro_validators_spec.rb +24 -0
  131. data/spec/lib/reporter_spec.rb +132 -0
  132. data/spec/macros/core_spec.rb +2 -3
  133. data/spec/macros/filters_spec.rb +2 -2
  134. data/spec/macros/html5_spec.rb +101 -0
  135. data/spec/macros/macros_spec.rb +16 -6
  136. data/spec/macros/web5_spec.rb +32 -0
  137. data/spec/macros/web_spec.rb +59 -0
  138. data/spec/macros/xml_spec.rb +1 -1
  139. data/spec/spec_helper.rb +24 -4
  140. data/spec/tasks/generate_spec.rb +54 -0
  141. data/spec/tasks/load_spec.rb +29 -3
  142. data/spec/tasks/project_spec.rb +21 -3
  143. data/styles/default.css +40 -4
  144. data/styles/pagination.css +59 -41
  145. data/tasks/generate.rake +110 -31
  146. data/tasks/load.rake +39 -7
  147. data/tasks/project.rake +9 -7
  148. metadata +115 -34
  149. data/book/images/glyph.png +0 -0
  150. data/book/images/glyph.svg +0 -351
  151. data/book/output/html/glyph.html +0 -4482
  152. data/book/output/html/images/document_generation.png +0 -0
  153. data/book/output/html/images/glyph.png +0 -0
  154. data/book/output/html/images/glyph.svg +0 -351
  155. data/book/output/pdf/glyph.pdf +4 -10254
  156. data/book/script/authors +0 -1
  157. data/book/script/changelog +0 -1
  158. data/book/script/license +0 -1
  159. data/book/script/readme +0 -1
  160. data/book/text/ref_config.glyph +0 -100
  161. data/book/text/ref_macros.glyph +0 -6
  162. data/book/text/troubleshooting/errors_intro.glyph +0 -3
data/macros/core.rb CHANGED
@@ -69,7 +69,7 @@ macro :include do
69
69
  macro_warning e.message, e
70
70
  end
71
71
  else
72
- if Glyph["filters.by_file_extension"] && !ext.in?(['rb','glyph']) then
72
+ if Glyph["options.filter_by_file_extension"] && !ext.in?(['rb','glyph']) then
73
73
  if Glyph::MACROS.include?(ext.to_sym) then
74
74
  contents = "#{ext}[#{contents}]"
75
75
  else
@@ -77,7 +77,9 @@ macro :include do
77
77
  end
78
78
  end
79
79
  begin
80
- update_source v
80
+ folder = Glyph.lite? ? "" : "text/"
81
+ topic = (attr(:topic) && Glyph.multiple_output_files?) ? folder+v : nil
82
+ update_source v, folder+v, topic
81
83
  interpret contents
82
84
  rescue Glyph::MutualInclusionError => e
83
85
  raise
@@ -135,18 +137,21 @@ macro :condition do
135
137
  end
136
138
 
137
139
  macro :eq do
140
+ within :condition
138
141
  min_parameters 1
139
142
  max_parameters 2
140
143
  (param(0).to_s == param(1).to_s) ? true : nil
141
144
  end
142
145
 
143
146
  macro :not do
147
+ within :condition
144
148
  max_parameters 1
145
149
  v = param(0).to_s
146
150
  (v.blank? || v == "false") ? true : nil
147
151
  end
148
152
 
149
153
  macro :and do
154
+ within :condition
150
155
  min_parameters 1
151
156
  max_parameters 2
152
157
  res_a = !param(0).blank?
@@ -155,6 +160,7 @@ macro :and do
155
160
  end
156
161
 
157
162
  macro :or do
163
+ within :condition
158
164
  min_parameters 1
159
165
  max_parameters 2
160
166
  res_a = !param(0).blank?
@@ -163,6 +169,7 @@ macro :or do
163
169
  end
164
170
 
165
171
  macro :match do
172
+ within :condition
166
173
  exact_parameters 2
167
174
  val = param(0).to_s
168
175
  regexp = param(1).to_s
@@ -184,19 +191,7 @@ macro "rewrite:" do
184
191
  macro_error "Macro '#{macro_name}' cannot be defined by itself"
185
192
  end
186
193
  end
187
- string = raw_param(1)
188
- Glyph.macro macro_name do
189
- s = string.dup
190
- # Parameters
191
- s.gsub!(/\{\{(\d+)\}\}/) do
192
- raw_param($1.to_i).strip
193
- end
194
- # Attributes
195
- s.gsub!(/\{\{([^\[\]\|\\\s]+)\}\}/) do
196
- raw_attr($1.to_sym).strip
197
- end
198
- interpret s
199
- end
194
+ Glyph.rewrite macro_name, raw_param(1).dup
200
195
  nil
201
196
  end
202
197
 
data/macros/filters.rb CHANGED
@@ -2,14 +2,13 @@
2
2
 
3
3
  macro :textile do
4
4
  exact_parameters 1
5
- rc = nil
6
5
  begin
7
6
  require 'RedCloth'
8
- rc = RedCloth.new value, Glyph::CONFIG.get("filters.redcloth.restrictions")
9
7
  rescue Exception
10
8
  macro_error "RedCloth gem not installed. Please run: gem install RedCloth"
11
9
  end
12
- target = Glyph["filters.target"]
10
+ rc = RedCloth.new value, Glyph::CONFIG.get("filters.redcloth.restrictions")
11
+ target = Glyph["output.#{Glyph['document.output']}.filter_target"]
13
12
  case target.to_sym
14
13
  when :html
15
14
  rc.to_html.gsub /<p><\/p>/, ''
@@ -63,7 +62,7 @@ macro :markdown do
63
62
  else
64
63
  macro_error "No supported MarkDown converter installed. Please run: gem install bluecloth"
65
64
  end
66
- target = Glyph["filters.target"]
65
+ target = Glyph["output.#{Glyph['document.output']}.filter_target"]
67
66
  if target.to_sym == :html then
68
67
  md.to_html
69
68
  else
@@ -98,7 +97,7 @@ macro :highlight do
98
97
  end
99
98
  end
100
99
  Glyph["highlighter.current"] = highlighter
101
- target = Glyph["filters.target"]
100
+ target = Glyph["output.#{Glyph['document.output']}.filter_target"]
102
101
  result = ""
103
102
  case highlighter.to_sym
104
103
  when :coderay
data/macros/html/block.rb CHANGED
@@ -33,10 +33,9 @@ macro :image do
33
33
  max_parameters 3
34
34
  image = param(0)
35
35
  alt = "@alt[-]" unless attr(:alt)
36
- source_file = Glyph.lite? ? image : Glyph::PROJECT/"images/#{image}"
37
- dest_file = Glyph.lite? ? image : "images/#{image}"
38
- Glyph.warning "Image '#{image}' not found" unless Pathname.new(dest_file).exist?
39
- interpret "img[#{alt}@src[#{dest_file}]#{@node.attrs.join}]"
36
+ image_element_for image, alt do |alt, dest_file|
37
+ interpret "img[#{alt}@src[#{Glyph["output.#{Glyph['document.output']}.base"]}#{dest_file}]#{@node.attrs.join}]"
38
+ end
40
39
  end
41
40
 
42
41
  macro :figure do
@@ -44,47 +43,39 @@ macro :figure do
44
43
  max_parameters 2
45
44
  image = param(0)
46
45
  alt = "@alt[-]" unless attr(:alt)
47
- caption = param(1) rescue nil
48
- caption = "div[@class[caption]#{caption}]" if caption
49
- source_file = Glyph.lite? ? image : Glyph::PROJECT/"images/#{image}"
50
- dest_file = Glyph.lite? ? image : "images/#{image}"
51
- Glyph.warning "Figure '#{image}' not found" unless Pathname.new(dest_file).exist?
52
- interpret %{div[@class[figure]
53
- img[#{alt}@src[#{dest_file}]#{@node.attrs.join}]
54
- #{caption}
46
+ caption = "div[@class[caption]#{param(1)}]" rescue nil
47
+ figure_element_for image, alt, caption do |alt, dest_file, caption|
48
+ interpret %{div[@class[figure]
49
+ img[#{alt}@src[#{Glyph["output.#{Glyph['document.output']}.base"]}#{dest_file}]#{@node.attrs.join}]
50
+ #{caption}
55
51
  ]}
52
+ end
56
53
  end
57
54
 
58
55
  macro :title do
59
56
  no_parameters
60
- unless Glyph["document.title"].blank? then
61
- %{<h1>
62
- #{Glyph["document.title"]}
57
+ title_element do
58
+ %{<h1>
59
+ #{Glyph["document.title"]}
63
60
  </h1>}
64
- else
65
- ""
66
61
  end
67
62
  end
68
63
 
69
64
  macro :subtitle do
70
65
  no_parameters
71
- unless Glyph["document.subtitle"].blank? then
72
- %{<h2>
73
- #{Glyph["document.subtitle"]}
66
+ subtitle_element do
67
+ %{<h2>
68
+ #{Glyph["document.subtitle"]}
74
69
  </h2>}
75
- else
76
- ""
77
70
  end
78
71
  end
79
72
 
80
73
  macro :author do
81
74
  no_parameters
82
- unless Glyph['document.author'].blank? then
83
- %{<div class="author">
75
+ author_element do
76
+ %{<div class="author">
84
77
  by <em>#{Glyph["document.author"]}</em>
85
78
  </div>}
86
- else
87
- ""
88
79
  end
89
80
  end
90
81
 
@@ -96,11 +87,36 @@ macro :pubdate do
96
87
  end
97
88
 
98
89
  macro :revision do
99
- unless Glyph["document.revision"].blank? then
100
- %{<div class="revision">#{Glyph['document.revision']}</div>}
101
- else
102
- ""
90
+ no_parameters
91
+ revision_element do
92
+ %{<div class="revision">#{Glyph['document.revision']}</div>}
93
+ end
94
+ end
95
+
96
+ macro :navigation do
97
+ exact_parameters 1
98
+ procs = {}
99
+ procs[:contents] = lambda do
100
+ %{<a href="#{Glyph["output.#{Glyph['document.output']}.base"]}index.html">Contents</a>}
101
+ end
102
+ procs[:previous] = lambda do |topic|
103
+ if topic then
104
+ %{<a href="#{Glyph["output.#{Glyph['document.output']}.base"]}#{topic[:src].gsub(/\..+$/, '.html')}">#{topic[:title]} &larr;</a>}
105
+ else
106
+ ""
107
+ end
108
+ end
109
+ procs[:next] = lambda do |topic|
110
+ if topic then
111
+ %{<a href="#{Glyph["output.#{Glyph['document.output']}.base"]}#{topic[:src].gsub(/\..+$/, '.html')}">&rarr; #{topic[:title]}</a>}
112
+ else
113
+ ""
114
+ end
115
+ end
116
+ procs[:navigation] = lambda do |contents, prev_link, next_link|
117
+ %{<div class="navigation">#{prev_link}#{contents}#{next_link}</div>}
103
118
  end
119
+ navigation_element_for param(0).to_sym, procs
104
120
  end
105
121
 
106
122
  macro_alias :important => :note
@@ -3,61 +3,35 @@
3
3
  macro :anchor do
4
4
  min_parameters 1
5
5
  max_parameters 2
6
- ident = param(0)
7
- title = param(1) rescue nil
8
- macro_error "Bookmark '#{ident}' already exists" if bookmark? ident
9
- bookmark :id => ident, :title => title
10
- %{<a id="#{ident}">#{title}</a>}
6
+ bookmark :id => param(0), :title => param(1), :file => @source_file
7
+ %{<a id="#{param(0)}">#{(param(1) rescue nil)}</a>}
11
8
  end
12
9
 
13
10
  macro :link do
14
11
  min_parameters 1
15
12
  max_parameters 2
16
- href = param(0)
17
- title = param(1) rescue nil
18
- if href.match /^#/ then
19
- anchor = href.gsub(/^#/, '').to_sym
20
- bmk = bookmark? anchor
21
- if bmk then
22
- title ||= bmk[:title]
23
- else
24
- plac = placeholder do |document|
25
- macro_error "Bookmark '#{anchor}' does not exist" unless document.bookmarks[anchor]
26
- document.bookmarks[anchor][:title]
27
- end
28
- title ||= plac
29
- end
13
+ link_element_for param(0), param(1) do |target, title|
14
+ %{<a href="#{target}">#{title}</a>}
30
15
  end
31
- title ||= href
32
- %{<a href="#{href}">#{title.to_s}</a>}
33
16
  end
34
17
 
35
18
  macro :fmi do
36
19
  exact_parameters 2, :level => :warning
37
- topic = param(0)
38
- href = param(1)
39
- link = placeholder do |document|
40
- interpret "link[#{href}]"
20
+ fmi_element_for param(0), param(1) do |topic, link|
21
+ %{<span class="fmi">for more information on #{topic}, see #{link}</span>}
41
22
  end
42
- %{<span class="fmi">for more information on #{topic}, see #{link}</span>}
43
23
  end
44
24
 
45
25
  macro :draftcomment do
46
- if Glyph['document.draft'] then
26
+ draftcomment_element do |value|
47
27
  %{<span class="comment"><span class="comment-pre"><strong>Comment:</strong> </span>#{value}</span>}
48
- else
49
- ""
50
28
  end
51
29
  end
52
30
 
53
31
  macro :todo do
54
32
  exact_parameters 1
55
- todo = {:source => @source, :text => value}
56
- @node[:document].todos << todo unless @node[:document].todos.include? todo
57
- if Glyph['document.draft'] then
58
- %{<span class="todo"><span class="todo-pre"><strong>TODO:</strong> </span>#{value}</span>}
59
- else
60
- ""
33
+ todo_element do |value|
34
+ %{<span class="todo"><span class="todo-pre"><strong>TODO:</strong> </span>#{value}</span>}
61
35
  end
62
36
  end
63
37
 
@@ -1,31 +1,21 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  macro :section do
4
- exact_parameters 1
5
- h = ""
6
- h_title = attr :title
7
- h_id = attr :id
8
- h_notoc = attr :notoc
9
- macro_warning "Please specify a title for section ##{h_id}" if h_id && !h_title
10
- if h_title then
11
- level = 1
12
- @node.ascend do |n|
13
- if n.is_a?(Glyph::MacroNode) && Glyph["system.structure.headers"].include?(n[:name]) then
14
- level+=1
15
- end
16
- end
17
- h_id ||= "h_#{@node[:document].headers.length+1}"
18
- h_id = h_id.to_sym
19
- header :title => h_title, :level => level, :id => h_id, :notoc => h_notoc
20
- @node[:header] = h_id
21
- macro_error "Bookmark '#{h_id}' already exists" if bookmark? h_id
22
- bookmark :id => h_id, :title => h_title
23
- h = %{<h#{level} id="#{h_id}">#{h_title}</h#{level}>\n}
4
+ max_parameters 1
5
+ if raw_attribute(:src) && Glyph.multiple_output_files? then
6
+ required_attribute :title
24
7
  end
25
- %{<div class="#{@name}">
26
- #{h}#{value}
8
+ procs = {}
9
+ procs[:title] = lambda do |level, ident, title|
10
+ %{<h#{level} id="#{ident}">#{title}</h#{level}>\n}
11
+ end
12
+ procs[:body] = lambda do |title, value|
13
+ %{<div class="#{@name}">
14
+ #{title}#{value}
27
15
 
28
16
  </div>}
17
+ end
18
+ section_element_for procs
29
19
  end
30
20
 
31
21
  macro :article do
@@ -112,79 +102,76 @@ macro :head do
112
102
  #{author}
113
103
  #{copy}
114
104
  <meta name="generator" content="Glyph v#{Glyph::VERSION} (http://www.h3rald.com/glyph)" />
105
+ <meta http-equiv="content-type" content="text/html; charset=utf-8" />
115
106
  #{value}
116
107
  </head>
117
108
  }
118
109
  end
119
110
 
120
111
  macro :style do
112
+ within :head
121
113
  exact_parameters 1
122
114
  file = Glyph.lite? ? Pathname.new(value) : Glyph::PROJECT/"styles/#{value}"
123
115
  file = Pathname.new Glyph::HOME/'styles'/value unless file.exist?
124
116
  macro_error "Stylesheet '#{value}' not found" unless file.exist?
125
- style = ""
126
- case file.extname
127
- when ".css"
128
- style = file_load file
129
- when ".sass"
130
- begin
131
- require 'sass'
132
- style = Sass::Engine.new(file_load(file)).render
133
- rescue LoadError
134
- macro_error "Haml is not installed. Please run: gem install haml"
135
- rescue Exception
136
- raise
117
+
118
+ @node[:document].style file
119
+ case Glyph['document.styles'].to_s
120
+ when 'embed' then
121
+ style = ""
122
+ case file.extname
123
+ when ".css"
124
+ style = file_load file
125
+ when ".sass"
126
+ begin
127
+ require 'sass'
128
+ style = Sass::Engine.new(file_load(file)).render
129
+ rescue LoadError
130
+ macro_error "Haml is not installed. Please run: gem install haml"
131
+ rescue Exception
132
+ raise
133
+ end
134
+ else
135
+ macro_error "Extension '#{file.extname}' not supported."
137
136
  end
137
+ %{<style type="text/css">
138
+ #{style}
139
+ </style>}
140
+ when 'import' then
141
+ %{<style type="text/css">
142
+ @import url("#{Glyph["output.#{Glyph['document.output']}.base"]}styles/#{value.gsub(/\..+$/, '.css')}");
143
+ </style>}
144
+ when 'link' then
145
+ %{<link href="#{Glyph["output.#{Glyph['document.output']}.base"]}styles/#{value.gsub(/\..+$/, '.css')}" rel="stylesheet" type="text/css" />}
138
146
  else
139
- macro_error "Extension '#{file.extname}' not supported."
147
+ macro_error "Value '#{Glyph['document.styles']}' not allowed for 'document.styles' setting"
140
148
  end
141
- %{<style type="text/css">
142
- #{style}
143
- </style>}
144
149
  end
145
150
 
146
151
  macro :toc do
147
152
  max_parameters 1
148
- depth = param 0
149
- link_header = lambda do |header|
150
- %{<a href="##{header[:id]}">#{header[:title]}</a>}
153
+ link_proc = lambda do |head|
154
+ (!Glyph.multiple_output_files? || (head.definition != head.file)) ? %{<a href="#{head.link(@source_file)}">#{head.title}</a>} : head.title
151
155
  end
152
- toc = placeholder do |document|
153
- descend_section = lambda do |n1, added_headers|
154
- list = ""
155
- added_headers ||= []
156
- n1.descend do |n2, level|
157
- if n2.is_a?(Glyph::MacroNode) && Glyph['system.structure.headers'].include?(n2[:name]) then
158
- next if n2.find_parent{|node| Glyph['system.structure.special'].include? node[:name] }
159
- header_id = n2[:header]
160
- header_hash = document.header?(header_id)
161
- next if depth && header_hash && (header_hash[:level]-1 > depth.to_i) || header_hash && header_hash[:notoc]
162
- next if added_headers.include? header_id
163
- added_headers << header_id
164
- # Check if part of frontmatter, bodymatter or backmatter
165
- container = n2.find_parent do |node|
166
- node.is_a?(Glyph::MacroNode) &&
167
- node[:name].in?([:frontmatter, :bodymatter, :appendix, :backmatter])
168
- end[:name] rescue nil
169
- list << "<li class=\"#{container} #{n2[:name]}\">#{link_header.call(header_hash)}</li>\n" if header_id
170
- child_list = ""
171
- n2.children.each do |c|
172
- child_list << descend_section.call(c, added_headers)
173
- end
174
- list << "<li><ol>#{child_list}</ol></li>\n" unless child_list.blank?
175
- end
176
- end
177
- list
178
- end
179
- toc_title = attr(:title) || "Table of Contents"
156
+ toc_list_proc = lambda do |descend_proc, bmk, document|
180
157
  %{<div class="contents">
181
- <h2 class="toc-header" id="h_toc">#{toc_title}</h2>
158
+ <h2 class="toc-header" id="#{bmk}">#{bmk.title}</h2>
182
159
  <ol class="toc">
183
- #{descend_section.call(document.structure, nil)}
160
+ #{descend_proc.call(document.structure, nil)}
184
161
  </ol>
185
162
  </div>}
186
163
  end
187
- toc
164
+ toc_item_proc = lambda do |classes, header|
165
+ "<li class=\"#{classes.join(" ").strip}\">#{header}</li>"
166
+ end
167
+ toc_sublist_proc = lambda do |contents|
168
+ "<li><ol>#{contents}</ol></li>\n"
169
+ end
170
+ toc_element_for param(0), attr(:title),
171
+ :link => link_proc,
172
+ :toc_list => toc_list_proc,
173
+ :toc_item => toc_item_proc,
174
+ :toc_sublist => toc_sublist_proc
188
175
  end
189
176
 
190
177
  # See: