wireframe-haml 2.1.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.
- data/README.rdoc +332 -0
- data/VERSION.yml +4 -0
- data/bin/css2sass +7 -0
- data/bin/haml +9 -0
- data/bin/html2haml +7 -0
- data/bin/sass +8 -0
- data/lib/haml/buffer.rb +255 -0
- data/lib/haml/engine.rb +268 -0
- data/lib/haml/error.rb +22 -0
- data/lib/haml/exec.rb +395 -0
- data/lib/haml/filters.rb +276 -0
- data/lib/haml/helpers/action_view_extensions.rb +45 -0
- data/lib/haml/helpers/action_view_mods.rb +181 -0
- data/lib/haml/helpers.rb +468 -0
- data/lib/haml/html.rb +218 -0
- data/lib/haml/precompiler.rb +889 -0
- data/lib/haml/shared.rb +45 -0
- data/lib/haml/template/patch.rb +58 -0
- data/lib/haml/template/plugin.rb +72 -0
- data/lib/haml/template.rb +51 -0
- data/lib/haml/util.rb +77 -0
- data/lib/haml/version.rb +47 -0
- data/lib/haml.rb +1042 -0
- data/lib/sass/css.rb +388 -0
- data/lib/sass/engine.rb +499 -0
- data/lib/sass/environment.rb +33 -0
- data/lib/sass/error.rb +35 -0
- data/lib/sass/plugin/merb.rb +56 -0
- data/lib/sass/plugin/rails.rb +24 -0
- data/lib/sass/plugin.rb +203 -0
- data/lib/sass/repl.rb +51 -0
- data/lib/sass/script/bool.rb +13 -0
- data/lib/sass/script/color.rb +97 -0
- data/lib/sass/script/funcall.rb +28 -0
- data/lib/sass/script/functions.rb +122 -0
- data/lib/sass/script/lexer.rb +152 -0
- data/lib/sass/script/literal.rb +60 -0
- data/lib/sass/script/number.rb +231 -0
- data/lib/sass/script/operation.rb +30 -0
- data/lib/sass/script/parser.rb +142 -0
- data/lib/sass/script/string.rb +42 -0
- data/lib/sass/script/unary_operation.rb +21 -0
- data/lib/sass/script/variable.rb +20 -0
- data/lib/sass/script.rb +38 -0
- data/lib/sass/tree/attr_node.rb +64 -0
- data/lib/sass/tree/comment_node.rb +34 -0
- data/lib/sass/tree/debug_node.rb +22 -0
- data/lib/sass/tree/directive_node.rb +50 -0
- data/lib/sass/tree/file_node.rb +27 -0
- data/lib/sass/tree/for_node.rb +29 -0
- data/lib/sass/tree/if_node.rb +27 -0
- data/lib/sass/tree/mixin_def_node.rb +18 -0
- data/lib/sass/tree/mixin_node.rb +34 -0
- data/lib/sass/tree/node.rb +99 -0
- data/lib/sass/tree/rule_node.rb +120 -0
- data/lib/sass/tree/variable_node.rb +24 -0
- data/lib/sass/tree/while_node.rb +20 -0
- data/lib/sass.rb +1062 -0
- data/test/benchmark.rb +99 -0
- data/test/haml/engine_test.rb +734 -0
- data/test/haml/helper_test.rb +224 -0
- data/test/haml/html2haml_test.rb +92 -0
- data/test/haml/markaby/standard.mab +52 -0
- data/test/haml/mocks/article.rb +6 -0
- data/test/haml/results/content_for_layout.xhtml +15 -0
- data/test/haml/results/eval_suppressed.xhtml +9 -0
- data/test/haml/results/filters.xhtml +62 -0
- data/test/haml/results/helpers.xhtml +93 -0
- data/test/haml/results/helpful.xhtml +10 -0
- data/test/haml/results/just_stuff.xhtml +68 -0
- data/test/haml/results/list.xhtml +12 -0
- data/test/haml/results/nuke_inner_whitespace.xhtml +40 -0
- data/test/haml/results/nuke_outer_whitespace.xhtml +148 -0
- data/test/haml/results/original_engine.xhtml +20 -0
- data/test/haml/results/partial_layout.xhtml +5 -0
- data/test/haml/results/partials.xhtml +21 -0
- data/test/haml/results/render_layout.xhtml +3 -0
- data/test/haml/results/silent_script.xhtml +74 -0
- data/test/haml/results/standard.xhtml +42 -0
- data/test/haml/results/tag_parsing.xhtml +23 -0
- data/test/haml/results/very_basic.xhtml +5 -0
- data/test/haml/results/whitespace_handling.xhtml +89 -0
- data/test/haml/rhtml/_av_partial_1.rhtml +12 -0
- data/test/haml/rhtml/_av_partial_2.rhtml +8 -0
- data/test/haml/rhtml/action_view.rhtml +62 -0
- data/test/haml/rhtml/standard.rhtml +54 -0
- data/test/haml/template_test.rb +204 -0
- data/test/haml/templates/_av_partial_1.haml +9 -0
- data/test/haml/templates/_av_partial_1_ugly.haml +9 -0
- data/test/haml/templates/_av_partial_2.haml +5 -0
- data/test/haml/templates/_av_partial_2_ugly.haml +5 -0
- data/test/haml/templates/_layout.erb +3 -0
- data/test/haml/templates/_layout_for_partial.haml +3 -0
- data/test/haml/templates/_partial.haml +8 -0
- data/test/haml/templates/_text_area.haml +3 -0
- data/test/haml/templates/action_view.haml +47 -0
- data/test/haml/templates/action_view_ugly.haml +47 -0
- data/test/haml/templates/breakage.haml +8 -0
- data/test/haml/templates/content_for_layout.haml +10 -0
- data/test/haml/templates/eval_suppressed.haml +11 -0
- data/test/haml/templates/filters.haml +66 -0
- data/test/haml/templates/helpers.haml +95 -0
- data/test/haml/templates/helpful.haml +11 -0
- data/test/haml/templates/just_stuff.haml +83 -0
- data/test/haml/templates/list.haml +12 -0
- data/test/haml/templates/nuke_inner_whitespace.haml +32 -0
- data/test/haml/templates/nuke_outer_whitespace.haml +144 -0
- data/test/haml/templates/original_engine.haml +17 -0
- data/test/haml/templates/partial_layout.haml +3 -0
- data/test/haml/templates/partialize.haml +1 -0
- data/test/haml/templates/partials.haml +12 -0
- data/test/haml/templates/render_layout.haml +2 -0
- data/test/haml/templates/silent_script.haml +40 -0
- data/test/haml/templates/standard.haml +42 -0
- data/test/haml/templates/standard_ugly.haml +1 -0
- data/test/haml/templates/tag_parsing.haml +21 -0
- data/test/haml/templates/very_basic.haml +4 -0
- data/test/haml/templates/whitespace_handling.haml +87 -0
- data/test/linked_rails.rb +12 -0
- data/test/sass/css2sass_test.rb +193 -0
- data/test/sass/engine_test.rb +786 -0
- data/test/sass/functions_test.rb +96 -0
- data/test/sass/more_results/more1.css +9 -0
- data/test/sass/more_results/more1_with_line_comments.css +26 -0
- data/test/sass/more_results/more_import.css +29 -0
- data/test/sass/more_templates/_more_partial.sass +2 -0
- data/test/sass/more_templates/more1.sass +23 -0
- data/test/sass/more_templates/more_import.sass +11 -0
- data/test/sass/plugin_test.rb +208 -0
- data/test/sass/results/alt.css +4 -0
- data/test/sass/results/basic.css +9 -0
- data/test/sass/results/compact.css +5 -0
- data/test/sass/results/complex.css +87 -0
- data/test/sass/results/compressed.css +1 -0
- data/test/sass/results/expanded.css +19 -0
- data/test/sass/results/import.css +29 -0
- data/test/sass/results/line_numbers.css +49 -0
- data/test/sass/results/mixins.css +95 -0
- data/test/sass/results/multiline.css +24 -0
- data/test/sass/results/nested.css +22 -0
- data/test/sass/results/parent_ref.css +13 -0
- data/test/sass/results/script.css +16 -0
- data/test/sass/results/subdir/nested_subdir/nested_subdir.css +1 -0
- data/test/sass/results/subdir/subdir.css +3 -0
- data/test/sass/results/units.css +11 -0
- data/test/sass/script_test.rb +153 -0
- data/test/sass/templates/_partial.sass +2 -0
- data/test/sass/templates/alt.sass +16 -0
- data/test/sass/templates/basic.sass +23 -0
- data/test/sass/templates/bork.sass +2 -0
- data/test/sass/templates/bork2.sass +2 -0
- data/test/sass/templates/compact.sass +17 -0
- data/test/sass/templates/complex.sass +309 -0
- data/test/sass/templates/compressed.sass +15 -0
- data/test/sass/templates/expanded.sass +17 -0
- data/test/sass/templates/import.sass +11 -0
- data/test/sass/templates/importee.sass +19 -0
- data/test/sass/templates/line_numbers.sass +13 -0
- data/test/sass/templates/mixins.sass +76 -0
- data/test/sass/templates/multiline.sass +20 -0
- data/test/sass/templates/nested.sass +25 -0
- data/test/sass/templates/parent_ref.sass +25 -0
- data/test/sass/templates/script.sass +101 -0
- data/test/sass/templates/subdir/nested_subdir/_nested_partial.sass +2 -0
- data/test/sass/templates/subdir/nested_subdir/nested_subdir.sass +3 -0
- data/test/sass/templates/subdir/subdir.sass +6 -0
- data/test/sass/templates/units.sass +11 -0
- data/test/test_helper.rb +21 -0
- metadata +247 -0
data/lib/haml/shared.rb
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
require 'strscan'
|
|
2
|
+
|
|
3
|
+
# :stopdoc:
|
|
4
|
+
module Haml
|
|
5
|
+
# This module contains functionality that's shared across Haml and Sass.
|
|
6
|
+
module Shared
|
|
7
|
+
def self.handle_interpolation(str)
|
|
8
|
+
scan = StringScanner.new(str)
|
|
9
|
+
yield scan while scan.scan(/(.*?)(\\*)\#\{/)
|
|
10
|
+
scan.rest
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def self.balance(scanner, start, finish, count = 0)
|
|
14
|
+
str = ''
|
|
15
|
+
scanner = StringScanner.new(scanner) unless scanner.is_a? StringScanner
|
|
16
|
+
regexp = Regexp.new("(.*?)[\\#{start.chr}\\#{finish.chr}]", Regexp::MULTILINE)
|
|
17
|
+
while scanner.scan(regexp)
|
|
18
|
+
str << scanner.matched
|
|
19
|
+
count += 1 if scanner.matched[-1] == start
|
|
20
|
+
count -= 1 if scanner.matched[-1] == finish
|
|
21
|
+
return [str.strip, scanner.rest] if count == 0
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def self.human_indentation(indentation, was = false)
|
|
26
|
+
if !indentation.include?(?\t)
|
|
27
|
+
noun = 'space'
|
|
28
|
+
elsif !indentation.include?(?\s)
|
|
29
|
+
noun = 'tab'
|
|
30
|
+
else
|
|
31
|
+
return indentation.inspect + (was ? ' was' : '')
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
singular = indentation.length == 1
|
|
35
|
+
if was
|
|
36
|
+
was = singular ? ' was' : ' were'
|
|
37
|
+
else
|
|
38
|
+
was = ''
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
"#{indentation.length} #{noun}#{'s' unless singular}#{was}"
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
# :startdoc:
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# This file makes Haml work with Rails
|
|
2
|
+
# by monkeypatching the core template-compilation methods.
|
|
3
|
+
# This is necessary for versions <= 2.0.1 because the template handler API
|
|
4
|
+
# wasn't sufficiently powerful to deal with caching and so forth.
|
|
5
|
+
|
|
6
|
+
# This module refers to the ActionView module that's part of Ruby on Rails.
|
|
7
|
+
# Haml can be used as an alternate templating engine for it,
|
|
8
|
+
# and includes several modifications to make it more Haml-friendly.
|
|
9
|
+
# The documentation can be found
|
|
10
|
+
# here[http://rubyonrails.org/api/classes/ActionView/Base.html].
|
|
11
|
+
module ActionView
|
|
12
|
+
class Base # :nodoc:
|
|
13
|
+
def delegate_template_exists_with_haml(template_path)
|
|
14
|
+
template_exists?(template_path, :haml) && [:haml]
|
|
15
|
+
end
|
|
16
|
+
alias_method :delegate_template_exists_without_haml, :delegate_template_exists?
|
|
17
|
+
alias_method :delegate_template_exists?, :delegate_template_exists_with_haml
|
|
18
|
+
|
|
19
|
+
def compile_template_with_haml(extension, template, file_name, local_assigns)
|
|
20
|
+
return compile_haml(template, file_name, local_assigns) if extension.to_s == "haml"
|
|
21
|
+
compile_template_without_haml(extension, template, file_name, local_assigns)
|
|
22
|
+
end
|
|
23
|
+
alias_method :compile_template_without_haml, :compile_template
|
|
24
|
+
alias_method :compile_template, :compile_template_with_haml
|
|
25
|
+
|
|
26
|
+
def compile_haml(template, file_name, local_assigns)
|
|
27
|
+
render_symbol = assign_method_name(:haml, template, file_name)
|
|
28
|
+
locals = local_assigns.keys
|
|
29
|
+
|
|
30
|
+
@@template_args[render_symbol] ||= {}
|
|
31
|
+
locals_keys = @@template_args[render_symbol].keys | locals
|
|
32
|
+
@@template_args[render_symbol] = Haml::Util.to_hash(locals_keys.map {|k| [k, true]})
|
|
33
|
+
|
|
34
|
+
options = Haml::Template.options.dup
|
|
35
|
+
options[:filename] = file_name || 'compiled-template'
|
|
36
|
+
|
|
37
|
+
begin
|
|
38
|
+
Haml::Engine.new(template, options).def_method(CompiledTemplates, render_symbol, *locals_keys)
|
|
39
|
+
rescue Exception => e
|
|
40
|
+
if logger
|
|
41
|
+
logger.debug "ERROR: compiling #{render_symbol} RAISED #{e}"
|
|
42
|
+
logger.debug "Backtrace: #{e.backtrace.join("\n")}"
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
base_path = if defined?(extract_base_path_from)
|
|
46
|
+
# Rails 2.0.x
|
|
47
|
+
extract_base_path_from(file_name) || view_paths.first
|
|
48
|
+
else
|
|
49
|
+
# Rails <=1.2.6
|
|
50
|
+
@base_path
|
|
51
|
+
end
|
|
52
|
+
raise ActionView::TemplateError.new(base_path, file_name || template, @assigns, template, e)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
@@compile_time[render_symbol] = Time.now
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# :stopdoc:
|
|
2
|
+
# This file makes Haml work with Rails
|
|
3
|
+
# using the > 2.0.1 template handler API.
|
|
4
|
+
|
|
5
|
+
module Haml
|
|
6
|
+
class Plugin < ActionView::TemplateHandler
|
|
7
|
+
include ActionView::TemplateHandlers::Compilable if defined?(ActionView::TemplateHandlers::Compilable)
|
|
8
|
+
|
|
9
|
+
def compile(template)
|
|
10
|
+
options = Haml::Template.options.dup
|
|
11
|
+
|
|
12
|
+
# template is a template object in Rails >=2.1.0,
|
|
13
|
+
# a source string previously
|
|
14
|
+
if template.respond_to? :source
|
|
15
|
+
options[:filename] = template.filename
|
|
16
|
+
source = template.source
|
|
17
|
+
else
|
|
18
|
+
source = template
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
Haml::Engine.new(source, options).send(:precompiled_with_ambles, [])
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def cache_fragment(block, name = {}, options = nil)
|
|
25
|
+
@view.fragment_for(block, name, options) do
|
|
26
|
+
eval("_hamlout.buffer", block.binding)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
if defined? ActionView::Template and ActionView::Template.respond_to? :register_template_handler
|
|
33
|
+
ActionView::Template
|
|
34
|
+
else
|
|
35
|
+
ActionView::Base
|
|
36
|
+
end.register_template_handler(:haml, Haml::Plugin)
|
|
37
|
+
|
|
38
|
+
# In Rails 2.0.2, ActionView::TemplateError took arguments
|
|
39
|
+
# that we can't fill in from the Haml::Plugin context.
|
|
40
|
+
# Thus, we've got to monkeypatch ActionView::Base to catch the error.
|
|
41
|
+
if ActionView::TemplateError.instance_method(:initialize).arity == 5
|
|
42
|
+
class ActionView::Base
|
|
43
|
+
def compile_template(handler, template, file_name, local_assigns)
|
|
44
|
+
render_symbol = assign_method_name(handler, template, file_name)
|
|
45
|
+
|
|
46
|
+
# Move begin up two lines so it captures compilation exceptions.
|
|
47
|
+
begin
|
|
48
|
+
render_source = create_template_source(handler, template, render_symbol, local_assigns.keys)
|
|
49
|
+
line_offset = @@template_args[render_symbol].size + handler.line_offset
|
|
50
|
+
|
|
51
|
+
file_name = 'compiled-template' if file_name.blank?
|
|
52
|
+
CompiledTemplates.module_eval(render_source, file_name, -line_offset)
|
|
53
|
+
rescue Exception => e # errors from template code
|
|
54
|
+
if logger
|
|
55
|
+
logger.debug "ERROR: compiling #{render_symbol} RAISED #{e}"
|
|
56
|
+
logger.debug "Function body: #{render_source}"
|
|
57
|
+
logger.debug "Backtrace: #{e.backtrace.join("\n")}"
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
# There's no way to tell Haml about the filename,
|
|
61
|
+
# so we've got to insert it ourselves.
|
|
62
|
+
e.backtrace[0].gsub!('(haml)', file_name) if e.is_a?(Haml::Error)
|
|
63
|
+
|
|
64
|
+
raise ActionView::TemplateError.new(extract_base_path_from(file_name) || view_paths.first, file_name || template, @assigns, template, e)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
@@compile_time[render_symbol] = Time.now
|
|
68
|
+
# logger.debug "Compiled template #{file_name || template}\n ==> #{render_symbol}" if logger
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
# :startdoc:
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
require 'haml/engine'
|
|
2
|
+
|
|
3
|
+
module Haml
|
|
4
|
+
class Template
|
|
5
|
+
class << self
|
|
6
|
+
@@options = {}
|
|
7
|
+
|
|
8
|
+
# Gets various options for Haml. See README.rdoc for details.
|
|
9
|
+
def options
|
|
10
|
+
@@options
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# Sets various options for Haml. See README.rdoc for details.
|
|
14
|
+
def options=(value)
|
|
15
|
+
@@options = value
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# Decide how we want to load Haml into Rails.
|
|
22
|
+
# Patching was necessary for versions <= 2.0.1,
|
|
23
|
+
# but we can make it a normal handler for higher versions.
|
|
24
|
+
if defined?(ActionView::TemplateHandler)
|
|
25
|
+
require 'haml/template/plugin'
|
|
26
|
+
else
|
|
27
|
+
require 'haml/template/patch'
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
if defined?(RAILS_ROOT)
|
|
31
|
+
# Update init.rb to the current version
|
|
32
|
+
# if it's out of date.
|
|
33
|
+
#
|
|
34
|
+
# We can probably remove this as of v1.9,
|
|
35
|
+
# because the new init file is sufficiently flexible
|
|
36
|
+
# to not need updating.
|
|
37
|
+
rails_init_file = File.join(RAILS_ROOT, 'vendor', 'plugins', 'haml', 'init.rb')
|
|
38
|
+
haml_init_file = Haml.scope('init.rb')
|
|
39
|
+
begin
|
|
40
|
+
if File.exists?(rails_init_file)
|
|
41
|
+
require 'fileutils'
|
|
42
|
+
FileUtils.cp(haml_init_file, rails_init_file) unless FileUtils.cmp(rails_init_file, haml_init_file)
|
|
43
|
+
end
|
|
44
|
+
rescue SystemCallError
|
|
45
|
+
warn <<END
|
|
46
|
+
HAML WARNING:
|
|
47
|
+
#{rails_init_file} is out of date and couldn't be automatically updated.
|
|
48
|
+
Please run `haml --rails #{File.expand_path(RAILS_ROOT)}' to update it.
|
|
49
|
+
END
|
|
50
|
+
end
|
|
51
|
+
end
|
data/lib/haml/util.rb
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
require 'erb'
|
|
2
|
+
require 'set'
|
|
3
|
+
require 'enumerator'
|
|
4
|
+
|
|
5
|
+
module Haml
|
|
6
|
+
module Util
|
|
7
|
+
class << self; include Haml::Util; end
|
|
8
|
+
|
|
9
|
+
RUBY_VERSION = ::RUBY_VERSION.split(".").map {|s| s.to_i}
|
|
10
|
+
|
|
11
|
+
def to_hash(arr)
|
|
12
|
+
arr.compact.inject({}) {|h, (k, v)| h[k] = v; h}
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def map_keys(hash)
|
|
16
|
+
to_hash(hash.map {|k, v| [yield(k), v]})
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def map_vals(hash)
|
|
20
|
+
to_hash(hash.map {|k, v| [k, yield(v)]})
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def map_hash(hash, &block)
|
|
24
|
+
to_hash(hash.map(&block))
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def powerset(arr)
|
|
28
|
+
arr.inject([Set.new].to_set) do |powerset, el|
|
|
29
|
+
new_powerset = Set.new
|
|
30
|
+
powerset.each do |subset|
|
|
31
|
+
new_powerset << subset
|
|
32
|
+
new_powerset << subset + [el]
|
|
33
|
+
end
|
|
34
|
+
new_powerset
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def ruby1_8?
|
|
39
|
+
Haml::Util::RUBY_VERSION[0] == 1 && Haml::Util::RUBY_VERSION[1] < 9
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def has?(attr, klass, method)
|
|
43
|
+
klass.send("#{attr}s").include?(ruby1_8? ? method.to_s : method.to_sym)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def enum_with_index(enum)
|
|
47
|
+
ruby1_8? ? enum.enum_with_index : enum.each_with_index
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
class StaticConditionalContext
|
|
51
|
+
def initialize(set)
|
|
52
|
+
@set = set
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def method_missing(name, *args, &block)
|
|
56
|
+
super unless args.empty? && block.nil?
|
|
57
|
+
@set.include?(name)
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def def_static_method(klass, name, args, *vars)
|
|
62
|
+
erb = vars.pop
|
|
63
|
+
powerset(vars).each do |set|
|
|
64
|
+
context = StaticConditionalContext.new(set).instance_eval {binding}
|
|
65
|
+
klass.class_eval(<<METHOD)
|
|
66
|
+
def #{static_method_name(name, *vars.map {|v| set.include?(v)})}(#{args.join(', ')})
|
|
67
|
+
#{ERB.new(erb).result(context)}
|
|
68
|
+
end
|
|
69
|
+
METHOD
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def static_method_name(name, *vars)
|
|
74
|
+
"#{name}_#{vars.map {|v| !!v}.join('_')}"
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
data/lib/haml/version.rb
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
module Haml
|
|
2
|
+
module Version
|
|
3
|
+
# Returns a hash representing the version of Haml.
|
|
4
|
+
# The :major, :minor, and :teeny keys have their respective numbers.
|
|
5
|
+
# The :string key contains a human-readable string representation of the version.
|
|
6
|
+
# If Haml is checked out from Git,
|
|
7
|
+
# the :rev key will have the revision hash.
|
|
8
|
+
def version
|
|
9
|
+
return @@version if defined?(@@version)
|
|
10
|
+
|
|
11
|
+
numbers = File.read(scope('VERSION')).strip.split('.').map { |n| n.to_i }
|
|
12
|
+
@@version = {
|
|
13
|
+
:major => numbers[0],
|
|
14
|
+
:minor => numbers[1],
|
|
15
|
+
:teeny => numbers[2]
|
|
16
|
+
}
|
|
17
|
+
@@version[:string] = [:major, :minor, :teeny].map { |comp| @@version[comp] }.compact.join('.')
|
|
18
|
+
|
|
19
|
+
if File.exists?(scope('REVISION'))
|
|
20
|
+
rev = File.read(scope('REVISION')).strip
|
|
21
|
+
rev = nil if rev !~ /^([a-f0-9]+|\(.*\))$/
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
if (rev.nil? || rev == '(unknown)') && File.exists?(scope('.git/HEAD'))
|
|
25
|
+
rev = File.read(scope('.git/HEAD')).strip
|
|
26
|
+
if rev =~ /^ref: (.*)$/
|
|
27
|
+
rev = File.read(scope(".git/#{$1}")).strip
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
if rev
|
|
32
|
+
@@version[:rev] = rev
|
|
33
|
+
unless rev[0] == ?(
|
|
34
|
+
@@version[:string] << "."
|
|
35
|
+
@@version[:string] << rev[0...7]
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
@@version
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# Returns the path of file relative to the Haml root.
|
|
43
|
+
def scope(file) # :nodoc:
|
|
44
|
+
File.expand_path File.join(File.dirname(__FILE__), '..', '..', file)
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|