glyph 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (114) hide show
  1. data/AUTHORS.textile +1 -1
  2. data/CHANGELOG.textile +119 -222
  3. data/LICENSE.textile +1 -1
  4. data/README.textile +42 -23
  5. data/Rakefile +1 -3
  6. data/VERSION +1 -1
  7. data/benchmark.rb +72 -0
  8. data/book/config.yml +4 -4
  9. data/book/document.glyph +90 -57
  10. data/book/images/document_generation.png +0 -0
  11. data/book/lib/macros/reference.rb +75 -22
  12. data/book/output/html/glyph.html +3183 -2121
  13. data/book/output/html/images/document_generation.png +0 -0
  14. data/book/output/pdf/glyph.pdf +7370 -4913
  15. data/book/resources/document_generation.txt +34 -0
  16. data/book/snippets.yml +6 -0
  17. data/book/text/changelog.glyph +45 -34
  18. data/book/text/compiling/compiling.glyph +23 -0
  19. data/book/text/compiling/lite_mode.glyph +23 -0
  20. data/book/text/compiling/programmatic_usage.glyph +77 -0
  21. data/book/text/extending/bookmarks_headers.glyph +21 -0
  22. data/book/text/extending/further_reading.glyph +13 -0
  23. data/book/text/extending/internals.glyph +79 -0
  24. data/book/text/extending/interpreting.glyph +51 -0
  25. data/book/text/extending/macro_def.glyph +64 -0
  26. data/book/text/extending/params_attrs.glyph +70 -0
  27. data/book/text/extending/placeholders.glyph +34 -0
  28. data/book/text/extending/validators.glyph +16 -0
  29. data/book/text/getting_started/configuration.glyph +49 -0
  30. data/book/text/getting_started/create_project.glyph +41 -0
  31. data/book/text/getting_started/structure.glyph +55 -0
  32. data/book/text/introduction.glyph +49 -26
  33. data/book/text/license.glyph +1 -1
  34. data/book/text/macros/macros_block.glyph +99 -0
  35. data/book/text/macros/macros_core.glyph +208 -0
  36. data/book/text/macros/macros_filters.glyph +40 -0
  37. data/book/text/macros/macros_inline.glyph +50 -0
  38. data/book/text/macros/macros_structure.glyph +100 -0
  39. data/book/text/ref_commands.glyph +94 -73
  40. data/book/text/ref_config.glyph +34 -42
  41. data/book/text/ref_macros.glyph +1 -373
  42. data/book/text/text_editing/code.glyph +51 -0
  43. data/book/text/text_editing/conditionals.glyph +49 -0
  44. data/book/text/text_editing/evaluation.glyph +13 -0
  45. data/book/text/text_editing/glyph_files.glyph +7 -0
  46. data/book/text/text_editing/images.glyph +29 -0
  47. data/book/text/text_editing/inclusions.glyph +44 -0
  48. data/book/text/text_editing/links.glyph +53 -0
  49. data/book/text/text_editing/macro_intro.glyph +111 -0
  50. data/book/text/text_editing/raw_html.glyph +112 -0
  51. data/book/text/text_editing/sections.glyph +63 -0
  52. data/book/text/text_editing/stylesheets.glyph +36 -0
  53. data/book/text/troubleshooting/errors_command.glyph +39 -0
  54. data/book/text/troubleshooting/errors_generic.glyph +29 -0
  55. data/book/text/troubleshooting/errors_intro.glyph +3 -0
  56. data/book/text/troubleshooting/errors_macro.glyph +98 -0
  57. data/book/text/troubleshooting/errors_parser.glyph +29 -0
  58. data/config.yml +77 -58
  59. data/document.glyph +25 -25
  60. data/glyph.gemspec +57 -22
  61. data/lib/glyph.rb +54 -13
  62. data/lib/glyph/commands.rb +84 -17
  63. data/lib/glyph/config.rb +3 -3
  64. data/lib/glyph/document.rb +14 -8
  65. data/lib/glyph/interpreter.rb +18 -58
  66. data/lib/glyph/macro.rb +160 -55
  67. data/lib/glyph/macro_validators.rb +104 -12
  68. data/lib/glyph/node.rb +24 -0
  69. data/lib/glyph/parser.rb +278 -0
  70. data/lib/glyph/syntax_node.rb +225 -0
  71. data/macros/core.rb +212 -0
  72. data/macros/filters.rb +66 -15
  73. data/macros/html/block.rb +43 -105
  74. data/macros/html/inline.rb +11 -12
  75. data/macros/html/structure.rb +123 -58
  76. data/macros/xml.rb +33 -0
  77. data/spec/files/container.textile +2 -2
  78. data/spec/files/document.glyph +2 -2
  79. data/spec/files/document_with_toc.glyph +3 -3
  80. data/spec/files/included.textile +1 -1
  81. data/spec/files/ligature.jpg +0 -0
  82. data/spec/files/markdown.markdown +2 -1
  83. data/spec/lib/commands_spec.rb +46 -3
  84. data/spec/lib/document_spec.rb +4 -4
  85. data/spec/lib/glyph_spec.rb +17 -46
  86. data/spec/lib/interpreter_spec.rb +6 -25
  87. data/spec/lib/macro_spec.rb +141 -43
  88. data/spec/lib/macro_validators_spec.rb +27 -5
  89. data/spec/lib/node_spec.rb +26 -1
  90. data/spec/lib/parser_spec.rb +246 -0
  91. data/spec/lib/syntax_node_spec.rb +111 -0
  92. data/spec/macros/core_spec.rb +195 -0
  93. data/spec/macros/filters_spec.rb +38 -4
  94. data/spec/macros/macros_spec.rb +20 -176
  95. data/spec/macros/textile_spec.rb +13 -71
  96. data/spec/macros/xml_spec.rb +77 -0
  97. data/spec/spec_helper.rb +50 -10
  98. data/spec/tasks/load_spec.rb +13 -2
  99. data/styles/default.css +18 -6
  100. data/styles/pagination.css +1 -19
  101. data/tasks/generate.rake +2 -2
  102. data/tasks/load.rake +27 -17
  103. data/tasks/project.rake +1 -1
  104. metadata +75 -62
  105. data/book/script/compile.rb +0 -8
  106. data/book/script/prof +0 -1
  107. data/book/script/prof_results.htm +0 -21079
  108. data/book/text/authoring.glyph +0 -548
  109. data/book/text/extending.glyph +0 -224
  110. data/book/text/getting_started.glyph +0 -158
  111. data/book/text/troubleshooting.glyph +0 -179
  112. data/lib/glyph/glyph_language.rb +0 -538
  113. data/lib/glyph/glyph_language.treetop +0 -27
  114. data/macros/common.rb +0 -160
data/Rakefile CHANGED
@@ -31,17 +31,15 @@ begin
31
31
  s.files.include "book/**/*"
32
32
  s.add_dependency 'gli', '>= 0.3.1' # Command line interface
33
33
  s.add_dependency 'extlib', '>= 0.9.12' # Extension methods
34
- s.add_dependency 'treetop', '>= 0.4.3' # Glyph Language Parser
35
34
  s.add_dependency 'rake', '>= 0.8.7' # Glyph rasks
36
35
  s.add_development_dependency 'rspec', '>= 1.1.11' # Test suite
37
36
  s.add_development_dependency 'yard', '>= 1.5.4' # Documentation suite
38
37
  s.add_development_dependency 'jeweler', '1.4.0' # Gem management
39
38
  s.add_development_dependency 'directory_watcher', ">= 1.3.2" # Auto-regeneration
40
- s.add_development_dependency 'haml', ">= 2.2.3" # Sass filter
39
+ s.add_development_dependency 'haml', ">= 3.0.6" # Sass filter
41
40
  s.add_development_dependency 'RedCloth', ">= 4.2.3" # Textile filter
42
41
  s.add_development_dependency 'bluecloth', ">= 2.0.7" # Markdown filter
43
42
  s.add_development_dependency 'coderay', ">= 0.9.3" # Syntax Highlighting
44
- s.add_development_dependency 'ruby-prof', ">= 0.8.1" # Code profiling
45
43
  end
46
44
  Jeweler::GemcutterTasks.new
47
45
  rescue LoadError
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.3.0
data/benchmark.rb ADDED
@@ -0,0 +1,72 @@
1
+ require 'rubygems'
2
+ require 'pathname'
3
+ require 'extlib'
4
+ require 'bluecloth'
5
+ require 'redcloth'
6
+ require 'benchmark'
7
+ require Pathname.new(__FILE__).parent/"lib/glyph.rb"
8
+
9
+
10
+
11
+ def macro_exec(text)
12
+ Glyph::Interpreter.new(text).document.output
13
+ end
14
+
15
+ def sep
16
+ puts "="*100
17
+ end
18
+
19
+ N = 50
20
+
21
+ def rep(x, title, &block)
22
+ x.report(title.to_s) { N.times(&block) }
23
+ end
24
+
25
+ def reset_glyph
26
+ Glyph.lite_mode = true
27
+ Glyph['system.quiet'] = true
28
+ end
29
+
30
+
31
+ text = %{
32
+ Lorem ipsum dolor sit amet, consectetur _adipisicing elit_, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
33
+ Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
34
+ * Duis aute irure dolor in *reprehenderit* in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
35
+ * Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
36
+ }
37
+ html = %{
38
+ p[Lorem ipsum dolor sit amet, consectetur em[adipisicing elit], sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.]
39
+ p[Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.]
40
+ ul[
41
+ li[Duis aute irure dolor in strong[reprehenderit] in voluptate velit esse cillum dolore eu fugiat nulla pariatur.]
42
+ li[Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.]
43
+ ]
44
+ }
45
+
46
+ reset_glyph
47
+ Glyph.run! 'load:all'
48
+ Glyph::SNIPPETS[:test] = text
49
+ Benchmark.bm(30) do |x|
50
+
51
+ sep
52
+ puts " => Core Classes"
53
+ rep(x, "Glyph::Interpreter.new.parse") {Glyph::Interpreter.new(text).parse}
54
+ rep(x, "Glyph::Parser.new(text).parse") {Glyph::Parser.new(text).parse}
55
+ sep
56
+ puts " => Macro Set: Glyph"
57
+ sep
58
+ rep(x, "section[...]") { macro_exec "section[#{text}]" }
59
+ rep(x, "snippet[...]") { macro_exec "snippet[test]" }
60
+ rep(x, "textile[...]") { macro_exec "textile[#{text}]" }
61
+ rep(x, "markdown[...]") { macro_exec "markdown[#{text}]" }
62
+ rep(x, "HTML text") { macro_exec html }
63
+ sep
64
+ rep(x, "Markdown (BlueCloth)") {BlueCloth.new(text).to_html }
65
+ rep(x, "Textile (RedCloth)") {RedCloth.new(text).to_html }
66
+ sep
67
+ puts " => Macro Set: XML"
68
+ reset_glyph
69
+ Glyph['language.set'] = 'xml'
70
+ Glyph.run! 'load:all'
71
+ rep(x, "HTML text") { macro_exec html }
72
+ end
data/book/config.yml CHANGED
@@ -1,11 +1,11 @@
1
1
  ---
2
- :highlighters:
3
- :current: ultraviolet
4
- :ultraviolet:
5
- :theme: blackboard
6
2
  :document:
7
3
  :output: html
8
4
  :title: Glyph
9
5
  :subtitle: Rapid Document Authoring Framework
10
6
  :author: Fabio Cevasco
7
+ :revision: "v0.3.0"
11
8
  :filename: glyph
9
+ :draft: true
10
+ :filters:
11
+ :highlighter: ultraviolet
data/book/document.glyph CHANGED
@@ -1,66 +1,99 @@
1
- document[
2
- head[
1
+ book[
2
+ @head[
3
3
  style[default.css]
4
4
  ?[eq[$[document.output]|pdf]|style[pagination.css]]
5
- ?[eq[$[highlighters.current]|coderay]|style[coderay.css]]
6
- ?[eq[$[highlighters.current]|ultraviolet]|style[ultraviolet/blackboard.css]]
5
+ ?[eq[$[filters.highlighter]|coderay]|style[coderay.css]]
6
+ ?[eq[$[filters.highlighter]|ultraviolet]|style[ultraviolet/lazy.css]]
7
7
  ]
8
- body[
9
- titlepage[
10
- ?[eq[$[document.output]|pdf]|img[glyph.svg|20%|20%]]
11
- ?[eq[$[document.output]|html]|img[glyph.png|20%|20%]]
12
- title[]
13
- subtitle[]
14
- v\.%[Glyph::VERSION]
15
- author[]
16
- pubdate[]
17
- ]
18
- frontmatter[
19
- toc[]
20
- introduction[header[Introduction]
21
- textile[@[introduction.glyph]]
22
- section[header[License]
23
- textile[@[license.glyph]]
24
- ]
25
- ]
26
- acknowledgement[header[Acknowledgement]
27
- textile[@[acknowledgement.glyph]]
8
+ @pre-title[
9
+ ?[eq[$[document.output]|pdf]|image[@width[20%]@height[20%]glyph.svg]]
10
+ ?[eq[$[document.output]|html]|image[@width[20%]@height[20%]glyph.png]]
11
+ ]
12
+ @frontmatter[
13
+ toc[3]
14
+ introduction[
15
+ @title[Introduction]
16
+ textile[include[introduction]]
17
+ section[
18
+ @title[License]
19
+ textile[include[license]]
28
20
  ]
29
21
  ]
30
- bodymatter[
31
- chapter[
32
- header[Getting Started]
33
- textile[@[getting_started.glyph]]
34
- ]
35
- chapter[
36
- header[Authoring Documents]
37
- textile[@[authoring.glyph]]
38
- ]
39
- chapter[
40
- header[Extending Glyph|extending]
41
- textile[@[extending.glyph]]
42
- ]
43
- chapter[
44
- header[Troubleshooting]
45
- textile[@[troubleshooting.glyph]]
46
- ]
22
+ acknowledgement[
23
+ @title[Acknowledgement]
24
+ textile[include[acknowledgement]]
47
25
  ]
48
- backmatter[
49
- appendix[
50
- header[Command Reference|cmd_ref]
51
- textile[@[ref_commands.glyph]]
52
- ]
53
- appendix[
54
- header[Macro Reference|macro_ref]
55
- textile[@[ref_macros.glyph]]
56
- ]
57
- appendix[
58
- header[Configuration Reference|cfg_ref]
59
- textile[@[ref_config.glyph]]
60
- ]
61
- appendix[header[Changelog]
62
- @[changelog.glyph]
63
- ]
26
+ ]
27
+ @bodymatter[
28
+ chapter[
29
+ @title[Getting Started]
30
+ include[getting_started/create_project]
31
+ include[getting_started/structure]
32
+ include[getting_started/configuration]
33
+ ]
34
+ chapter[
35
+ @title[Authoring Documents]
36
+ include[text_editing/glyph_files]
37
+ include[text_editing/macro_intro]
38
+ include[text_editing/sections]
39
+ include[text_editing/links]
40
+ include[text_editing/images]
41
+ include[text_editing/code]
42
+ include[text_editing/raw_html]
43
+ include[text_editing/stylesheets]
44
+ include[text_editing/inclusions]
45
+ include[text_editing/evaluation]
46
+ include[text_editing/conditionals]
47
+ ]
48
+ chapter[
49
+ @title[Generating Output Files]
50
+ include[compiling/compiling]
51
+ include[compiling/lite_mode]
52
+ include[compiling/programmatic_usage]
53
+ ]
54
+ chapter[
55
+ @title[Extending Glyph]
56
+ @id[extending]
57
+ include[extending/internals]
58
+ include[extending/macro_def]
59
+ include[extending/params_attrs]
60
+ include[extending/bookmarks_headers]
61
+ include[extending/placeholders]
62
+ include[extending/validators]
63
+ include[extending/interpreting]
64
+ include[extending/further_reading]
65
+ ]
66
+ chapter[
67
+ @title[Troubleshooting]
68
+ include[troubleshooting/errors_intro]
69
+ include[troubleshooting/errors_generic]
70
+ include[troubleshooting/errors_parser]
71
+ include[troubleshooting/errors_command]
72
+ include[troubleshooting/errors_macro]
73
+ ]
74
+ ]
75
+ @backmatter[
76
+ appendix[
77
+ @title[Command Reference]
78
+ @id[cmd_ref]
79
+ include[ref_commands]
80
+ ]
81
+ appendix[
82
+ @title[Macro Reference]
83
+ @id[macro_ref]
84
+ include[macros/macros_core]
85
+ include[macros/macros_block]
86
+ include[macros/macros_inline]
87
+ include[macros/macros_filters]
88
+ include[macros/macros_structure]
89
+ ]
90
+ appendix[
91
+ @title[Configuration Reference]
92
+ @id[cfg_ref]
93
+ include[ref_config]
94
+ ]
95
+ appendix[@title[Changelog]
96
+ include[changelog]
64
97
  ]
65
98
  ]
66
99
  ]
Binary file
@@ -6,7 +6,7 @@ macro :error_table do
6
6
  <th style="width:30%">Error Message</th>
7
7
  <th>Description</th>
8
8
  </tr>
9
- #{@value}
9
+ #{value}
10
10
  </table>
11
11
  }
12
12
  end
@@ -22,42 +22,45 @@ macro :ref_error do
22
22
  end
23
23
 
24
24
  macro :"%>" do
25
- interpret "=>[#m_#{@value.gsub(/[^a-z0-1_-]/, '_')}|#@value] macro"
25
+ interpret "=>[#m_#{value.gsub(/[^a-z0-1_-]/, '_')}|#{value}] macro"
26
26
  end
27
27
 
28
28
  macro :"#>" do
29
- interpret "=>[#c_#@value|#@value] command"
29
+ interpret "=>[#c_#{value}|#{value}] command"
30
30
  end
31
31
 
32
32
  macro :"$>" do
33
- val = @value.gsub /\./, "_"
34
- interpret "=>[#s_#{val}|#@value] setting"
33
+ val = value.gsub /\./, "_"
34
+ interpret "=>[#s_#{val}|#{value}] setting"
35
35
  end
36
36
 
37
37
  macro :default do
38
- %{*Default Value:* @#@value@}
38
+ %{<strong>Default Value:</strong> <code>#{value}</code>}
39
39
  end
40
40
 
41
- macro :"parameters" do
41
+ macro :parameters do
42
42
  interpret %{
43
- section[header[#{@name.to_s[0..0].upcase+@name.to_s[1..@name.to_s.length-1]}]
43
+ section[
44
+ @title[#{@name.to_s[0..0].upcase+@name.to_s[1..@name.to_s.length-1]}]
45
+ @notoc[true]
44
46
 
45
47
  <table style="width:100%;">
46
48
  <tr>
47
49
  <th style="width:30%">#{@name.to_s[0..0].upcase+@name.to_s[1..@name.to_s.length-2]}</th>
48
50
  <th>Description</th>
49
51
  </tr>
50
- #{@value}
52
+ #{value}
51
53
  </table>
52
54
  ]
53
55
  }
54
56
  end
55
57
 
56
58
  macro :option do
57
- ident, desc = params
59
+ ident = param(0)
60
+ desc = param(1)
58
61
  %{
59
62
  <tr>
60
- <td><notextile>-#{ident[0..0]} (--#{ident})</notextile></td>
63
+ <td><code>-#{ident[0..0]}</code> (<code>--#{ident}</code>)</td>
61
64
  <td>
62
65
  #{desc}
63
66
  </td>
@@ -66,40 +69,79 @@ macro :option do
66
69
  end
67
70
 
68
71
  macro :values do
69
- %{*Possible Values:* @#@value@}
72
+ %{*Possible Values:* @#{value}@}
70
73
  end
71
74
 
72
75
  macro :example do
73
- %{*Example:* <code>#@value</code>}
76
+ %{<p><strong>Example:</strong> <code>#{value}</code></p>}
77
+ end
78
+
79
+ macro :block_example do
80
+ interpret %{
81
+ div[@class[example]
82
+ p[strong[Example]]
83
+ highlight[=html|
84
+ #{value}
85
+ =]
86
+ ]
87
+ }
74
88
  end
75
89
 
76
90
  macro :examples do
77
91
  %{
78
- *Examples:*
79
- #{@value.split("\n").map{|i| "@#{i}@\n"}.to_s}
92
+ <div class="examples">
93
+ <p><strong>Examples:</strong></p>
94
+ #{value.split("\n").map{|i| "<code>#{i}</code><br />"}.to_s}
95
+ </div>
80
96
  }
81
97
  end
82
98
 
83
99
  macro :aliases do
84
- %{*Aliases:* @#@value@}
100
+ %{<strong>Aliases:</strong> <code>#{value}</code>}
85
101
  end
86
102
 
87
103
  macro :ref_macro do
88
- m_name, m_value = params
104
+ m_name = raw_attr(:n)
105
+ m_value = raw_attr(:desc)
106
+ m_params = "parameters[#{raw_attr(:params)}]" if raw_attr(:params)
107
+ m_attrs = "attributes[#{raw_attr(:attrs)}]" if raw_attr(:attrs)
108
+ m_examples = "examples[#{raw_attr(:examples)}]" if raw_attr(:examples)
109
+ m_example = "example[#{raw_attr(:example)}]" if raw_attr(:example)
110
+ m_block_example = "block_example[#{raw_attr(:block_example)}]" if raw_attr(:block_example)
111
+ m_aliases = "aliases[#{raw_attr(:aliases)}]" if raw_attr(:aliases)
112
+ m_remarks = %{section[
113
+ @title[Remarks]
114
+ @notoc[:true]
115
+ txt[
116
+ #{raw_attr(:remarks)}
117
+ ]
118
+ ]} if raw_attr(:remarks)
89
119
  interpret %{
90
- section[header[@#{m_name}@|m_#{m_name.gsub(/[^a-z0-1_-]/, '_')}]
120
+ section[
121
+ @title[<code>#{m_name}</code>]
122
+ @id[m_#{m_name.gsub(/[^a-z0-1_-]/, '_')}]
123
+ txt[
91
124
  #{m_value}
125
+ ]
126
+ #{m_aliases}
127
+ #{m_example}
128
+ #{m_block_example}
129
+ #{m_examples}
130
+ #{m_params}
131
+ #{m_attrs}
132
+ #{m_remarks}
92
133
  ]
93
134
  }
94
135
  end
95
136
 
96
137
  macro :ref_config do
97
- m_name, m_value = params
138
+ m_name = param(0)
139
+ m_value = param(1)
98
140
  default = Glyph::SYSTEM_CONFIG.get(m_name).to_yaml.gsub(/^---/, '')
99
141
  default = "nil" if default.blank?
100
142
  interpret %{tr[
101
- td[codeph[#{m_name}] #[s_#{m_name.gsub(/\./, '_')}]]
102
- td[#{m_value}]
143
+ td[code[#{m_name}] #[s_#{m_name.gsub(/\./, '_').gsub(/\*/,'')}]]
144
+ td[txt[#{m_value}]]
103
145
  td[
104
146
  code[=
105
147
  #{default}
@@ -115,11 +157,22 @@ macro :config_table do
115
157
  th[Description]
116
158
  th[Default (YAML)]
117
159
  ]
118
- #@value
160
+ #{value}
119
161
  ]}
120
162
  end
121
163
 
164
+ macro :class do
165
+ if value.match /Glyph::/ then
166
+ path = "Glyph/#{value.gsub /Glyph::/, ''}"
167
+ else
168
+ path = value
169
+ end
170
+ interpret %{=>[&[yardoc]/#{path}|code[#{value}]]}
171
+ end
172
+
122
173
 
123
174
  macro_alias :options => :parameters
175
+ macro_alias :attributes => :parameters
124
176
  macro_alias '-p' => :ref_error
177
+ macro_alias '-a' => :ref_error
125
178
  macro_alias '-o' => :option