mack-haml 0.8.1 → 0.8.2

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 (43) hide show
  1. data/lib/gems.rb +13 -0
  2. data/lib/gems/haml-2.0.4/VERSION +1 -0
  3. data/lib/gems/haml-2.0.4/bin/css2sass +7 -0
  4. data/lib/gems/haml-2.0.4/bin/haml +9 -0
  5. data/lib/gems/haml-2.0.4/bin/html2haml +7 -0
  6. data/lib/gems/haml-2.0.4/bin/sass +8 -0
  7. data/lib/gems/haml-2.0.4/lib/haml.rb +1040 -0
  8. data/lib/gems/haml-2.0.4/lib/haml/buffer.rb +239 -0
  9. data/lib/gems/haml-2.0.4/lib/haml/engine.rb +265 -0
  10. data/lib/gems/haml-2.0.4/lib/haml/error.rb +22 -0
  11. data/lib/gems/haml-2.0.4/lib/haml/exec.rb +364 -0
  12. data/lib/gems/haml-2.0.4/lib/haml/filters.rb +275 -0
  13. data/lib/gems/haml-2.0.4/lib/haml/helpers.rb +453 -0
  14. data/lib/gems/haml-2.0.4/lib/haml/helpers/action_view_extensions.rb +45 -0
  15. data/lib/gems/haml-2.0.4/lib/haml/helpers/action_view_mods.rb +179 -0
  16. data/lib/gems/haml-2.0.4/lib/haml/html.rb +227 -0
  17. data/lib/gems/haml-2.0.4/lib/haml/precompiler.rb +805 -0
  18. data/lib/gems/haml-2.0.4/lib/haml/template.rb +51 -0
  19. data/lib/gems/haml-2.0.4/lib/haml/template/patch.rb +58 -0
  20. data/lib/gems/haml-2.0.4/lib/haml/template/plugin.rb +72 -0
  21. data/lib/gems/haml-2.0.4/lib/sass.rb +863 -0
  22. data/lib/gems/haml-2.0.4/lib/sass/constant.rb +214 -0
  23. data/lib/gems/haml-2.0.4/lib/sass/constant/color.rb +101 -0
  24. data/lib/gems/haml-2.0.4/lib/sass/constant/literal.rb +54 -0
  25. data/lib/gems/haml-2.0.4/lib/sass/constant/nil.rb +9 -0
  26. data/lib/gems/haml-2.0.4/lib/sass/constant/number.rb +87 -0
  27. data/lib/gems/haml-2.0.4/lib/sass/constant/operation.rb +30 -0
  28. data/lib/gems/haml-2.0.4/lib/sass/constant/string.rb +22 -0
  29. data/lib/gems/haml-2.0.4/lib/sass/css.rb +394 -0
  30. data/lib/gems/haml-2.0.4/lib/sass/engine.rb +466 -0
  31. data/lib/gems/haml-2.0.4/lib/sass/error.rb +35 -0
  32. data/lib/gems/haml-2.0.4/lib/sass/plugin.rb +169 -0
  33. data/lib/gems/haml-2.0.4/lib/sass/plugin/merb.rb +56 -0
  34. data/lib/gems/haml-2.0.4/lib/sass/plugin/rails.rb +24 -0
  35. data/lib/gems/haml-2.0.4/lib/sass/tree/attr_node.rb +53 -0
  36. data/lib/gems/haml-2.0.4/lib/sass/tree/comment_node.rb +20 -0
  37. data/lib/gems/haml-2.0.4/lib/sass/tree/directive_node.rb +46 -0
  38. data/lib/gems/haml-2.0.4/lib/sass/tree/node.rb +42 -0
  39. data/lib/gems/haml-2.0.4/lib/sass/tree/rule_node.rb +89 -0
  40. data/lib/gems/haml-2.0.4/lib/sass/tree/value_node.rb +16 -0
  41. data/lib/gems/haml-2.0.4/rails/init.rb +1 -0
  42. data/lib/mack-haml.rb +1 -0
  43. metadata +65 -16
@@ -0,0 +1,45 @@
1
+ require 'haml/helpers/action_view_mods'
2
+
3
+ if defined?(ActionView)
4
+ module Haml
5
+ module Helpers
6
+ # This module contains various useful helper methods
7
+ # that either tie into ActionView or the rest of the ActionPack stack,
8
+ # or are only useful in that context.
9
+ # Thus, the methods defined here are only available
10
+ # if ActionView is installed.
11
+ module ActionViewExtensions
12
+ # Returns a value for the "class" attribute
13
+ # unique to this controller/action pair.
14
+ # This can be used to target styles specifically at this action or controller.
15
+ # For example, if the current action were EntryController#show,
16
+ #
17
+ # %div{:class => page_class} My Div
18
+ #
19
+ # would become
20
+ #
21
+ # <div class="entry show">My Div</div>
22
+ #
23
+ # Then, in a stylesheet
24
+ # (shown here as Sass),
25
+ # you could refer to this specific action:
26
+ #
27
+ # .entry.show
28
+ # :font-weight bold
29
+ #
30
+ # or to all actions in the entry controller:
31
+ #
32
+ # .entry
33
+ # :color #00f
34
+ #
35
+ def page_class
36
+ controller.controller_name + " " + controller.action_name
37
+ end
38
+
39
+ # :stopdoc:
40
+ alias_method :generate_content_class_names, :page_class
41
+ # :startdoc:
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,179 @@
1
+ if defined?(ActionView) and not defined?(Merb::Plugins)
2
+ module ActionView
3
+ class Base # :nodoc:
4
+ def render_with_haml(*args, &block)
5
+ options = args.first
6
+
7
+ # If render :layout is used with a block,
8
+ # it concats rather than returning a string
9
+ # so we need it to keep thinking it's Haml
10
+ # until it hits the sub-render
11
+ if is_haml? && !(options.is_a?(Hash) && options[:layout] && block_given?)
12
+ return non_haml { render_without_haml(*args, &block) }
13
+ end
14
+ render_without_haml(*args, &block)
15
+ end
16
+ alias_method :render_without_haml, :render
17
+ alias_method :render, :render_with_haml
18
+
19
+ # Rails >2.1
20
+ if instance_methods.include?('output_buffer')
21
+ def output_buffer_with_haml
22
+ return haml_buffer.buffer if is_haml?
23
+ output_buffer_without_haml
24
+ end
25
+ alias_method :output_buffer_without_haml, :output_buffer
26
+ alias_method :output_buffer, :output_buffer_with_haml
27
+
28
+ def set_output_buffer_with_haml(new)
29
+ if is_haml?
30
+ haml_buffer.buffer = new
31
+ else
32
+ set_output_buffer_without_haml new
33
+ end
34
+ end
35
+ alias_method :set_output_buffer_without_haml, :output_buffer=
36
+ alias_method :output_buffer=, :set_output_buffer_with_haml
37
+ end
38
+ end
39
+
40
+ # This overrides various helpers in ActionView
41
+ # to make them work more effectively with Haml.
42
+ module Helpers
43
+ # :stopdoc:
44
+ # In Rails <=2.1, we've got to override considerable capturing infrastructure.
45
+ # In Rails >2.1, we can make do with only overriding #capture
46
+ # (which no longer behaves differently in helper contexts).
47
+ unless ActionView::Base.instance_methods.include?('output_buffer')
48
+ module CaptureHelper
49
+ def capture_with_haml(*args, &block)
50
+ # Rails' #capture helper will just return the value of the block
51
+ # if it's not actually in the template context,
52
+ # as detected by the existance of an _erbout variable.
53
+ # We've got to do the same thing for compatibility.
54
+ block_is_haml =
55
+ begin
56
+ eval('_hamlout', block)
57
+ true
58
+ rescue
59
+ false
60
+ end
61
+
62
+ if block_is_haml && is_haml?
63
+ capture_haml(*args, &block)
64
+ else
65
+ capture_without_haml(*args, &block)
66
+ end
67
+ end
68
+ alias_method :capture_without_haml, :capture
69
+ alias_method :capture, :capture_with_haml
70
+
71
+ def capture_erb_with_buffer_with_haml(buffer, *args, &block)
72
+ if is_haml?
73
+ capture_haml(*args, &block)
74
+ else
75
+ capture_erb_with_buffer_without_haml(buffer, *args, &block)
76
+ end
77
+ end
78
+ alias_method :capture_erb_with_buffer_without_haml, :capture_erb_with_buffer
79
+ alias_method :capture_erb_with_buffer, :capture_erb_with_buffer_with_haml
80
+ end
81
+
82
+ module TextHelper
83
+ def concat_with_haml(string, binding = nil)
84
+ if is_haml?
85
+ haml_buffer.buffer.concat(string)
86
+ else
87
+ concat_without_haml(string, binding)
88
+ end
89
+ end
90
+ alias_method :concat_without_haml, :concat
91
+ alias_method :concat, :concat_with_haml
92
+ end
93
+ else
94
+ module CaptureHelper
95
+ def capture_with_haml(*args, &block)
96
+ if is_haml?
97
+ capture_haml(*args, &block)
98
+ else
99
+ capture_without_haml(*args, &block)
100
+ end
101
+ end
102
+ alias_method :capture_without_haml, :capture
103
+ alias_method :capture, :capture_with_haml
104
+ end
105
+ end
106
+
107
+ module TagHelper
108
+ def content_tag_with_haml(name, *args, &block)
109
+ content = content_tag_without_haml(name, *args, &block)
110
+
111
+ if is_haml? && haml_buffer.options[:preserve].include?(name.to_s)
112
+ content = Haml::Helpers.preserve content
113
+ end
114
+
115
+ content
116
+ end
117
+ alias_method :content_tag_without_haml, :content_tag
118
+ alias_method :content_tag, :content_tag_with_haml
119
+ end
120
+
121
+ class InstanceTag
122
+ # Includes TagHelper
123
+
124
+ def haml_buffer
125
+ @template_object.send :haml_buffer
126
+ end
127
+
128
+ def is_haml?
129
+ @template_object.send :is_haml?
130
+ end
131
+
132
+ alias_method :content_tag_without_haml, :content_tag
133
+ alias_method :content_tag, :content_tag_with_haml
134
+ end
135
+
136
+ module FormTagHelper
137
+ def form_tag_with_haml(url_for_options = {}, options = {}, *parameters_for_url, &proc)
138
+ if is_haml?
139
+ if block_given?
140
+ oldproc = proc
141
+ proc = haml_bind_proc do |*args|
142
+ concat "\n"
143
+ tab_up
144
+ oldproc.call(*args)
145
+ tab_down
146
+ end
147
+ end
148
+ res = form_tag_without_haml(url_for_options, options, *parameters_for_url, &proc) + "\n"
149
+ concat "\n" if block_given? && is_haml?
150
+ res
151
+ else
152
+ form_tag_without_haml(url_for_options, options, *parameters_for_url, &proc)
153
+ end
154
+ end
155
+ alias_method :form_tag_without_haml, :form_tag
156
+ alias_method :form_tag, :form_tag_with_haml
157
+ end
158
+
159
+ module FormHelper
160
+ def form_for_with_haml(object_name, *args, &proc)
161
+ if block_given? && is_haml?
162
+ oldproc = proc
163
+ proc = haml_bind_proc do |*args|
164
+ tab_up
165
+ oldproc.call(*args)
166
+ tab_down
167
+ end
168
+ end
169
+ form_for_without_haml(object_name, *args, &proc)
170
+ concat "\n" if block_given? && is_haml?
171
+ end
172
+ alias_method :form_for_without_haml, :form_for
173
+ alias_method :form_for, :form_for_with_haml
174
+ end
175
+ # :startdoc:
176
+ end
177
+ end
178
+ end
179
+
@@ -0,0 +1,227 @@
1
+ require File.dirname(__FILE__) + '/../haml'
2
+
3
+ require 'haml/engine'
4
+ require 'rubygems'
5
+ require 'hpricot'
6
+ require 'cgi'
7
+
8
+ module Haml
9
+ # This class contains the functionality used in the +html2haml+ utility,
10
+ # namely converting HTML documents to Haml templates.
11
+ # It depends on Hpricot for HTML parsing (http://code.whytheluckystiff.net/hpricot/).
12
+ class HTML
13
+ # Creates a new instance of Haml::HTML that will compile the given template,
14
+ # which can either be a string containing HTML or an Hpricot node,
15
+ # to a Haml string when +render+ is called.
16
+ def initialize(template, options = {})
17
+ @@options = options
18
+
19
+ if template.is_a? Hpricot::Node
20
+ @template = template
21
+ else
22
+ if template.is_a? IO
23
+ template = template.read
24
+ end
25
+
26
+ if @@options[:rhtml]
27
+ match_to_html(template, /<%=(.*?)-?%>/m, 'loud')
28
+ match_to_html(template, /<%-?(.*?)-?%>/m, 'silent')
29
+ end
30
+
31
+ method = @@options[:xhtml] ? Hpricot.method(:XML) : method(:Hpricot)
32
+ @template = method.call(template.gsub('&', '&amp;'))
33
+ end
34
+ end
35
+
36
+ # Processes the document and returns the result as a string
37
+ # containing the Haml template.
38
+ def render
39
+ @template.to_haml(0)
40
+ end
41
+ alias_method :to_haml, :render
42
+
43
+ module ::Hpricot::Node
44
+ # Returns the Haml representation of the given node,
45
+ # at the given tabulation.
46
+ def to_haml(tabs = 0)
47
+ parse_text(self.to_s, tabs)
48
+ end
49
+
50
+ private
51
+
52
+ def tabulate(tabs)
53
+ ' ' * tabs
54
+ end
55
+
56
+ def parse_text(text, tabs)
57
+ text.strip!
58
+ if text.empty?
59
+ String.new
60
+ else
61
+ lines = text.split("\n")
62
+
63
+ lines.map do |line|
64
+ line.strip!
65
+ "#{tabulate(tabs)}#{'\\' if Haml::Engine::SPECIAL_CHARACTERS.include?(line[0])}#{line}\n"
66
+ end.join
67
+ end
68
+ end
69
+ end
70
+
71
+ # :stopdoc:
72
+
73
+ def self.options
74
+ @@options
75
+ end
76
+
77
+ TEXT_REGEXP = /^(\s*).*$/
78
+
79
+ class ::Hpricot::Doc
80
+ def to_haml(tabs = 0)
81
+ output = ''
82
+ children.each { |child| output += child.to_haml(0) }
83
+ output
84
+ end
85
+ end
86
+
87
+ class ::Hpricot::XMLDecl
88
+ def to_haml(tabs = 0)
89
+ "#{tabulate(tabs)}!!! XML\n"
90
+ end
91
+ end
92
+
93
+ class ::Hpricot::DocType
94
+ def to_haml(tabs = 0)
95
+ attrs = public_id.scan(/DTD\s+([^\s]+)\s*([^\s]*)\s*([^\s]*)\s*\/\//)[0]
96
+ if attrs == nil
97
+ raise Exception.new("Invalid doctype")
98
+ end
99
+
100
+ type, version, strictness = attrs.map { |a| a.downcase }
101
+ if type == "html"
102
+ version = "1.0"
103
+ strictness = "transitional"
104
+ end
105
+
106
+ if version == "1.0" || version.empty?
107
+ version = nil
108
+ end
109
+
110
+ if strictness == 'transitional' || strictness.empty?
111
+ strictness = nil
112
+ end
113
+
114
+ version = " #{version}" if version
115
+ if strictness
116
+ strictness[0] = strictness[0] - 32
117
+ strictness = " #{strictness}"
118
+ end
119
+
120
+ "#{tabulate(tabs)}!!!#{version}#{strictness}\n"
121
+ end
122
+ end
123
+
124
+ class ::Hpricot::Comment
125
+ def to_haml(tabs = 0)
126
+ "#{tabulate(tabs)}/\n#{parse_text(self.content, tabs + 1)}"
127
+ end
128
+ end
129
+
130
+ class ::Hpricot::Elem
131
+ def to_haml(tabs = 0)
132
+ output = "#{tabulate(tabs)}"
133
+ if HTML.options[:rhtml] && name[0...5] == 'haml:'
134
+ return output + HTML.send("haml_tag_#{name[5..-1]}", CGI.unescapeHTML(self.inner_text))
135
+ end
136
+
137
+ output += "%#{name}" unless name == 'div' && (static_id? || static_classname?)
138
+
139
+ if attributes
140
+ if static_id?
141
+ output += "##{attributes['id']}"
142
+ remove_attribute('id')
143
+ end
144
+ if static_classname?
145
+ attributes['class'].split(' ').each { |c| output += ".#{c}" }
146
+ remove_attribute('class')
147
+ end
148
+ output += haml_attributes if attributes.length > 0
149
+ end
150
+
151
+ output += "/" if children.length == 0
152
+ output += "\n"
153
+
154
+ self.children.each do |child|
155
+ output += child.to_haml(tabs + 1)
156
+ end
157
+
158
+ output
159
+ end
160
+
161
+ private
162
+
163
+ def dynamic_attributes
164
+ @dynamic_attributes ||= begin
165
+ attributes.inject({}) do |dynamic, pair|
166
+ name, value = pair
167
+ unless value.empty?
168
+ full_match = nil
169
+ ruby_value = value.gsub(%r{<haml:loud>\s*(.+?)\s*</haml:loud>}) do
170
+ full_match = $`.empty? && $'.empty?
171
+ full_match ? $1: "\#{#{$1}}"
172
+ end
173
+ unless ruby_value == value
174
+ dynamic[name] = full_match ? ruby_value : %("#{ruby_value}")
175
+ end
176
+ end
177
+ dynamic
178
+ end
179
+ end
180
+ end
181
+
182
+ def static_attribute?(name)
183
+ attributes[name] and !dynamic_attribute?(name)
184
+ end
185
+
186
+ def dynamic_attribute?(name)
187
+ HTML.options[:rhtml] and dynamic_attributes.key?(name)
188
+ end
189
+
190
+ def static_id?
191
+ static_attribute? 'id'
192
+ end
193
+
194
+ def static_classname?
195
+ static_attribute? 'class'
196
+ end
197
+
198
+ # Returns a string representation of an attributes hash
199
+ # that's prettier than that produced by Hash#inspect
200
+ def haml_attributes
201
+ attrs = attributes.map do |name, value|
202
+ value = dynamic_attribute?(name) ? dynamic_attributes[name] : value.inspect
203
+ name = name.index(/\W/) ? name.inspect : ":#{name}"
204
+ "#{name} => #{value}"
205
+ end
206
+ "{ #{attrs.join(', ')} }"
207
+ end
208
+ end
209
+
210
+ def self.haml_tag_loud(text)
211
+ "= #{text.gsub(/\n\s*/, ' ').strip}\n"
212
+ end
213
+
214
+ def self.haml_tag_silent(text)
215
+ text.split("\n").map { |line| "- #{line.strip}\n" }.join
216
+ end
217
+
218
+ private
219
+
220
+ def match_to_html(string, regex, tag)
221
+ string.gsub!(regex) do
222
+ "<haml:#{tag}>#{CGI.escapeHTML($1)}</haml:#{tag}>"
223
+ end
224
+ end
225
+ # :startdoc:
226
+ end
227
+ end