radiant 0.6.6 → 0.6.7

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 (208) hide show
  1. data/CHANGELOG +15 -0
  2. data/CONTRIBUTORS +8 -0
  3. data/app/controllers/admin/page_controller.rb +1 -11
  4. data/app/controllers/admin/welcome_controller.rb +5 -6
  5. data/app/controllers/application.rb +2 -0
  6. data/app/controllers/site_controller.rb +1 -0
  7. data/app/helpers/admin/page_helper.rb +36 -0
  8. data/app/helpers/admin/regions_helper.rb +28 -0
  9. data/app/helpers/admin/user_helper.rb +6 -0
  10. data/app/helpers/application_helper.rb +2 -1
  11. data/app/models/user.rb +7 -8
  12. data/app/views/admin/extension/index.html.haml +28 -0
  13. data/app/views/admin/layout/edit.html.haml +44 -0
  14. data/app/views/admin/layout/index.html.haml +25 -0
  15. data/app/views/admin/layout/remove.html.haml +16 -0
  16. data/app/views/admin/page/_meta_row.html.haml +6 -0
  17. data/app/views/admin/page/_node.html.haml +25 -0
  18. data/app/views/admin/page/_part.html.haml +17 -0
  19. data/app/views/admin/page/_tag_reference.html.haml +3 -0
  20. data/app/views/admin/page/children.html.haml +2 -0
  21. data/app/views/admin/page/edit.html.haml +114 -0
  22. data/app/views/admin/page/index.html.haml +28 -0
  23. data/app/views/admin/page/remove.html.haml +20 -0
  24. data/app/views/admin/snippet/edit.html.haml +36 -0
  25. data/app/views/admin/snippet/index.html.haml +20 -0
  26. data/app/views/admin/snippet/remove.html.haml +19 -0
  27. data/app/views/admin/user/edit.html.haml +80 -0
  28. data/app/views/admin/user/index.html.haml +23 -0
  29. data/app/views/admin/user/preferences.html.haml +28 -0
  30. data/app/views/admin/user/remove.html.haml +18 -0
  31. data/app/views/admin/welcome/login.html.haml +44 -0
  32. data/app/views/layouts/application.html.haml +54 -0
  33. data/app/views/site/not_found.html.haml +3 -0
  34. data/db/migrate/019_add_salt_to_users.rb +11 -0
  35. data/db/schema.rb +2 -1
  36. data/lib/login_system.rb +1 -0
  37. data/lib/radiant.rb +1 -1
  38. data/lib/radiant/admin_ui.rb +65 -0
  39. data/lib/radiant/admin_ui/region_partials.rb +18 -0
  40. data/lib/radiant/admin_ui/region_set.rb +35 -0
  41. data/lib/tasks/extensions.rake +33 -0
  42. data/public/javascripts/admin/admin.js +8 -2
  43. data/public/javascripts/admin/sitemap.js +2 -1
  44. data/public/stylesheets/admin/main.css +4 -0
  45. data/spec/controllers/admin/abstract_model_controller_spec.rb +2 -0
  46. data/spec/controllers/admin/page_controller_spec.rb +3 -28
  47. data/spec/controllers/admin/user_controller_spec.rb +1 -1
  48. data/spec/controllers/admin/welcome_controller_spec.rb +26 -0
  49. data/spec/helpers/admin/page_helper_spec.rb +4 -0
  50. data/spec/helpers/admin/regions_helper_spec.rb +47 -0
  51. data/spec/helpers/admin/user_helper_spec.rb +7 -0
  52. data/spec/helpers/application_helper_spec.rb +7 -3
  53. data/spec/lib/login_system_spec.rb +5 -0
  54. data/spec/lib/radiant/admin_ui/region_partials_spec.rb +35 -0
  55. data/spec/lib/radiant/admin_ui/region_set_spec.rb +61 -0
  56. data/spec/lib/radiant/admin_ui_spec.rb +74 -18
  57. data/spec/models/user_spec.rb +11 -4
  58. data/spec/scenarios/users_scenario.rb +2 -2
  59. data/vendor/plugins/haml/MIT-LICENSE +20 -0
  60. data/vendor/plugins/haml/README.rdoc +319 -0
  61. data/vendor/plugins/haml/Rakefile +158 -0
  62. data/vendor/plugins/haml/TODO +9 -0
  63. data/vendor/plugins/haml/VERSION +1 -0
  64. data/vendor/plugins/haml/bin/css2sass +7 -0
  65. data/vendor/plugins/haml/bin/haml +8 -0
  66. data/vendor/plugins/haml/bin/html2haml +7 -0
  67. data/vendor/plugins/haml/bin/sass +8 -0
  68. data/vendor/plugins/haml/extra/haml-mode.el +328 -0
  69. data/vendor/plugins/haml/extra/sass-mode.el +88 -0
  70. data/vendor/plugins/haml/init.rb +2 -0
  71. data/vendor/plugins/haml/lib/haml.rb +977 -0
  72. data/vendor/plugins/haml/lib/haml/buffer.rb +229 -0
  73. data/vendor/plugins/haml/lib/haml/engine.rb +274 -0
  74. data/vendor/plugins/haml/lib/haml/error.rb +23 -0
  75. data/vendor/plugins/haml/lib/haml/exec.rb +347 -0
  76. data/vendor/plugins/haml/lib/haml/filters.rb +249 -0
  77. data/vendor/plugins/haml/lib/haml/helpers.rb +413 -0
  78. data/vendor/plugins/haml/lib/haml/helpers/action_view_extensions.rb +45 -0
  79. data/vendor/plugins/haml/lib/haml/helpers/action_view_mods.rb +122 -0
  80. data/vendor/plugins/haml/lib/haml/html.rb +188 -0
  81. data/vendor/plugins/haml/lib/haml/precompiler.rb +757 -0
  82. data/vendor/plugins/haml/lib/haml/template.rb +43 -0
  83. data/vendor/plugins/haml/lib/haml/template/patch.rb +58 -0
  84. data/vendor/plugins/haml/lib/haml/template/plugin.rb +72 -0
  85. data/vendor/plugins/haml/lib/sass.rb +833 -0
  86. data/vendor/plugins/haml/lib/sass/constant.rb +245 -0
  87. data/vendor/plugins/haml/lib/sass/constant/color.rb +101 -0
  88. data/vendor/plugins/haml/lib/sass/constant/literal.rb +53 -0
  89. data/vendor/plugins/haml/lib/sass/constant/number.rb +87 -0
  90. data/vendor/plugins/haml/lib/sass/constant/operation.rb +30 -0
  91. data/vendor/plugins/haml/lib/sass/constant/string.rb +22 -0
  92. data/vendor/plugins/haml/lib/sass/css.rb +378 -0
  93. data/vendor/plugins/haml/lib/sass/engine.rb +459 -0
  94. data/vendor/plugins/haml/lib/sass/error.rb +35 -0
  95. data/vendor/plugins/haml/lib/sass/plugin.rb +165 -0
  96. data/vendor/plugins/haml/lib/sass/plugin/merb.rb +56 -0
  97. data/vendor/plugins/haml/lib/sass/plugin/rails.rb +24 -0
  98. data/vendor/plugins/haml/lib/sass/tree/attr_node.rb +53 -0
  99. data/vendor/plugins/haml/lib/sass/tree/comment_node.rb +20 -0
  100. data/vendor/plugins/haml/lib/sass/tree/directive_node.rb +46 -0
  101. data/vendor/plugins/haml/lib/sass/tree/node.rb +42 -0
  102. data/vendor/plugins/haml/lib/sass/tree/rule_node.rb +89 -0
  103. data/vendor/plugins/haml/lib/sass/tree/value_node.rb +16 -0
  104. data/vendor/plugins/haml/test/benchmark.rb +82 -0
  105. data/vendor/plugins/haml/test/haml/engine_test.rb +587 -0
  106. data/vendor/plugins/haml/test/haml/helper_test.rb +187 -0
  107. data/vendor/plugins/haml/test/haml/html2haml_test.rb +60 -0
  108. data/vendor/plugins/haml/test/haml/markaby/standard.mab +52 -0
  109. data/vendor/plugins/haml/test/haml/mocks/article.rb +6 -0
  110. data/vendor/plugins/haml/test/haml/results/content_for_layout.xhtml +16 -0
  111. data/vendor/plugins/haml/test/haml/results/eval_suppressed.xhtml +11 -0
  112. data/vendor/plugins/haml/test/haml/results/filters.xhtml +82 -0
  113. data/vendor/plugins/haml/test/haml/results/helpers.xhtml +94 -0
  114. data/vendor/plugins/haml/test/haml/results/helpful.xhtml +10 -0
  115. data/vendor/plugins/haml/test/haml/results/just_stuff.xhtml +64 -0
  116. data/vendor/plugins/haml/test/haml/results/list.xhtml +12 -0
  117. data/vendor/plugins/haml/test/haml/results/original_engine.xhtml +22 -0
  118. data/vendor/plugins/haml/test/haml/results/partials.xhtml +21 -0
  119. data/vendor/plugins/haml/test/haml/results/silent_script.xhtml +74 -0
  120. data/vendor/plugins/haml/test/haml/results/standard.xhtml +42 -0
  121. data/vendor/plugins/haml/test/haml/results/tag_parsing.xhtml +28 -0
  122. data/vendor/plugins/haml/test/haml/results/very_basic.xhtml +7 -0
  123. data/vendor/plugins/haml/test/haml/results/whitespace_handling.xhtml +94 -0
  124. data/vendor/plugins/haml/test/haml/rhtml/_av_partial_1.rhtml +12 -0
  125. data/vendor/plugins/haml/test/haml/rhtml/_av_partial_2.rhtml +8 -0
  126. data/vendor/plugins/haml/test/haml/rhtml/action_view.rhtml +62 -0
  127. data/vendor/plugins/haml/test/haml/rhtml/standard.rhtml +54 -0
  128. data/vendor/plugins/haml/test/haml/template_test.rb +168 -0
  129. data/vendor/plugins/haml/test/haml/templates/_av_partial_1.haml +9 -0
  130. data/vendor/plugins/haml/test/haml/templates/_av_partial_2.haml +5 -0
  131. data/vendor/plugins/haml/test/haml/templates/_partial.haml +8 -0
  132. data/vendor/plugins/haml/test/haml/templates/_text_area.haml +3 -0
  133. data/vendor/plugins/haml/test/haml/templates/action_view.haml +47 -0
  134. data/vendor/plugins/haml/test/haml/templates/breakage.haml +8 -0
  135. data/vendor/plugins/haml/test/haml/templates/content_for_layout.haml +10 -0
  136. data/vendor/plugins/haml/test/haml/templates/eval_suppressed.haml +11 -0
  137. data/vendor/plugins/haml/test/haml/templates/filters.haml +81 -0
  138. data/vendor/plugins/haml/test/haml/templates/helpers.haml +69 -0
  139. data/vendor/plugins/haml/test/haml/templates/helpful.haml +11 -0
  140. data/vendor/plugins/haml/test/haml/templates/just_stuff.haml +77 -0
  141. data/vendor/plugins/haml/test/haml/templates/list.haml +12 -0
  142. data/vendor/plugins/haml/test/haml/templates/original_engine.haml +17 -0
  143. data/vendor/plugins/haml/test/haml/templates/partialize.haml +1 -0
  144. data/vendor/plugins/haml/test/haml/templates/partials.haml +12 -0
  145. data/vendor/plugins/haml/test/haml/templates/silent_script.haml +40 -0
  146. data/vendor/plugins/haml/test/haml/templates/standard.haml +42 -0
  147. data/vendor/plugins/haml/test/haml/templates/tag_parsing.haml +24 -0
  148. data/vendor/plugins/haml/test/haml/templates/very_basic.haml +4 -0
  149. data/vendor/plugins/haml/test/haml/templates/whitespace_handling.haml +87 -0
  150. data/vendor/plugins/haml/test/haml/test_helper.rb +15 -0
  151. data/vendor/plugins/haml/test/profile.rb +65 -0
  152. data/vendor/plugins/haml/test/sass/engine_test.rb +276 -0
  153. data/vendor/plugins/haml/test/sass/plugin_test.rb +159 -0
  154. data/vendor/plugins/haml/test/sass/results/alt.css +4 -0
  155. data/vendor/plugins/haml/test/sass/results/basic.css +9 -0
  156. data/vendor/plugins/haml/test/sass/results/compact.css +5 -0
  157. data/vendor/plugins/haml/test/sass/results/complex.css +87 -0
  158. data/vendor/plugins/haml/test/sass/results/compressed.css +1 -0
  159. data/vendor/plugins/haml/test/sass/results/constants.css +14 -0
  160. data/vendor/plugins/haml/test/sass/results/expanded.css +19 -0
  161. data/vendor/plugins/haml/test/sass/results/import.css +29 -0
  162. data/vendor/plugins/haml/test/sass/results/mixins.css +95 -0
  163. data/vendor/plugins/haml/test/sass/results/multiline.css +24 -0
  164. data/vendor/plugins/haml/test/sass/results/nested.css +22 -0
  165. data/vendor/plugins/haml/test/sass/results/parent_ref.css +13 -0
  166. data/vendor/plugins/haml/test/sass/results/subdir/nested_subdir/nested_subdir.css +1 -0
  167. data/vendor/plugins/haml/test/sass/results/subdir/subdir.css +1 -0
  168. data/vendor/plugins/haml/test/sass/templates/_partial.sass +2 -0
  169. data/vendor/plugins/haml/test/sass/templates/alt.sass +16 -0
  170. data/vendor/plugins/haml/test/sass/templates/basic.sass +23 -0
  171. data/vendor/plugins/haml/test/sass/templates/bork.sass +2 -0
  172. data/vendor/plugins/haml/test/sass/templates/bork2.sass +2 -0
  173. data/vendor/plugins/haml/test/sass/templates/compact.sass +17 -0
  174. data/vendor/plugins/haml/test/sass/templates/complex.sass +310 -0
  175. data/vendor/plugins/haml/test/sass/templates/compressed.sass +15 -0
  176. data/vendor/plugins/haml/test/sass/templates/constants.sass +97 -0
  177. data/vendor/plugins/haml/test/sass/templates/expanded.sass +17 -0
  178. data/vendor/plugins/haml/test/sass/templates/import.sass +11 -0
  179. data/vendor/plugins/haml/test/sass/templates/importee.sass +14 -0
  180. data/vendor/plugins/haml/test/sass/templates/mixins.sass +76 -0
  181. data/vendor/plugins/haml/test/sass/templates/multiline.sass +20 -0
  182. data/vendor/plugins/haml/test/sass/templates/nested.sass +25 -0
  183. data/vendor/plugins/haml/test/sass/templates/parent_ref.sass +25 -0
  184. data/vendor/plugins/haml/test/sass/templates/subdir/nested_subdir/nested_subdir.sass +3 -0
  185. data/vendor/plugins/haml/test/sass/templates/subdir/subdir.sass +6 -0
  186. metadata +185 -24
  187. data/app/views/admin/extension/index.html.erb +0 -40
  188. data/app/views/admin/layout/edit.html.erb +0 -39
  189. data/app/views/admin/layout/index.html.erb +0 -38
  190. data/app/views/admin/layout/remove.html.erb +0 -17
  191. data/app/views/admin/page/_meta_row.html.erb +0 -4
  192. data/app/views/admin/page/_node.html.erb +0 -28
  193. data/app/views/admin/page/_part.html.erb +0 -13
  194. data/app/views/admin/page/_tag_reference.html.erb +0 -4
  195. data/app/views/admin/page/children.html.erb +0 -4
  196. data/app/views/admin/page/edit.html.erb +0 -140
  197. data/app/views/admin/page/index.html.erb +0 -31
  198. data/app/views/admin/page/remove.html.erb +0 -14
  199. data/app/views/admin/snippet/edit.html.erb +0 -29
  200. data/app/views/admin/snippet/index.html.erb +0 -36
  201. data/app/views/admin/snippet/remove.html.erb +0 -16
  202. data/app/views/admin/user/edit.html.erb +0 -54
  203. data/app/views/admin/user/index.html.erb +0 -43
  204. data/app/views/admin/user/preferences.html.erb +0 -29
  205. data/app/views/admin/user/remove.html.erb +0 -16
  206. data/app/views/admin/welcome/login.html.erb +0 -51
  207. data/app/views/layouts/application.html.erb +0 -83
  208. data/app/views/site/not_found.html.erb +0 -3
@@ -0,0 +1,23 @@
1
+ module Haml
2
+ # An exception raised by Haml code.
3
+ class Error < Exception
4
+ # :stopdoc:
5
+
6
+ # By default, an error is taken to refer to the line of the template
7
+ # that was being processed when the exception was raised.
8
+ # However, if line_offset is non-zero, it's added to that line number
9
+ # to get the line to report for the error.
10
+ attr_reader :line_offset
11
+
12
+ def initialize(message = nil, line_offset = 0)
13
+ super(message)
14
+ @line_offset = line_offset
15
+ end
16
+ # :startdoc:
17
+ end
18
+
19
+ # SyntaxError is the type of exception raised when Haml encounters an
20
+ # ill-formatted document.
21
+ # It's not particularly interesting, except in that it includes Haml::Error.
22
+ class SyntaxError < Haml::Error; end
23
+ end
@@ -0,0 +1,347 @@
1
+ require File.dirname(__FILE__) + '/../haml'
2
+ require 'optparse'
3
+
4
+ module Haml
5
+ # This module contains code for working with the
6
+ # haml, sass, and haml2html executables,
7
+ # such as command-line parsing stuff.
8
+ # It shouldn't need to be invoked by client code.
9
+ module Exec # :nodoc:
10
+ # A class that encapsulates the executable code
11
+ # for all three executables.
12
+ class Generic # :nodoc:
13
+ def initialize(args)
14
+ @args = args
15
+ @options = {}
16
+ end
17
+
18
+ def parse!
19
+ begin
20
+ @opts = OptionParser.new(&method(:set_opts))
21
+ @opts.parse!(@args)
22
+
23
+ process_result
24
+
25
+ @options
26
+ rescue Exception => e
27
+ raise e if e.is_a? SystemExit
28
+
29
+ $stderr.print "#{e.class} on line #{get_line e}: " if @options[:trace]
30
+ $stderr.puts e.message
31
+
32
+ e.backtrace[1..-1].each { |t| $stderr.puts " #{t}" } if @options[:trace]
33
+
34
+ exit 1
35
+ end
36
+ exit 0
37
+ end
38
+
39
+ def to_s
40
+ @opts.to_s
41
+ end
42
+
43
+ protected
44
+
45
+ def get_line(exception)
46
+ # SyntaxErrors have weird line reporting
47
+ # when there's trailing whitespace,
48
+ # which there is for Haml documents.
49
+ return exception.message.scan(/:(\d+)/)[0] if exception.is_a?(::SyntaxError)
50
+ exception.backtrace[0].scan(/:(\d+)/)[0]
51
+ end
52
+
53
+ private
54
+
55
+ def set_opts(opts)
56
+ opts.on('-s', '--stdin', :NONE, 'Read input from standard input instead of an input file') do
57
+ @options[:input] = $stdin
58
+ end
59
+
60
+ opts.on('--trace', :NONE, 'Show a full traceback on error') do
61
+ @options[:trace] = true
62
+ end
63
+
64
+ opts.on_tail("-?", "-h", "--help", "Show this message") do
65
+ puts opts
66
+ exit
67
+ end
68
+
69
+ opts.on_tail("-v", "--version", "Print version") do
70
+ puts("Haml #{::Haml.version[:string]}")
71
+ exit
72
+ end
73
+ end
74
+
75
+ def process_result
76
+ input, output = @options[:input], @options[:output]
77
+ input_file, output_file = if input
78
+ [nil, open_file(ARGV[0], 'w')]
79
+ else
80
+ [open_file(ARGV[0]), open_file(ARGV[1], 'w')]
81
+ end
82
+
83
+ input ||= input_file
84
+ output ||= output_file
85
+ input ||= $stdin
86
+ output ||= $stdout
87
+
88
+ @options[:input], @options[:output] = input, output
89
+ end
90
+
91
+ def open_file(filename, flag = 'r')
92
+ return if filename.nil?
93
+ File.open(filename, flag)
94
+ end
95
+ end
96
+
97
+ # A class encapsulating the executable functionality
98
+ # specific to Haml and Sass.
99
+ class HamlSass < Generic # :nodoc:
100
+ def initialize(args)
101
+ super
102
+ @options[:for_engine] = {}
103
+ end
104
+
105
+ private
106
+
107
+ def set_opts(opts)
108
+ opts.banner = <<END
109
+ Usage: #{@name.downcase} [options] [INPUT] [OUTPUT]
110
+
111
+ Description:
112
+ Uses the #{@name} engine to parse the specified template
113
+ and outputs the result to the specified file.
114
+
115
+ Options:
116
+ END
117
+
118
+ opts.on('--rails RAILS_DIR', "Install Haml and Sass from the Gem to a Rails project") do |dir|
119
+ original_dir = dir
120
+
121
+ dir = File.join(dir, 'vendor', 'plugins')
122
+
123
+ unless File.exists?(dir)
124
+ puts "Directory #{dir} doesn't exist"
125
+ exit
126
+ end
127
+
128
+ dir = File.join(dir, 'haml')
129
+
130
+ if File.exists?(dir)
131
+ puts "Directory #{dir} already exists."
132
+ exit
133
+ end
134
+
135
+ begin
136
+ Dir.mkdir(dir)
137
+ rescue SystemCallError
138
+ puts "Cannot create #{dir}"
139
+ exit
140
+ end
141
+
142
+ File.open(File.join(dir, 'init.rb'), 'w') do |file|
143
+ file.puts "require 'rubygems'"
144
+ file << File.read(File.dirname(__FILE__) + "/../../init.rb")
145
+ end
146
+
147
+ puts "Haml plugin added to #{original_dir}"
148
+ exit
149
+ end
150
+
151
+ opts.on('-c', '--check', "Just check syntax, don't evaluate.") do
152
+ require 'stringio'
153
+ @options[:check_syntax] = true
154
+ @options[:output] = StringIO.new
155
+ end
156
+
157
+ super
158
+ end
159
+
160
+ def process_result
161
+ super
162
+ require File.dirname(__FILE__) + "/../#{@name.downcase}"
163
+ end
164
+ end
165
+
166
+ # A class encapsulating executable functionality
167
+ # specific to Sass.
168
+ class Sass < HamlSass # :nodoc:
169
+ def initialize(args)
170
+ super
171
+ @name = "Sass"
172
+ end
173
+
174
+ def set_opts(opts)
175
+ super
176
+
177
+ opts.on('-t', '--style NAME',
178
+ 'Output style. Can be nested (default), compact, compressed, or expanded.') do |name|
179
+ @options[:for_engine][:style] = name.to_sym
180
+ end
181
+ end
182
+
183
+ def process_result
184
+ super
185
+ input = @options[:input]
186
+ output = @options[:output]
187
+
188
+ template = input.read()
189
+ input.close() if input.is_a? File
190
+
191
+ begin
192
+ # We don't need to do any special handling of @options[:check_syntax] here,
193
+ # because the Sass syntax checking happens alongside evaluation
194
+ # and evaluation doesn't actually evaluate any code anyway.
195
+ result = ::Sass::Engine.new(template, @options[:for_engine]).render
196
+ rescue ::Sass::SyntaxError => e
197
+ raise e if @options[:trace]
198
+ raise "Syntax error on line #{get_line e}: #{e.message}"
199
+ end
200
+
201
+ output.write(result)
202
+ output.close() if output.is_a? File
203
+ end
204
+ end
205
+
206
+ # A class encapsulating executable functionality
207
+ # specific to Haml.
208
+ class Haml < HamlSass # :nodoc:
209
+ def initialize(args)
210
+ super
211
+ @name = "Haml"
212
+ end
213
+
214
+ def set_opts(opts)
215
+ super
216
+
217
+ opts.on('-t', '--style NAME',
218
+ 'Output style. Can be indented (default) or ugly.') do |name|
219
+ @options[:for_engine][:ugly] = true if name.to_sym == :ugly
220
+ end
221
+
222
+ opts.on('-f', '--format NAME',
223
+ 'Output format. Can be xhtml (default), html4, or html5.') do |name|
224
+ @options[:for_engine][:format] = name.to_sym
225
+ end
226
+
227
+ opts.on('-e', '--escape-html',
228
+ 'Escape HTML characters (like ampersands and angle brackets) by default.') do
229
+ @options[:for_engine][:escape_html] = true
230
+ end
231
+ end
232
+
233
+ def process_result
234
+ super
235
+ input = @options[:input]
236
+ output = @options[:output]
237
+
238
+ template = input.read()
239
+ input.close() if input.is_a? File
240
+
241
+ begin
242
+ engine = ::Haml::Engine.new(template, @options[:for_engine])
243
+ if @options[:check_syntax]
244
+ puts "Syntax OK"
245
+ return
246
+ end
247
+ result = engine.to_html
248
+ rescue Exception => e
249
+ raise e if @options[:trace]
250
+
251
+ case e
252
+ when ::Haml::SyntaxError; raise "Syntax error on line #{get_line e}: #{e.message}"
253
+ when ::Haml::Error; raise "Haml error on line #{get_line e}: #{e.message}"
254
+ else raise "Exception on line #{get_line e}: #{e.message}\n Use --trace for backtrace."
255
+ end
256
+ end
257
+
258
+ output.write(result)
259
+ output.close() if output.is_a? File
260
+ end
261
+ end
262
+
263
+ # A class encapsulating executable functionality
264
+ # specific to the html2haml executable.
265
+ class HTML2Haml < Generic # :nodoc:
266
+ def initialize(args)
267
+ super
268
+
269
+ @module_opts = {}
270
+
271
+ begin
272
+ require 'haml/html'
273
+ rescue LoadError => err
274
+ dep = err.message.scan(/^no such file to load -- (.*)/)[0]
275
+ puts "Required dependency #{dep} not found!"
276
+ exit 1
277
+ end
278
+ end
279
+
280
+ def set_opts(opts)
281
+ opts.banner = <<END
282
+ Usage: html2haml [options] [INPUT] [OUTPUT]
283
+
284
+ Description: Transforms an HTML file into corresponding Haml code.
285
+
286
+ Options:
287
+ END
288
+
289
+ opts.on('-r', '--rhtml', 'Parse RHTML tags.') do
290
+ @module_opts[:rhtml] = true
291
+ end
292
+
293
+ opts.on('-x', '--xhtml', 'Parse the input using the more strict XHTML parser.') do
294
+ @module_opts[:xhtml] = true
295
+ end
296
+
297
+ super
298
+ end
299
+
300
+ def process_result
301
+ super
302
+
303
+ input = @options[:input]
304
+ output = @options[:output]
305
+
306
+ output.write(::Haml::HTML.new(input, @module_opts).render)
307
+ end
308
+ end
309
+
310
+ # A class encapsulating executable functionality
311
+ # specific to the css2sass executable.
312
+ class CSS2Sass < Generic # :nodoc:
313
+ def initialize(args)
314
+ super
315
+
316
+ @module_opts = {}
317
+
318
+ require 'sass/css'
319
+ end
320
+
321
+ def set_opts(opts)
322
+ opts.banner = <<END
323
+ Usage: css2sass [options] [INPUT] [OUTPUT]
324
+
325
+ Description: Transforms a CSS file into corresponding Sass code.
326
+
327
+ Options:
328
+ END
329
+
330
+ opts.on('-a', '--alternate', 'Output using alternative Sass syntax (margin: 1px)') do
331
+ @module_opts[:alternate] = true
332
+ end
333
+
334
+ super
335
+ end
336
+
337
+ def process_result
338
+ super
339
+
340
+ input = @options[:input]
341
+ output = @options[:output]
342
+
343
+ output.write(::Sass::CSS.new(input, @module_opts).render)
344
+ end
345
+ end
346
+ end
347
+ end
@@ -0,0 +1,249 @@
1
+ # This file contains redefinitions of and wrappers around various text
2
+ # filters so they can be used as Haml filters.
3
+
4
+ module Haml
5
+ # The module containing the default filters,
6
+ # as well as the base module,
7
+ # Haml::Filters::Base.
8
+ module Filters
9
+ # The base module for Haml filters.
10
+ # User-defined filters should be modules including this module.
11
+ #
12
+ # A user-defined filter should override either Base#render or Base #compile.
13
+ # Base#render is the most common.
14
+ # It takes a string, the filter source,
15
+ # and returns another string,
16
+ # the result of the filter.
17
+ # For example:
18
+ #
19
+ # module Haml::Filters::Sass
20
+ # include Haml::Filters::Base
21
+ #
22
+ # def render(text)
23
+ # ::Sass::Engine.new(text).render
24
+ # end
25
+ # end
26
+ #
27
+ # For details on overriding #compile, see its documentation.
28
+ #
29
+ module Base
30
+ def self.included(base) # :nodoc:
31
+ base.extend(base)
32
+ end
33
+
34
+ # Takes a string, the source text that should be passed to the filter,
35
+ # and returns the string resulting from running the filter on <tt>text</tt>.
36
+ #
37
+ # This should be overridden in most individual filter modules
38
+ # to render text with the given filter.
39
+ # If compile is overridden, however, render doesn't need to be.
40
+ def render(text)
41
+ raise Error.new("#{self.inspect}#render not defined!")
42
+ end
43
+
44
+ def internal_compile(*args) # :nodoc:
45
+ resolve_lazy_requires
46
+ compile(*args)
47
+ end
48
+
49
+ # compile should be overridden when a filter needs to have access
50
+ # to the Haml evaluation context.
51
+ # Rather than applying a filter to a string at compile-time,
52
+ # compile uses the Haml::Precompiler instance to compile the string to Ruby code
53
+ # that will be executed in the context of the active Haml template.
54
+ #
55
+ # Warning: the Haml::Precompiler interface is neither well-documented
56
+ # nor guaranteed to be stable.
57
+ # If you want to make use of it,
58
+ # you'll probably need to look at the source code
59
+ # and should test your filter when upgrading to new Haml versions.
60
+ def compile(precompiler, text)
61
+ resolve_lazy_requires
62
+ filter = self
63
+ precompiler.instance_eval do
64
+ if contains_interpolation?(text)
65
+ return if options[:suppress_eval]
66
+
67
+ push_script("#{filter.inspect}.render(#{unescape_interpolation(text)})", false)
68
+ return
69
+ end
70
+
71
+ rendered = filter.render(text)
72
+
73
+ if !options[:ugly]
74
+ push_text(rendered.rstrip.gsub("\n", "\n#{' ' * @output_tabs}"))
75
+ else
76
+ push_text(rendered.rstrip)
77
+ end
78
+ end
79
+ end
80
+
81
+ # This becomes a class method of modules that include Base.
82
+ # It allows the module to specify one or more Ruby files
83
+ # that Haml should try to require when compiling the filter.
84
+ #
85
+ # The first file specified is tried first,
86
+ # then the second, etc.
87
+ # If none are found, the compilation throws an exception.
88
+ #
89
+ # For example:
90
+ #
91
+ # module Haml::Filters::Markdown
92
+ # lazy_require 'bluecloth', 'redcloth'
93
+ #
94
+ # ...
95
+ # end
96
+ #
97
+ def lazy_require(*reqs)
98
+ @lazy_requires = reqs
99
+ end
100
+
101
+ private
102
+
103
+ def resolve_lazy_requires
104
+ return unless @lazy_requires
105
+
106
+ @lazy_requires[0...-1].each do |req|
107
+ begin
108
+ @required = req
109
+ require @required
110
+ return
111
+ rescue LoadError; end # RCov doesn't see this, but it is run
112
+ end
113
+
114
+ begin
115
+ @required = @lazy_requires[-1]
116
+ require @required
117
+ rescue LoadError => e
118
+ classname = self.class.to_s.gsub(/\w+::/, '')
119
+
120
+ if @lazy_requires.size == 1
121
+ raise Error.new("Can't run #{classname} filter; required file '#{@lazy_requires.first}' not found")
122
+ else
123
+ raise Error.new("Can't run #{classname} filter; required #{@lazy_requires.map { |r| "'#{r}'" }.join(' or ')}, but none were found")
124
+ end
125
+ end
126
+ end
127
+ end
128
+ end
129
+ end
130
+
131
+ # :stopdoc:
132
+
133
+ begin
134
+ require 'rubygems'
135
+ rescue LoadError; end
136
+
137
+ module Haml
138
+ module Filters
139
+ module Plain
140
+ include Base
141
+
142
+ def render(text); text; end
143
+ end
144
+
145
+ module Javascript
146
+ include Base
147
+
148
+ def render(text)
149
+ <<END
150
+ <script type='text/javascript'>
151
+ //<![CDATA[
152
+ #{text.rstrip.gsub("\n", "\n ")}
153
+ //]]>
154
+ </script>
155
+ END
156
+ end
157
+ end
158
+
159
+ module Ruby
160
+ include Base
161
+ lazy_require 'stringio'
162
+
163
+ def compile(precompiler, text)
164
+ precompiler.instance_eval do
165
+ push_silent <<-END.gsub("\n", ';')
166
+ _haml_old_stdout = $stdout
167
+ $stdout = StringIO.new(_hamlout.buffer, 'a')
168
+ #{text}
169
+ _haml_old_stdout, $stdout = $stdout, _haml_old_stdout
170
+ _haml_old_stdout.close
171
+ END
172
+ end
173
+ end
174
+ end
175
+
176
+ module Preserve
177
+ include Base
178
+
179
+ def compile(precompiler, text)
180
+ text = Haml::Helpers.preserve(text) + "\n"
181
+
182
+ precompiler.instance_eval do
183
+ if contains_interpolation?(text)
184
+ return if options[:suppress_eval]
185
+
186
+ push_silent("_hamlout.buffer << #{unescape_interpolation(text)};")
187
+ return
188
+ end
189
+
190
+ concat_merged_text(text)
191
+ end
192
+ end
193
+ end
194
+
195
+ module Sass
196
+ include Base
197
+ lazy_require 'sass/engine'
198
+
199
+ def render(text)
200
+ ::Sass::Engine.new(text).render
201
+ end
202
+ end
203
+
204
+ module ERB
205
+ include Base
206
+ lazy_require 'erb'
207
+
208
+ def compile(precompiler, text)
209
+ src = ::ERB.new(text).src.sub(/^_erbout = '';/, "").gsub("\n", ';')
210
+ precompiler.send(:push_silent, src)
211
+ end
212
+ end
213
+
214
+ module RedCloth
215
+ include Base
216
+ lazy_require 'redcloth'
217
+
218
+ def render(text)
219
+ ::RedCloth.new(text).to_html
220
+ end
221
+ end
222
+
223
+ # Uses RedCloth to provide only Textile (not Markdown) parsing
224
+ module Textile
225
+ include Base
226
+ lazy_require 'redcloth'
227
+
228
+ def render(text)
229
+ ::RedCloth.new(text).to_html(:textile)
230
+ end
231
+ end
232
+
233
+ # Uses BlueCloth or RedCloth to provide only Markdown (not Textile) parsing
234
+ module Markdown
235
+ include Base
236
+ lazy_require 'bluecloth', 'redcloth'
237
+
238
+ def render(text)
239
+ if @required == 'bluecloth'
240
+ ::BlueCloth.new(text).to_html
241
+ else
242
+ ::RedCloth.new(text).to_html(:markdown)
243
+ end
244
+ end
245
+ end
246
+ end
247
+ end
248
+
249
+ # :startdoc: