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
@@ -36,11 +36,11 @@ Testing:
36
36
 
37
37
  it "should be embeddable in section macros" do
38
38
  text1 =
39
- %{textile[section[header[Test]
39
+ %{textile[section[@title[Test]
40
40
  #@textile
41
41
  ]]}
42
42
  text2 =
43
- %{textile[section[header[Test]#@textile
43
+ %{textile[section[@title[Test]#@textile
44
44
  ]]}
45
45
  result =
46
46
  %{<div class="section">
@@ -48,67 +48,9 @@ Testing:
48
48
  #@html
49
49
  </div>}
50
50
  filter(text1).should == result
51
- filter(text2).gsub(/<\/h2>/, "</h2>\n").should == result
51
+ filter(text2).gsub(/<\/h2>/, "</h2>").should == result
52
52
  end
53
53
 
54
- ######################################
55
-
56
- it "should be embeddable in td macros" do
57
- text0 =
58
- %{<table>
59
- <tr>
60
- <td>
61
- #@textile
62
- </td>
63
- </tr>
64
- </table>
65
- }
66
- text1 =
67
- %{textile[table[
68
- tr[td[#@textile]]
69
- ]]}
70
- text2 =
71
- %{textile[table[
72
- tr[
73
- td[#@textile]
74
- ]
75
- ]]}
76
- text3 =
77
- %{textile[table[
78
- tr[
79
- td[
80
- #@textile
81
- ]
82
- ]
83
- ]]}
84
- text4 = %{textile[table[
85
- tr[
86
- td[This is a _test_.]
87
- ]
88
- ]]}
89
- result =
90
- %{<table>
91
- <tr>
92
- <td>
93
- #@html
94
- </td>
95
- </tr>
96
- </table>}
97
- result2 =
98
- %{<table>
99
- <tr>
100
- <td>
101
- <p>This is a <em>test</em>.</p>
102
- </td>
103
- </tr>
104
- </table>}
105
- filter(text1).should == result
106
- filter(text2).should == result
107
- filter(text3).should == result
108
- ##### Check inline textile
109
- filter(text4).should == result2
110
- end
111
-
112
54
  ######################################
113
55
 
114
56
  it "should be embeddable in box macros" do
@@ -177,33 +119,33 @@ Testing:
177
119
  </div>
178
120
  </div>}
179
121
  text1 = %{textile[
180
- section[header[Test]
122
+ section[@title[Test]
181
123
  #@textile
182
- code[#{code}]
124
+ codeblock[#{code}]
183
125
  ]]}
184
126
  text2 = %{textile[
185
- section[header[Test]
127
+ section[@title[Test]
186
128
  #@textile
187
- code[#{code}
129
+ codeblock[#{code}
188
130
  ]
189
131
  ]
190
132
  ]}
191
133
  text3 = %{textile[
192
- section[header[Test]
134
+ section[@title[Test]
193
135
  #@textile
194
- code[
136
+ codeblock[
195
137
  #{code}]
196
138
  ]]}
197
139
  text4 = %{textile[
198
- section[header[Test]
140
+ section[@title[Test]
199
141
  #@textile
200
- code[
142
+ codeblock[
201
143
  #{code}
202
144
  ]]]}
203
145
  text5 = %{textile[
204
- section[header[Test]
146
+ section[@title[Test]
205
147
  #@textile
206
- code[
148
+ codeblock[
207
149
  #{code}
208
150
  ]
209
151
  ]]}
@@ -0,0 +1,77 @@
1
+ #!/usr/bin/env ruby
2
+ require File.join(File.dirname(__FILE__), "..", "spec_helper")
3
+
4
+ describe "Glyph Language" do
5
+
6
+ before do
7
+ create_project
8
+ end
9
+
10
+ after do
11
+ reset_quiet
12
+ language('glyph')
13
+ delete_project
14
+ end
15
+
16
+ it "should support XML fallback by default" do
17
+ Glyph.run 'load:all'
18
+ output_for(%{
19
+ i[test]
20
+ code[
21
+ test
22
+ ]
23
+ }).gsub(/\s+/, '').should == %{
24
+ <i>test</i>
25
+ <code>
26
+ test
27
+ </code>}.gsub(/\s+/, '')
28
+ end
29
+
30
+ it "should support XML macros" do
31
+ language('xml')
32
+ output_for("pre[code[test]]").should == "<pre>\n<code>test</code>\n</pre>"
33
+ end
34
+
35
+ it "should support XML attributes" do
36
+ language('xml')
37
+ output_for("span[@class[test] @style[color:red;] test...]").should == %{
38
+ <span class="test" style="color:red;">test...</span>
39
+ }.strip
40
+ end
41
+
42
+ it "should detect invalid characters for XML elements and attributes" do
43
+ language('xml')
44
+ lambda { interpret("!&test[test]").document }.should raise_error
45
+ output_for("span[@class[test]@.[test]test]").should == %{<span class="test">test</span>}
46
+ end
47
+
48
+ it "should notify the user that a macro is not found for invalid elements if xml_fallback is enabled" do
49
+ # Assuming language.options.xml_fallback = true
50
+ language('glyph')
51
+ lambda { interpret("*a[test]").document }.should raise_error(Glyph::MacroError, "Unknown macro '*a'")
52
+ end
53
+
54
+ it "should not render blacklisted tags" do
55
+ language('xml')
56
+ text = %{
57
+ object[test]
58
+ applet[test]
59
+ base[test]
60
+ basefont[test]
61
+ embed[test]
62
+ frame[test]
63
+ frameset[test]
64
+ iframe[test]
65
+ isindex[test]
66
+ test[test]
67
+ meta[test]
68
+ noframes[test]
69
+ noscript[test]
70
+ object[test]
71
+ param[test]
72
+ title[tesy]
73
+ }
74
+ output_for(text).gsub(/\s/, '').should == "<test>test</test>"
75
+ end
76
+
77
+ end
data/spec/spec_helper.rb CHANGED
@@ -14,7 +14,7 @@ end
14
14
 
15
15
  require "glyph"
16
16
 
17
- Glyph[:quiet] = true
17
+ Glyph['system.quiet'] = true
18
18
 
19
19
  def create_project_dir
20
20
  Glyph::PROJECT.mkpath
@@ -22,7 +22,7 @@ end
22
22
 
23
23
  def reset_quiet
24
24
  Glyph.reset
25
- Glyph[:quiet] = true
25
+ Glyph['system.quiet'] = true
26
26
  end
27
27
 
28
28
  def create_project
@@ -32,15 +32,15 @@ def create_project
32
32
  Glyph.run! 'project:create', Glyph::PROJECT.to_s
33
33
  file_copy Glyph::SPEC_DIR/'files/container.textile', Glyph::PROJECT/'text/container.textile'
34
34
  (Glyph::PROJECT/'text/a/b/c').mkpath
35
- file_copy Glyph::SPEC_DIR/'files/included.textile', Glyph::PROJECT/'text/a//b/c/included.textile'
36
- file_copy Glyph::SPEC_DIR/'files/markdown.markdown', Glyph::PROJECT/'text/a//b/c/markdown.markdown'
35
+ file_copy Glyph::SPEC_DIR/'files/included.textile', Glyph::PROJECT/'text/a/b/c/included.textile'
36
+ file_copy Glyph::SPEC_DIR/'files/markdown.markdown', Glyph::PROJECT/'text/a/b/c/markdown.markdown'
37
37
  file_copy Glyph::SPEC_DIR/'files/document.glyph', Glyph::PROJECT/'document.glyph'
38
38
  file_copy Glyph::SPEC_DIR/'files/test.sass', Glyph::PROJECT/'styles/test.sass'
39
39
  file_copy Glyph::SPEC_DIR/'files/ligature.jpg', Glyph::PROJECT/'images/ligature.jpg'
40
40
  end
41
41
 
42
42
  def delete_project_dir
43
- return unless Glyph::PROJECT.exist?
43
+ return unless Glyph::PROJECT.exist?
44
44
  Glyph::PROJECT.children.each do |f|
45
45
  FileUtils.rmtree f if f.directory?
46
46
  FileUtils.rm f if f.file?
@@ -61,9 +61,9 @@ def run_command(cmd)
61
61
  old_stderr = $stderr
62
62
  $stdout = out
63
63
  $stderr = out
64
- Glyph[:quiet] = false
64
+ Glyph['system.quiet'] = false
65
65
  GLI.run cmd
66
- Glyph[:quiet] = true
66
+ Glyph['system.quiet'] = true
67
67
  $stdout = old_stdout
68
68
  $stderr = old_stderr
69
69
  out.string
@@ -75,22 +75,33 @@ end
75
75
 
76
76
  def define_em_macro
77
77
  Glyph.macro :em do
78
- %{<em>#{@value}</em>}
78
+ %{<em>#{value.to_s.strip}</em>}
79
79
  end
80
80
  end
81
81
 
82
82
  def define_ref_macro
83
83
  Glyph.macro :ref do
84
- %{<a href="#{params[0]}">#{params[1]}</a>}
84
+ %{<a href="#{parameter(0).to_s.strip}">#{parameter(1).to_s.strip}</a>}
85
85
  end
86
86
  end
87
87
 
88
+ def language(set)
89
+ reset_quiet
90
+ Glyph.run 'load:config'
91
+ Glyph['language.set'] = set
92
+ Glyph.run 'load:macros'
93
+ end
94
+
88
95
  def interpret(text)
89
96
  @p = Glyph::Interpreter.new(text)
90
97
  end
91
98
 
99
+ def output_for(text)
100
+ Glyph::Interpreter.new(text).document.output
101
+ end
102
+
92
103
  def create_tree(text)
93
- GlyphLanguageParser.new.parse text
104
+ Glyph::Interpreter.new(text).parse
94
105
  end
95
106
 
96
107
  def create_doc(tree)
@@ -100,3 +111,32 @@ end
100
111
  def filter(text)
101
112
  Glyph.filter text
102
113
  end
114
+
115
+ def text_node(value, options={})
116
+ Glyph::TextNode.new.from({:value => value}.merge options)
117
+ end
118
+
119
+ def escape_node(value, options={})
120
+ Glyph::EscapeNode.new.from({:value => value, :escaped => true})
121
+ end
122
+
123
+ def document_node
124
+ Glyph::DocumentNode.new.from({:name => "--".to_sym})
125
+ end
126
+
127
+ def a_node(name, options={})
128
+ Glyph::AttributeNode.new.from({
129
+ :name => :"#{name}",
130
+ :escape => false}.merge(options))
131
+ end
132
+
133
+ def p_node(n)
134
+ Glyph::ParameterNode.new.from({:name => :"#{n}"})
135
+ end
136
+
137
+ def macro_node(name, options={})
138
+ Glyph::MacroNode.new.from({
139
+ :name => name.to_sym,
140
+ :escape => false
141
+ }.merge options)
142
+ end
@@ -35,13 +35,24 @@ describe "load" do
35
35
  Glyph::MACROS[:"#"].blank?.should == false
36
36
  end
37
37
 
38
+ it "[macros] should be able to load only core macros" do
39
+ language 'core'
40
+ output_for("$:[language.set|glyph]").blank?.should == true
41
+ Glyph['language.set'].should == 'glyph'
42
+ end
43
+
44
+ it "[macros] should be able to load only filter macros" do
45
+ language 'filters'
46
+ output_for("textile[*test*]").should == "<p><strong>test</strong></p>"
47
+ end
48
+
38
49
  it "[config] should load configuration files and apply overrides" do
39
50
  Glyph.config_refresh
40
51
  lambda { Glyph.run! 'load:config'}.should_not raise_error
41
- Glyph[:quiet] = true
52
+ Glyph['system.quiet'] = true
42
53
  Glyph::PROJECT_CONFIG.blank?.should == false
43
54
  Glyph::SYSTEM_CONFIG.blank?.should == false
44
- Glyph['structure.headers'].class.to_s.should == "Array"
55
+ Glyph['system.structure.headers'].class.to_s.should == "Array"
45
56
  end
46
57
 
47
58
  end
data/styles/default.css CHANGED
@@ -31,7 +31,7 @@ body {
31
31
  }
32
32
 
33
33
  /* Structure */
34
- .titlepage {
34
+ .halftitlepage, .titlepage {
35
35
  margin: auto;
36
36
  text-align: center;
37
37
  }
@@ -41,7 +41,7 @@ body {
41
41
  line-height: 1.5em;
42
42
  margin-bottom: 0.2em;
43
43
  }
44
- .titlepage h2 {
44
+ .halftitlepage h2, .titlepage h2 {
45
45
  font-size: 1.1em;
46
46
  font-style: italic;
47
47
  font-weight: bold;
@@ -128,6 +128,13 @@ sup {
128
128
  background: #EEE;
129
129
  color: #1F1F1F;
130
130
  }
131
+ .note>p,
132
+ .important>p,
133
+ .tip>p,
134
+ .caution>p {
135
+ margin: 0;
136
+ padding: 0;
137
+ }
131
138
  .note-title {
132
139
  font-weight: bold;
133
140
  margin-right: 1em;
@@ -197,8 +204,13 @@ code, pre {
197
204
  font-size: 0.75em;
198
205
  }
199
206
  pre{
200
- margin: 1em;
201
- padding: 1em;
207
+ border: 1px solid #cecece;
208
+ padding: 0.5em;
209
+ background: #ededed;
210
+ }
211
+ span.line-numbers{
212
+ margin: 0;
213
+ padding: 3px;
202
214
  }
203
215
 
204
216
  pre>code {
@@ -214,11 +226,11 @@ td>div.code, td>code {
214
226
  }
215
227
 
216
228
  /* FONTS */
229
+
217
230
  body {
218
- font-family: "Book Antiqua", "Times New Roman", "Serif";
231
+ font-family: "Gentium Book Basic", "Book Antiqua", "Times New Roman", "Serif";
219
232
  }
220
233
 
221
234
  code, pre {
222
235
  font-family: "Droid Sans Mono", "Consolas", "Monaco", "Courier", "Monospace";
223
236
  }
224
-
@@ -1,21 +1,3 @@
1
- /* FONTS */
2
-
3
- @font-face {
4
- font-family: "Serif"
5
- src: local("Book Antiqua")
6
- }
7
-
8
- @font-face {
9
- font-family: "Monospace"
10
- src: local("Droid Sans Mono")
11
- }
12
- body {
13
- font-family: "Book Antiqua", "Times New Roman", "Serif";
14
- }
15
-
16
- code, pre {
17
- font-family: "Droid Sans Mono", "Consolas", "Monaco", "Courier", "Monospace";
18
- }
19
1
  @page {
20
2
  size: A4;
21
3
  margin: 40pt 30pt 40pt 30pt;
@@ -187,7 +169,7 @@ h2 {
187
169
  page-break-before: always;
188
170
  }
189
171
 
190
- .titlepage h2 {
172
+ .halftitlepage h2, .titlepage h2 {
191
173
  page-break-before: avoid;
192
174
  }
193
175
 
data/tasks/generate.rake CHANGED
@@ -4,13 +4,13 @@ namespace :generate do
4
4
 
5
5
  desc "Process source"
6
6
  task :document => ["load:all"] do
7
- Glyph.info "Parsing '#{Glyph['document.source']}'..."
8
7
  if Glyph.lite? then
9
8
  text = file_load Pathname.new(Glyph['document.source'])
10
9
  else
11
10
  text = file_load Glyph::PROJECT/Glyph['document.source']
12
11
  end
13
- interpreter = Glyph::Interpreter.new text, :source => "file: #{Glyph['document.source']}"
12
+ interpreter = Glyph::Interpreter.new text, :source => {:name => "#{Glyph['document.source']}"}, :info => true
13
+ interpreter.parse
14
14
  Glyph.info "Processing..."
15
15
  interpreter.process
16
16
  Glyph.info "Post-processing..."