glyph 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
@@ -1,27 +0,0 @@
1
- grammar GlyphLanguage
2
-
3
- rule expression
4
- (escaping_macro / macro / escaped_text)* <GlyphSyntaxNode>
5
- end
6
-
7
- rule escaping_macro
8
- macro_name '[=' text '=]' <EscapingMacroNode>
9
- end
10
-
11
- rule macro
12
- macro_name '[' expression ']' <MacroNode>
13
- end
14
-
15
- rule escaped_text
16
- (('\\' .) / !((macro_name ('[' / '[=')) / (']' / '=]')) .)+ <TextNode>
17
- end
18
-
19
- rule text
20
- (('\\' .) / !((macro_name '[=') / '=]') .)+ <TextNode>
21
- end
22
-
23
- rule macro_name
24
- [^\[\]\|\\\s]+
25
- end
26
-
27
- end
data/macros/common.rb DELETED
@@ -1,160 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- macro :snippet do
4
- ident = @value.to_sym
5
- if Glyph::SNIPPETS.has_key? ident then
6
- begin
7
- interpret Glyph::SNIPPETS[ident]
8
- rescue Exception => e
9
- raise if e.is_a? Glyph::MutualInclusionError
10
- Glyph.warning e.message
11
- macro_todo "Correct errors in snippet '#{@value}'"
12
- end
13
- else
14
- macro_warning "Snippet '#{ident}' does not exist"
15
- "[SNIPPET '#{@value}' NOT PROCESSED]"
16
- end
17
- end
18
-
19
- macro "snippet:" do
20
- exact_parameters 2
21
- ident, text = params
22
- Glyph::SNIPPETS[ident.to_sym] = text
23
- ""
24
- end
25
-
26
- macro "macro:" do
27
- exact_parameters 2
28
- ident, code = params
29
- Glyph.macro(ident) do
30
- instance_eval code
31
- end
32
- ""
33
- end
34
-
35
- macro :include do
36
- macro_error "Macro not available when compiling a single file." if Glyph.lite?
37
- file = nil
38
- (Glyph::PROJECT/"text").find do |f|
39
- file = f if f.to_s.match /\/#{@value}$/
40
- end
41
- if file then
42
- contents = file_load file
43
- ext = @value.match(/\.(.*)$/)[1]
44
- if Glyph["filters.by_file_extension"] && ext != 'glyph' then
45
- if Glyph::MACROS.include?(ext.to_sym) then
46
- contents = "#{ext}[#{contents}]"
47
- else
48
- macro_warning "Filter macro '#{ext}' not available"
49
- end
50
- end
51
- begin
52
- interpret contents
53
- rescue Exception => e
54
- raise if e.is_a? Glyph::MutualInclusionError
55
- Glyph.warning e.message
56
- macro_todo "Correct errors in file '#{@value}'"
57
- end
58
- else
59
- macro_warning "File '#{@value}' no found."
60
- "[FILE '#{@value}' NOT FOUND]"
61
- end
62
- end
63
-
64
- macro :ruby do
65
- res = Glyph.instance_eval(@value.gsub(/\\*([\[\]\|])/){$1})
66
- res.is_a?(Proc) ? "" : res
67
- end
68
-
69
- macro :config do
70
- Glyph[@value]
71
- end
72
-
73
- macro "config:" do
74
- exact_parameters 2
75
- setting,value = params
76
- Glyph[setting] = value
77
- nil
78
- end
79
-
80
- macro :comment do
81
- ""
82
- end
83
-
84
- macro :escape do
85
- @value
86
- end
87
-
88
- macro :encode do
89
- encode @value
90
- end
91
-
92
- macro :decode do
93
- decode @value
94
- end
95
-
96
- macro :condition do
97
- min_parameters 1
98
- max_parameters 2
99
- cond, actual_value = params
100
- res = interpret(cond)
101
- if res.blank? || res == "false" then
102
- ""
103
- else
104
- interpret(decode(actual_value))
105
- end
106
- end
107
-
108
-
109
- macro :eq do
110
- min_parameters 1
111
- max_parameters 2
112
- a, b = params
113
- res_a = interpret(a.to_s)
114
- res_b = interpret(b.to_s)
115
- (res_a == res_b) ? true : nil
116
- end
117
-
118
- macro :not do
119
- max_parameters 1
120
- v = interpret(@value)
121
- (v.blank? || v == "false") ? true : nil
122
- end
123
-
124
- macro :and do
125
- min_parameters 1
126
- max_parameters 2
127
- a, b = params
128
- res_a = !interpret(a.to_s).blank?
129
- res_b = !interpret(b.to_s).blank?
130
- (res_a && res_b) ? true : nil
131
- end
132
-
133
- macro :or do
134
- min_parameters 1
135
- max_parameters 2
136
- a, b = params
137
- res_a = !interpret(a.to_s).blank?
138
- res_b = !interpret(b.to_s).blank?
139
- (res_a || res_b) ? true : nil
140
- end
141
-
142
- macro :match do
143
- exact_parameters 2
144
- val, regexp = params
145
- macro_error "Invalid regular expression: #{regexp}" unless regexp.match /^\/.*\/[a-z]?$/
146
- (interpret(val).match(instance_eval(regexp))) ? true : nil
147
- end
148
-
149
- macro_alias '--' => :comment
150
- macro_alias '*' => :encode
151
- macro_alias '**' => :decode
152
- macro_alias '&' => :snippet
153
- macro_alias '&:' => 'snippet:'
154
- macro_alias '%:' => 'macro:'
155
- macro_alias '@' => :include
156
- macro_alias '%' => :ruby
157
- macro_alias '$' => :config
158
- macro_alias '$:' => 'config:'
159
- macro_alias '.' => :escape
160
- macro_alias '?' => :condition