glyph 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. data/AUTHORS.textile +8 -0
  2. data/CHANGELOG.textile +260 -0
  3. data/LICENSE.textile +26 -0
  4. data/README.textile +49 -21
  5. data/Rakefile +17 -7
  6. data/VERSION +1 -1
  7. data/book/config.yml +11 -5
  8. data/book/document.glyph +24 -13
  9. data/book/lib/macros/reference.rb +41 -14
  10. data/book/output/html/glyph.html +2298 -687
  11. data/book/output/pdf/glyph.pdf +6218 -2698
  12. data/book/script/authors +1 -0
  13. data/book/script/changelog +1 -0
  14. data/book/script/compile.rb +8 -0
  15. data/book/script/license +1 -0
  16. data/book/script/prof +1 -0
  17. data/book/script/prof_results.htm +21079 -0
  18. data/book/script/readme +1 -0
  19. data/book/snippets.yml +3 -4
  20. data/book/text/acknowledgement.glyph +8 -0
  21. data/book/text/authoring.glyph +548 -0
  22. data/book/text/changelog.glyph +76 -0
  23. data/book/text/extending.glyph +224 -0
  24. data/book/text/{getting_started.textile → getting_started.glyph} +30 -24
  25. data/book/text/{introduction.textile → introduction.glyph} +22 -12
  26. data/book/text/license.glyph +21 -0
  27. data/book/text/{ref_commands.textile → ref_commands.glyph} +30 -8
  28. data/book/text/ref_config.glyph +108 -0
  29. data/book/text/ref_macros.glyph +378 -0
  30. data/book/text/troubleshooting.glyph +179 -0
  31. data/config.yml +16 -4
  32. data/glyph.gemspec +83 -22
  33. data/lib/glyph.rb +164 -31
  34. data/lib/glyph/commands.rb +98 -23
  35. data/lib/glyph/document.rb +13 -7
  36. data/lib/glyph/glyph_language.rb +9 -1
  37. data/lib/glyph/glyph_language.treetop +1 -1
  38. data/lib/glyph/interpreter.rb +19 -9
  39. data/lib/glyph/macro.rb +88 -11
  40. data/lib/glyph/macro_validators.rb +48 -0
  41. data/lib/glyph/node.rb +13 -1
  42. data/lib/glyph/system_extensions.rb +0 -28
  43. data/macros/common.rb +125 -31
  44. data/macros/filters.rb +19 -13
  45. data/macros/html/block.rb +119 -68
  46. data/macros/html/inline.rb +29 -3
  47. data/macros/html/structure.rb +40 -40
  48. data/spec/files/article.glyph +5 -0
  49. data/spec/lib/commands_spec.rb +98 -3
  50. data/spec/lib/document_spec.rb +15 -2
  51. data/spec/lib/glyph_spec.rb +39 -10
  52. data/spec/lib/interpreter_spec.rb +8 -2
  53. data/spec/lib/macro_spec.rb +54 -6
  54. data/spec/lib/macro_validators_spec.rb +33 -0
  55. data/spec/lib/node_spec.rb +11 -3
  56. data/spec/macros/filters_spec.rb +5 -5
  57. data/spec/macros/macros_spec.rb +185 -8
  58. data/spec/macros/textile_spec.rb +217 -0
  59. data/spec/spec_helper.rb +25 -15
  60. data/spec/tasks/generate_spec.rb +3 -3
  61. data/spec/tasks/load_spec.rb +11 -1
  62. data/spec/tasks/project_spec.rb +0 -3
  63. data/styles/coderay.css +121 -0
  64. data/styles/default.css +54 -20
  65. data/{book/styles/css3.css → styles/pagination.css} +35 -7
  66. data/styles/ultraviolet/active4d.css +114 -0
  67. data/styles/ultraviolet/all_hallows_eve.css +72 -0
  68. data/styles/ultraviolet/amy.css +147 -0
  69. data/styles/ultraviolet/blackboard.css +88 -0
  70. data/styles/ultraviolet/brilliance_black.css +605 -0
  71. data/styles/ultraviolet/brilliance_dull.css +599 -0
  72. data/styles/ultraviolet/cobalt.css +149 -0
  73. data/styles/ultraviolet/dawn.css +121 -0
  74. data/styles/ultraviolet/eiffel.css +121 -0
  75. data/styles/ultraviolet/espresso_libre.css +109 -0
  76. data/styles/ultraviolet/idle.css +62 -0
  77. data/styles/ultraviolet/iplastic.css +80 -0
  78. data/styles/ultraviolet/lazy.css +73 -0
  79. data/styles/ultraviolet/mac_classic.css +123 -0
  80. data/styles/ultraviolet/magicwb_amiga.css +104 -0
  81. data/styles/ultraviolet/pastels_on_dark.css +188 -0
  82. data/styles/ultraviolet/slush_poppies.css +85 -0
  83. data/styles/ultraviolet/spacecadet.css +51 -0
  84. data/styles/ultraviolet/sunburst.css +180 -0
  85. data/styles/ultraviolet/twilight.css +137 -0
  86. data/styles/ultraviolet/zenburnesque.css +91 -0
  87. data/tasks/generate.rake +45 -26
  88. data/tasks/load.rake +21 -18
  89. data/tasks/project.rake +3 -1
  90. metadata +210 -41
  91. data/book/styles/default.css +0 -190
  92. data/book/text/authoring.textile +0 -351
  93. data/book/text/extending.textile +0 -148
  94. data/book/text/ref_config.textile +0 -0
  95. data/book/text/ref_macros.textile +0 -256
  96. data/book/text/troubleshooting.textile +0 -118
  97. data/styles/css3.css +0 -220
@@ -0,0 +1,217 @@
1
+ #!/usr/bin/env ruby
2
+ require File.join(File.dirname(__FILE__), "..", "spec_helper")
3
+
4
+ describe "Textile Markup" do
5
+
6
+ before do
7
+ @textile =
8
+ %{This is a _test_:
9
+ * item A
10
+ * item B
11
+ * item C
12
+
13
+ <div class="test">_hello!_
14
+ </div>
15
+ Testing:
16
+ # A
17
+ # B
18
+ # C}
19
+ @html =
20
+ %{<p>This is a <em>test</em>:</p>
21
+ <ul>
22
+ <li>item A</li>
23
+ <li>item B</li>
24
+ <li>item C</li>
25
+ </ul>
26
+ <div class="test"><em>hello!</em></div>
27
+ <p>Testing:</p>
28
+ <ol>
29
+ <li>A</li>
30
+ <li>B</li>
31
+ <li>C</li>
32
+ </ol>}
33
+ end
34
+
35
+ ######################################
36
+
37
+ it "should be embeddable in section macros" do
38
+ text1 =
39
+ %{textile[section[header[Test]
40
+ #@textile
41
+ ]]}
42
+ text2 =
43
+ %{textile[section[header[Test]#@textile
44
+ ]]}
45
+ result =
46
+ %{<div class="section">
47
+ <h2 id="h_1">Test</h2>
48
+ #@html
49
+ </div>}
50
+ filter(text1).should == result
51
+ filter(text2).gsub(/<\/h2>/, "</h2>\n").should == result
52
+ end
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
+ ######################################
113
+
114
+ it "should be embeddable in box macros" do
115
+ result =
116
+ %{<div class="box">
117
+ <div class="box-title">This is a <em>test</em></div>
118
+ #@html
119
+ </div>}
120
+ box1 = %{textile[box[This is a _test_|#@textile]]}
121
+ box2 = %{textile[box[This is a _test_|
122
+ #@textile]
123
+ ]}
124
+ box3 = %{textile[box[
125
+ This is a _test_|
126
+ #@textile]]}
127
+ box4 = %{textile[box[This is a _test_|
128
+ #@textile
129
+ ]
130
+ ]}
131
+ filter(box1).should == result
132
+ filter(box2).should == result
133
+ filter(box3).should == result
134
+ filter(box4).should == result
135
+ end
136
+
137
+ ######################################
138
+
139
+ it "should be embeddable in note macros" do
140
+ result =
141
+ %{<div class="note">
142
+ <p><span class="note-title">Note</span>#{@html.sub(/^<p>/, '')}
143
+ </div>}
144
+ note1 = %{textile[note[#@textile]]}
145
+ note2 = %{textile[note[
146
+ #@textile]
147
+ ]}
148
+ note3 = %{textile[note[
149
+ #@textile]]}
150
+ note4 = %{textile[note[
151
+ #@textile
152
+ ]
153
+ ]}
154
+ filter(note1).should == result
155
+ filter(note2).should == result
156
+ filter(note3).should == result
157
+ filter(note4).should == result
158
+ end
159
+
160
+ ######################################
161
+
162
+ it "should not interfere with the code macro" do
163
+ code =
164
+ %{<div class="test">
165
+ <p><em>Test: </em> Paragraph.</p>
166
+ </div>}
167
+ result =
168
+ %{<div class="section">
169
+ <h2 id="h_1">Test</h2>
170
+ #@html
171
+ <div class="code">
172
+ <pre>
173
+ <code>
174
+ #{code.gsub(/>/, '&gt;').gsub(/</, '&lt;')}
175
+ </code>
176
+ </pre>
177
+ </div>
178
+ </div>}
179
+ text1 = %{textile[
180
+ section[header[Test]
181
+ #@textile
182
+ code[#{code}]
183
+ ]]}
184
+ text2 = %{textile[
185
+ section[header[Test]
186
+ #@textile
187
+ code[#{code}
188
+ ]
189
+ ]
190
+ ]}
191
+ text3 = %{textile[
192
+ section[header[Test]
193
+ #@textile
194
+ code[
195
+ #{code}]
196
+ ]]}
197
+ text4 = %{textile[
198
+ section[header[Test]
199
+ #@textile
200
+ code[
201
+ #{code}
202
+ ]]]}
203
+ text5 = %{textile[
204
+ section[header[Test]
205
+ #@textile
206
+ code[
207
+ #{code}
208
+ ]
209
+ ]]}
210
+ filter(text1).should == result
211
+ filter(text2).should == result
212
+ filter(text3).should == result
213
+ filter(text4).should == result
214
+ filter(text5).should == result
215
+ end
216
+
217
+ end
data/spec/spec_helper.rb CHANGED
@@ -6,23 +6,29 @@ require "stringio"
6
6
  module Glyph; end
7
7
 
8
8
  begin
9
- unless Glyph.const_defined? :TEST_MODE then
10
- Glyph::TEST_MODE = true
9
+ unless Glyph.const_defined? :MODE then
10
+ Glyph::MODE = {:debug => false, :lite => false, :test => true}
11
11
  end
12
- rescue Exception => e
12
+ rescue
13
13
  end
14
14
 
15
15
  require "glyph"
16
16
 
17
- Glyph.config_override :quiet, true
17
+ Glyph[:quiet] = true
18
18
 
19
19
  def create_project_dir
20
20
  Glyph::PROJECT.mkpath
21
21
  end
22
22
 
23
+ def reset_quiet
24
+ Glyph.reset
25
+ Glyph[:quiet] = true
26
+ end
27
+
23
28
  def create_project
24
- enable_all_tasks
29
+ reset_quiet
25
30
  create_project_dir
31
+ return if Glyph.lite?
26
32
  Glyph.run! 'project:create', Glyph::PROJECT.to_s
27
33
  file_copy Glyph::SPEC_DIR/'files/container.textile', Glyph::PROJECT/'text/container.textile'
28
34
  (Glyph::PROJECT/'text/a/b/c').mkpath
@@ -33,20 +39,20 @@ def create_project
33
39
  file_copy Glyph::SPEC_DIR/'files/ligature.jpg', Glyph::PROJECT/'images/ligature.jpg'
34
40
  end
35
41
 
36
- def enable_all_tasks
37
- Rake::Task.tasks.each {|t| t.reenable }
38
- end
39
-
40
42
  def delete_project_dir
41
- FileUtils.rm_rf Glyph::PROJECT.to_s
43
+ return unless Glyph::PROJECT.exist?
44
+ Glyph::PROJECT.children.each do |f|
45
+ FileUtils.rmtree f if f.directory?
46
+ FileUtils.rm f if f.file?
47
+ end
42
48
  end
43
49
 
44
50
  def delete_project
45
51
  delete_project_dir
46
52
  Glyph::SNIPPETS.clear
47
53
  Glyph::MACROS.clear
48
- Glyph.config_override 'document.source', 'document.glyph'
49
- Glyph.instance_eval { remove_const :DOCUMENT rescue nil }
54
+ Glyph['document.source'] = 'document.glyph'
55
+ Glyph.document = nil
50
56
  end
51
57
 
52
58
  def run_command(cmd)
@@ -55,9 +61,9 @@ def run_command(cmd)
55
61
  old_stderr = $stderr
56
62
  $stdout = out
57
63
  $stderr = out
58
- Glyph.config_override :quiet, false
64
+ Glyph[:quiet] = false
59
65
  GLI.run cmd
60
- Glyph.config_override :quiet, true
66
+ Glyph[:quiet] = true
61
67
  $stdout = old_stdout
62
68
  $stderr = old_stderr
63
69
  out.string
@@ -75,7 +81,7 @@ end
75
81
 
76
82
  def define_ref_macro
77
83
  Glyph.macro :ref do
78
- %{<a href="#{@params[0]}">#{@params[1]}</a>}
84
+ %{<a href="#{params[0]}">#{params[1]}</a>}
79
85
  end
80
86
  end
81
87
 
@@ -90,3 +96,7 @@ end
90
96
  def create_doc(tree)
91
97
  Glyph::Document.new tree, {}
92
98
  end
99
+
100
+ def filter(text)
101
+ Glyph.filter text
102
+ end
@@ -10,10 +10,10 @@ describe "generate" do
10
10
  after do
11
11
  delete_project
12
12
  end
13
-
14
- it ":document should generate Glyph::DOCUMENT" do
13
+
14
+ it ":document should generate Glyph.document" do
15
15
  lambda { Glyph.run! 'generate:document'}.should_not raise_error
16
- Glyph::DOCUMENT.structure.children.length.should > 0
16
+ Glyph.document.structure.children.length.should > 0
17
17
  end
18
18
 
19
19
  it ":html should generate a standalone html document" do
@@ -22,6 +22,13 @@ describe "load" do
22
22
  Glyph::SNIPPETS[:test].blank?.should == false
23
23
  end
24
24
 
25
+ it "[snippets] should not load snippets.xml in Lite mode" do
26
+ Glyph.lite_mode = true
27
+ lambda { Glyph.run! 'load:snippets'}.should_not raise_error
28
+ Glyph::SNIPPETS[:test].blank?.should == true
29
+ Glyph.lite_mode = false
30
+ end
31
+
25
32
  it "[macros] should load macro definitions" do
26
33
  lambda { Glyph.run! 'load:macros'}.should_not raise_error
27
34
  Glyph::MACROS[:note].blank?.should == false
@@ -29,9 +36,12 @@ describe "load" do
29
36
  end
30
37
 
31
38
  it "[config] should load configuration files and apply overrides" do
39
+ Glyph.config_refresh
40
+ lambda { Glyph.run! 'load:config'}.should_not raise_error
41
+ Glyph[:quiet] = true
32
42
  Glyph::PROJECT_CONFIG.blank?.should == false
33
43
  Glyph::SYSTEM_CONFIG.blank?.should == false
34
- cfg('structure.headers').class.to_s.should == "Array"
44
+ Glyph['structure.headers'].class.to_s.should == "Array"
35
45
  end
36
46
 
37
47
  end
@@ -18,9 +18,6 @@ describe "project:create" do
18
18
  it "[create] should create a new project if an existing empty directory is supplied" do
19
19
  lambda { Glyph.run! 'project:create', Glyph::PROJECT }.should_not raise_error
20
20
  (Glyph::PROJECT/'lib').exist?.should == true
21
- (Glyph::PROJECT/'lib/tasks').exist?.should == true
22
- (Glyph::PROJECT/'lib/macros').exist?.should == true
23
- (Glyph::PROJECT/'lib/macros/html').exist?.should == true
24
21
  (Glyph::PROJECT/'document.glyph').exist?.should == true
25
22
  (Glyph::PROJECT/'config.yml').exist?.should == true
26
23
  (Glyph::PROJECT/'text').exist?.should == true
@@ -0,0 +1,121 @@
1
+ .CodeRay {
2
+ background-color: #f8f8f8;
3
+ border: 1px solid silver;
4
+ font-family: 'Courier New', 'Terminal', monospace;
5
+ color: #000;
6
+ }
7
+ .CodeRay pre { margin: 0px; }
8
+
9
+ span.CodeRay { white-space: pre; border: 0px; padding: 2px; }
10
+
11
+ table.CodeRay { border-collapse: collapse; width: 100%; padding: 2px; }
12
+ table.CodeRay td { padding: 2px 4px; vertical-align: top; }
13
+
14
+ .CodeRay .line_numbers, .CodeRay .no {
15
+ background-color: #def;
16
+ color: gray;
17
+ text-align: right;
18
+ }
19
+ .CodeRay .line_numbers a:target, .CodeRay .no a:target { color: blue; }
20
+ .CodeRay .line_numbers .highlighted, .CodeRay .no .highlighted { color: red; }
21
+ .CodeRay .no { padding: 0px 4px; }
22
+ .CodeRay .code { width: 100%; }
23
+ .CodeRay .code pre { overflow: auto; }
24
+
25
+ .CodeRay .debug { color:white ! important; background:blue ! important; }
26
+
27
+ .CodeRay .an { color:#007 }
28
+ .CodeRay .at { color:#f08 }
29
+ .CodeRay .av { color:#700 }
30
+ .CodeRay .bi { color:#509; font-weight:bold }
31
+ .CodeRay .c { color:#888; }
32
+ .CodeRay .c .dl { color:#444; }
33
+ .CodeRay .c .ch { color:#444; }
34
+
35
+ .CodeRay .ch { color:#04D }
36
+ .CodeRay .ch .k { color:#04D }
37
+ .CodeRay .ch .dl { color:#039 }
38
+
39
+ .CodeRay .cl { color:#B06; font-weight:bold }
40
+ .CodeRay .cm { color:#A08; font-weight:bold }
41
+ .CodeRay .co { color:#036; font-weight:bold }
42
+ .CodeRay .cr { color:#0A0 }
43
+ .CodeRay .cv { color:#369 }
44
+ .CodeRay .de { color:#B0B; }
45
+ .CodeRay .df { color:#099; font-weight:bold }
46
+ .CodeRay .di { color:#088; font-weight:bold }
47
+ .CodeRay .dl { color:black }
48
+ .CodeRay .do { color:#970 }
49
+ .CodeRay .dt { color:#34b }
50
+ .CodeRay .ds { color:#D42; font-weight:bold }
51
+ .CodeRay .e { color:#666; font-weight:bold }
52
+ .CodeRay .en { color:#800; font-weight:bold }
53
+ .CodeRay .er { color:#F00; background-color:#FAA }
54
+ .CodeRay .ex { color:#C00; font-weight:bold }
55
+ .CodeRay .fl { color:#60E; font-weight:bold }
56
+ .CodeRay .fu { color:#06B; font-weight:bold }
57
+ .CodeRay .gv { color:#d70; font-weight:bold }
58
+ .CodeRay .hx { color:#058; font-weight:bold }
59
+ .CodeRay .i { color:#00D; font-weight:bold }
60
+ .CodeRay .ic { color:#B44; font-weight:bold }
61
+
62
+ .CodeRay .il { background-color: hsla(0,0%,0%,0.1); color: black }
63
+ .CodeRay .il .idl { font-weight: bold; color: #666 }
64
+ .CodeRay .idl { font-weight: bold; color: #666; }
65
+
66
+ .CodeRay .im { color:#f00; }
67
+ .CodeRay .in { color:#B2B; font-weight:bold }
68
+ .CodeRay .iv { color:#33B }
69
+ .CodeRay .la { color:#970; font-weight:bold }
70
+ .CodeRay .lv { color:#963 }
71
+ .CodeRay .ns { color:#707; font-weight:bold }
72
+ .CodeRay .oc { color:#40E; font-weight:bold }
73
+ .CodeRay .op { }
74
+ .CodeRay .pc { color:#058; font-weight:bold }
75
+ .CodeRay .pd { color:#369; font-weight:bold }
76
+ .CodeRay .pp { color:#579; }
77
+ .CodeRay .ps { color:#00C; font-weight:bold }
78
+ .CodeRay .pt { color:#074; font-weight:bold }
79
+ .CodeRay .r, .kw { color:#080; font-weight:bold }
80
+
81
+ .CodeRay .ke { color: #808; }
82
+ .CodeRay .ke .dl { color: #606; }
83
+ .CodeRay .ke .ch { color: #80f; }
84
+ .CodeRay .vl { color: #088; }
85
+
86
+ .CodeRay .rx { background-color:hsla(300,100%,50%,0.1); color:#808 }
87
+ .CodeRay .rx .k { }
88
+ .CodeRay .rx .dl { color:#404 }
89
+ .CodeRay .rx .mod { color:#C2C }
90
+ .CodeRay .rx .fu { color:#404; font-weight: bold }
91
+
92
+ .CodeRay .s { background-color:hsla(0,100%,50%,0.1); color: #D20; }
93
+ .CodeRay .s .k { }
94
+ .CodeRay .s .ch { color: #b0b; }
95
+ .CodeRay .s .dl { color: #710; }
96
+
97
+ .CodeRay .sh { background-color:hsla(120,100%,50%,0.1); color:#2B2 }
98
+ .CodeRay .sh .k { }
99
+ .CodeRay .sh .dl { color:#161 }
100
+
101
+ .CodeRay .sy { color:#A60 }
102
+ .CodeRay .sy .k { color:#A60 }
103
+ .CodeRay .sy .dl { color:#630 }
104
+
105
+ .CodeRay .ta { color:#070 }
106
+ .CodeRay .ts { color:#D70; font-weight:bold }
107
+ .CodeRay .ty { color:#339; font-weight:bold }
108
+ .CodeRay .v { color:#036 }
109
+ .CodeRay .xt { color:#444 }
110
+
111
+ .CodeRay .ins { background: #afa; }
112
+ .CodeRay .del { background: #faa; }
113
+ .CodeRay .chg { color: #aaf; background: #007; }
114
+ .CodeRay .head { color: #f8f; background: #505 }
115
+ .CodeRay .head .filename { color: white; }
116
+
117
+ .CodeRay .ins .ins { color: #080; font-weight:bold }
118
+ .CodeRay .del .del { color: #800; font-weight:bold }
119
+ .CodeRay .chg .chg { color: #66f; }
120
+ .CodeRay .head .head { color: #f4f; }
121
+