merbjedi-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/FAQ +138 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +332 -0
- data/REVISION +1 -0
- data/Rakefile +184 -0
- data/VERSION +1 -0
- data/bin/css2sass +7 -0
- data/bin/haml +9 -0
- data/bin/html2haml +7 -0
- data/bin/sass +8 -0
- data/extra/haml-mode.el +434 -0
- data/extra/sass-mode.el +98 -0
- data/init.rb +8 -0
- data/lib/haml.rb +1025 -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.rb +465 -0
- data/lib/haml/helpers/action_view_extensions.rb +45 -0
- data/lib/haml/helpers/action_view_mods.rb +181 -0
- data/lib/haml/html.rb +218 -0
- data/lib/haml/precompiler.rb +896 -0
- data/lib/haml/shared.rb +45 -0
- data/lib/haml/template.rb +51 -0
- data/lib/haml/template/patch.rb +58 -0
- data/lib/haml/template/plugin.rb +72 -0
- data/lib/haml/util.rb +77 -0
- data/lib/haml/version.rb +47 -0
- data/lib/sass.rb +1062 -0
- data/lib/sass/css.rb +388 -0
- data/lib/sass/engine.rb +501 -0
- data/lib/sass/environment.rb +33 -0
- data/lib/sass/error.rb +35 -0
- data/lib/sass/plugin.rb +203 -0
- data/lib/sass/plugin/merb.rb +56 -0
- data/lib/sass/plugin/rails.rb +24 -0
- data/lib/sass/repl.rb +44 -0
- data/lib/sass/script.rb +38 -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 +144 -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/tree/attr_node.rb +64 -0
- data/lib/sass/tree/comment_node.rb +30 -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 +97 -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/rails/init.rb +1 -0
- data/test/benchmark.rb +99 -0
- data/test/haml/engine_test.rb +852 -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 +42 -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 +752 -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 +152 -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 +273 -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,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
|
@@ -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:
|
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
|
data/lib/sass.rb
ADDED
@@ -0,0 +1,1062 @@
|
|
1
|
+
dir = File.dirname(__FILE__)
|
2
|
+
$LOAD_PATH.unshift dir unless $LOAD_PATH.include?(dir)
|
3
|
+
|
4
|
+
require 'haml/version'
|
5
|
+
|
6
|
+
# = Sass (Syntactically Awesome StyleSheets)
|
7
|
+
#
|
8
|
+
# Sass is a meta-language on top of CSS
|
9
|
+
# that's used to describe the style of a document
|
10
|
+
# cleanly and structurally,
|
11
|
+
# with more power than flat CSS allows.
|
12
|
+
# Sass both provides a simpler, more elegant syntax for CSS
|
13
|
+
# and implements various features that are useful
|
14
|
+
# for creating manageable stylesheets.
|
15
|
+
#
|
16
|
+
# == Features
|
17
|
+
#
|
18
|
+
# * Whitespace active
|
19
|
+
# * Well-formatted output
|
20
|
+
# * Elegant input
|
21
|
+
# * Feature-rich
|
22
|
+
#
|
23
|
+
# == Using Sass
|
24
|
+
#
|
25
|
+
# Sass can be used in three ways:
|
26
|
+
# as a plugin for Ruby on Rails,
|
27
|
+
# as a standalone Ruby module,
|
28
|
+
# and as a command-line tool.
|
29
|
+
# Sass is bundled with Haml,
|
30
|
+
# so if the Haml plugin or RubyGem is installed,
|
31
|
+
# Sass will already be installed as a plugin or gem, respectively.
|
32
|
+
# The first step for all of these is to install the Haml gem:
|
33
|
+
#
|
34
|
+
# gem install haml
|
35
|
+
#
|
36
|
+
# To enable it as a Rails plugin,
|
37
|
+
# then run
|
38
|
+
#
|
39
|
+
# haml --rails path/to/rails/app
|
40
|
+
#
|
41
|
+
# To enable Sass in Merb,
|
42
|
+
# add
|
43
|
+
#
|
44
|
+
# dependency "merb-haml"
|
45
|
+
#
|
46
|
+
# to config/dependencies.rb.
|
47
|
+
#
|
48
|
+
# Sass templates in Rails don't quite function in the same way as views,
|
49
|
+
# because they don't contain dynamic content,
|
50
|
+
# and so only need to be compiled when the template file has been updated.
|
51
|
+
# By default (see options, below),
|
52
|
+
# ".sass" files are placed in public/stylesheets/sass.
|
53
|
+
# Then, whenever necessary, they're compiled into corresponding CSS files in public/stylesheets.
|
54
|
+
# For instance, public/stylesheets/sass/main.sass would be compiled to public/stylesheets/main.css.
|
55
|
+
#
|
56
|
+
# To run Sass from the command line, just use
|
57
|
+
#
|
58
|
+
# sass input.sass output.css
|
59
|
+
#
|
60
|
+
# Use <tt>sass --help</tt> for full documentation.
|
61
|
+
#
|
62
|
+
# Using Sass in Ruby code is very simple.
|
63
|
+
# After installing the Haml gem,
|
64
|
+
# you can use it by running <tt>require "sass"</tt>
|
65
|
+
# and using Sass::Engine like so:
|
66
|
+
#
|
67
|
+
# engine = Sass::Engine.new("#main\n :background-color #0000ff")
|
68
|
+
# engine.render #=> "#main { background-color: #0000ff; }\n"
|
69
|
+
#
|
70
|
+
# == CSS Rules
|
71
|
+
#
|
72
|
+
# Rules in flat CSS have two elements:
|
73
|
+
# the selector
|
74
|
+
# (e.g. "#main", "div p", "li a:hover")
|
75
|
+
# and the attributes
|
76
|
+
# (e.g. "color: #00ff00;", "width: 5em;").
|
77
|
+
#
|
78
|
+
# Sass has both of these,
|
79
|
+
# as well as one additional element: nested rules.
|
80
|
+
#
|
81
|
+
# === Rules and Selectors
|
82
|
+
#
|
83
|
+
# However, some of the syntax is a little different.
|
84
|
+
# The syntax for selectors is the same,
|
85
|
+
# but instead of using brackets to delineate the attributes that belong to a particular rule,
|
86
|
+
# Sass uses indentation.
|
87
|
+
# For example:
|
88
|
+
#
|
89
|
+
# #main p
|
90
|
+
# <attribute>
|
91
|
+
# <attribute>
|
92
|
+
# ...
|
93
|
+
#
|
94
|
+
# Like CSS, you can stretch rules over multiple lines.
|
95
|
+
# However, unlike CSS, you can only do this if each line but the last
|
96
|
+
# ends with a comma.
|
97
|
+
# For example:
|
98
|
+
#
|
99
|
+
# .users #userTab,
|
100
|
+
# .posts #postsTab
|
101
|
+
# <attributes>
|
102
|
+
#
|
103
|
+
# === Attributes
|
104
|
+
#
|
105
|
+
# There are two different ways to write CSS attrbibutes.
|
106
|
+
# The first is very similar to the how you're used to writing them:
|
107
|
+
# with a colon between the name and the value.
|
108
|
+
# However, Sass attributes don't have semicolons at the end;
|
109
|
+
# each attribute is on its own line, so they aren't necessary.
|
110
|
+
# For example:
|
111
|
+
#
|
112
|
+
# #main p
|
113
|
+
# color: #00ff00
|
114
|
+
# width: 97%
|
115
|
+
#
|
116
|
+
# is compiled to:
|
117
|
+
#
|
118
|
+
# #main p {
|
119
|
+
# color: #00ff00;
|
120
|
+
# width: 97% }
|
121
|
+
#
|
122
|
+
# The second syntax for attributes is slightly different.
|
123
|
+
# The colon is at the beginning of the attribute,
|
124
|
+
# rather than between the name and the value,
|
125
|
+
# so it's easier to tell what elements are attributes just by glancing at them.
|
126
|
+
# For example:
|
127
|
+
#
|
128
|
+
# #main p
|
129
|
+
# :color #00ff00
|
130
|
+
# :width 97%
|
131
|
+
#
|
132
|
+
# is compiled to:
|
133
|
+
#
|
134
|
+
# #main p {
|
135
|
+
# color: #00ff00;
|
136
|
+
# width: 97% }
|
137
|
+
#
|
138
|
+
# By default, either attribute syntax may be used.
|
139
|
+
# If you want to force one or the other,
|
140
|
+
# see the <tt>:attribute_syntax</tt> option below.
|
141
|
+
#
|
142
|
+
# === Nested Rules
|
143
|
+
#
|
144
|
+
# Rules can also be nested within each other.
|
145
|
+
# This signifies that the inner rule's selector is a child of the outer selector.
|
146
|
+
# For example:
|
147
|
+
#
|
148
|
+
# #main p
|
149
|
+
# :color #00ff00
|
150
|
+
# :width 97%
|
151
|
+
#
|
152
|
+
# .redbox
|
153
|
+
# :background-color #ff0000
|
154
|
+
# :color #000000
|
155
|
+
#
|
156
|
+
# is compiled to:
|
157
|
+
#
|
158
|
+
# #main p {
|
159
|
+
# color: #00ff00;
|
160
|
+
# width: 97%; }
|
161
|
+
# #main p .redbox {
|
162
|
+
# background-color: #ff0000;
|
163
|
+
# color: #000000; }
|
164
|
+
#
|
165
|
+
# This makes insanely complicated CSS layouts with lots of nested selectors very simple:
|
166
|
+
#
|
167
|
+
# #main
|
168
|
+
# :width 97%
|
169
|
+
#
|
170
|
+
# p, div
|
171
|
+
# :font-size 2em
|
172
|
+
# a
|
173
|
+
# :font-weight bold
|
174
|
+
#
|
175
|
+
# pre
|
176
|
+
# :font-size 3em
|
177
|
+
#
|
178
|
+
# is compiled to:
|
179
|
+
#
|
180
|
+
# #main {
|
181
|
+
# width: 97%; }
|
182
|
+
# #main p, #main div {
|
183
|
+
# font-size: 2em; }
|
184
|
+
# #main p a, #main div a {
|
185
|
+
# font-weight: bold; }
|
186
|
+
# #main pre {
|
187
|
+
# font-size: 3em; }
|
188
|
+
#
|
189
|
+
# === Referencing Parent Rules
|
190
|
+
#
|
191
|
+
# In addition to the default behavior of inserting the parent selector
|
192
|
+
# as a CSS parent of the current selector
|
193
|
+
# (e.g. above, "#main" is the parent of "p"),
|
194
|
+
# you can have more fine-grained control over what's done with the parent selector
|
195
|
+
# by using the ampersand character "&" in your selectors.
|
196
|
+
#
|
197
|
+
# The ampersand is automatically replaced by the parent selector,
|
198
|
+
# instead of having it prepended.
|
199
|
+
# This allows you to cleanly create pseudo-attributes:
|
200
|
+
#
|
201
|
+
# a
|
202
|
+
# :font-weight bold
|
203
|
+
# :text-decoration none
|
204
|
+
# &:hover
|
205
|
+
# :text-decoration underline
|
206
|
+
# &:visited
|
207
|
+
# :font-weight normal
|
208
|
+
#
|
209
|
+
# Which would become:
|
210
|
+
#
|
211
|
+
# a {
|
212
|
+
# font-weight: bold;
|
213
|
+
# text-decoration: none; }
|
214
|
+
# a:hover {
|
215
|
+
# text-decoration: underline; }
|
216
|
+
# a:visited {
|
217
|
+
# font-weight: normal; }
|
218
|
+
#
|
219
|
+
# It also allows you to add selectors at the base of the hierarchy,
|
220
|
+
# which can be useuful for targeting certain styles to certain browsers:
|
221
|
+
#
|
222
|
+
# #main
|
223
|
+
# :width 90%
|
224
|
+
# #sidebar
|
225
|
+
# :float left
|
226
|
+
# :margin-left 20%
|
227
|
+
# .ie6 &
|
228
|
+
# :margin-left 40%
|
229
|
+
#
|
230
|
+
# Which would become:
|
231
|
+
#
|
232
|
+
# #main {
|
233
|
+
# width: 90%; }
|
234
|
+
# #main #sidebar {
|
235
|
+
# float: left;
|
236
|
+
# margin-left: 20%; }
|
237
|
+
# .ie6 #main #sidebar {
|
238
|
+
# margin-left: 40%; }
|
239
|
+
#
|
240
|
+
# === Attribute Namespaces
|
241
|
+
#
|
242
|
+
# CSS has quite a few attributes that are in "namespaces;"
|
243
|
+
# for instance, "font-family," "font-size," and "font-weight"
|
244
|
+
# are all in the "font" namespace.
|
245
|
+
# In CSS, if you want to set a bunch of attributes in the same namespace,
|
246
|
+
# you have to type it out each time.
|
247
|
+
# Sass offers a shortcut for this:
|
248
|
+
# just write the namespace one,
|
249
|
+
# then indent each of the sub-attributes within it.
|
250
|
+
# For example:
|
251
|
+
#
|
252
|
+
# .funky
|
253
|
+
# :font
|
254
|
+
# :family fantasy
|
255
|
+
# :size 30em
|
256
|
+
# :weight bold
|
257
|
+
#
|
258
|
+
# is compiled to:
|
259
|
+
#
|
260
|
+
# .funky {
|
261
|
+
# font-family: fantasy;
|
262
|
+
# font-size: 30em;
|
263
|
+
# font-weight: bold; }
|
264
|
+
#
|
265
|
+
# === Rule Escaping
|
266
|
+
#
|
267
|
+
# In case, for whatever reason, you need to write a rule
|
268
|
+
# that begins with a Sass-meaningful character,
|
269
|
+
# you can escape it with a backslash (<tt>\</tt>).
|
270
|
+
# For example:
|
271
|
+
#
|
272
|
+
# #main
|
273
|
+
# \+div
|
274
|
+
# clear: both
|
275
|
+
#
|
276
|
+
# is compiled to:
|
277
|
+
#
|
278
|
+
# #main +div {
|
279
|
+
# clear: both; }
|
280
|
+
#
|
281
|
+
# == Directives
|
282
|
+
#
|
283
|
+
# Directives allow the author to directly issue instructions to the Sass compiler.
|
284
|
+
# They're prefixed with an at sign, "<tt>@</tt>",
|
285
|
+
# followed by the name of the directive,
|
286
|
+
# a space, and any arguments to it -
|
287
|
+
# just like CSS directives.
|
288
|
+
# For example:
|
289
|
+
#
|
290
|
+
# @import red.sass
|
291
|
+
#
|
292
|
+
# Some directives can also control whether or how many times
|
293
|
+
# a chunk of Sass is output.
|
294
|
+
# Those are documented under Control Structures.
|
295
|
+
#
|
296
|
+
# === import
|
297
|
+
#
|
298
|
+
# The "@import" directive works in a very similar way to the CSS import directive,
|
299
|
+
# and sometimes compiles to a literal CSS "@import".
|
300
|
+
#
|
301
|
+
# Sass can import either other Sass files or plain CSS files.
|
302
|
+
# If it imports a Sass file,
|
303
|
+
# not only are the rules from that file included,
|
304
|
+
# but all variables in that file are made available in the current file.
|
305
|
+
#
|
306
|
+
# Sass looks for other Sass files in the working directory,
|
307
|
+
# and the Sass file directory under Rails or Merb.
|
308
|
+
# Additional search directories may be specified
|
309
|
+
# using the :load_paths option (see below).
|
310
|
+
#
|
311
|
+
# Sass can also import plain CSS files.
|
312
|
+
# In this case, it doesn't literally include the content of the files;
|
313
|
+
# rather, it uses the built-in CSS "@import" directive to tell the client program
|
314
|
+
# to import the files.
|
315
|
+
#
|
316
|
+
# The import directive can take either a full filename
|
317
|
+
# or a filename without an extension.
|
318
|
+
# If an extension isn't provided,
|
319
|
+
# Sass will try to find a Sass file with the given basename in the load paths,
|
320
|
+
# and, failing that, will assume a relevant CSS file will be available.
|
321
|
+
#
|
322
|
+
# For example,
|
323
|
+
#
|
324
|
+
# @import foo.sass
|
325
|
+
#
|
326
|
+
# would compile to
|
327
|
+
#
|
328
|
+
# .foo
|
329
|
+
# :color #f00
|
330
|
+
#
|
331
|
+
# whereas
|
332
|
+
#
|
333
|
+
# @import foo.css
|
334
|
+
#
|
335
|
+
# would compile to
|
336
|
+
#
|
337
|
+
# @import foo.css
|
338
|
+
#
|
339
|
+
# Finally,
|
340
|
+
#
|
341
|
+
# @import foo
|
342
|
+
#
|
343
|
+
# might compile to either,
|
344
|
+
# depending on whether a file called "foo.sass" existed.
|
345
|
+
#
|
346
|
+
# === @debug
|
347
|
+
#
|
348
|
+
# The "@debug" directive prints the value of a SassScript expression
|
349
|
+
# to standard error.
|
350
|
+
# It's useful for debugging Sass files
|
351
|
+
# that have complicated SassScript going on.
|
352
|
+
# For example:
|
353
|
+
#
|
354
|
+
# @debug 10em + 12em
|
355
|
+
#
|
356
|
+
# outputs:
|
357
|
+
#
|
358
|
+
# Line 1 DEBUG: 22em
|
359
|
+
#
|
360
|
+
# === @font-face, @media, etc.
|
361
|
+
#
|
362
|
+
# Sass behaves as you'd expect for normal CSS @-directives.
|
363
|
+
# For example:
|
364
|
+
#
|
365
|
+
# @font-face
|
366
|
+
# font-family: "Bitstream Vera Sans"
|
367
|
+
# src: url(http://foo.bar/bvs")
|
368
|
+
#
|
369
|
+
# compiles to:
|
370
|
+
#
|
371
|
+
# @font-face {
|
372
|
+
# font-family: "Bitstream Vera Sans";
|
373
|
+
# src: url(http://foo.bar/bvs"); }
|
374
|
+
#
|
375
|
+
# and
|
376
|
+
#
|
377
|
+
# @media print
|
378
|
+
# #sidebar
|
379
|
+
# display: none
|
380
|
+
#
|
381
|
+
# #main
|
382
|
+
# background-color: white
|
383
|
+
#
|
384
|
+
# compiles to:
|
385
|
+
#
|
386
|
+
# @media print {
|
387
|
+
# #sidebar {
|
388
|
+
# display: none; }
|
389
|
+
#
|
390
|
+
# #main {
|
391
|
+
# background-color: white; }
|
392
|
+
# }
|
393
|
+
#
|
394
|
+
# == SassScript
|
395
|
+
#
|
396
|
+
# In addition to the declarative templating system,
|
397
|
+
# Sass supports a simple language known as SassScript
|
398
|
+
# for dynamically computing CSS values and controlling
|
399
|
+
# the styles and selectors that get emitted.
|
400
|
+
#
|
401
|
+
# === Interactive Shell
|
402
|
+
#
|
403
|
+
# You can easily experiment with SassScript using the interactive shell.
|
404
|
+
# To launch the shell run the sass command-line with the -i option. At the
|
405
|
+
# prompt, enter any legal SassScript expression to have it evaluated
|
406
|
+
# and the result printed out for you:
|
407
|
+
#
|
408
|
+
# $ sass -i
|
409
|
+
# >> "Hello, Sassy World!"
|
410
|
+
# "Hello, Sassy World!"
|
411
|
+
# >> 1px + 1px + 1px
|
412
|
+
# 3px
|
413
|
+
# >> #777 + #777
|
414
|
+
# #eeeeee
|
415
|
+
# >> #777 + #888
|
416
|
+
# white
|
417
|
+
#
|
418
|
+
# === Variables
|
419
|
+
#
|
420
|
+
# The most straightforward way to use SassScript
|
421
|
+
# is to set and reference variables.
|
422
|
+
# Variables begin with exclamation marks,
|
423
|
+
# and are set like so:
|
424
|
+
#
|
425
|
+
# !width = 5em
|
426
|
+
#
|
427
|
+
# You can then refer to them by putting an equals sign
|
428
|
+
# after your attributes:
|
429
|
+
#
|
430
|
+
# #main
|
431
|
+
# :width = !width
|
432
|
+
#
|
433
|
+
# Variables that are first defined in a scoped context are only
|
434
|
+
# available in that context.
|
435
|
+
#
|
436
|
+
# === Data Types
|
437
|
+
#
|
438
|
+
# SassScript supports four data types:
|
439
|
+
# * numbers (e.g. <tt>1.2</tt>, <tt>13</tt>, <tt>10px</tt>)
|
440
|
+
# * strings of text (e.g. <tt>"foo"</tt>, <tt>"bar"</tt>)
|
441
|
+
# * colors (e.g. +blue+, <tt>##04a3f9</tt>)
|
442
|
+
# * booleans (e.g. +true+, +false+)
|
443
|
+
#
|
444
|
+
# Any text that doesn't fit into one of those types
|
445
|
+
# in a SassScript context will cause an error:
|
446
|
+
#
|
447
|
+
# p
|
448
|
+
# !width = 5em
|
449
|
+
# // This will cause an error
|
450
|
+
# :border = !width solid blue
|
451
|
+
# // Use one of the following forms instead:
|
452
|
+
# :border = "#{!width} solid blue"
|
453
|
+
# :border = !width "solid" "blue"
|
454
|
+
#
|
455
|
+
# is compiled to:
|
456
|
+
#
|
457
|
+
# p {
|
458
|
+
# border: 5em solid blue;
|
459
|
+
# border: 5em solid blue; }
|
460
|
+
#
|
461
|
+
#
|
462
|
+
# === Operations
|
463
|
+
#
|
464
|
+
# SassScript supports the standard arithmetic operations on numbers
|
465
|
+
# (<tt>+</tt>, <tt>-</tt>, <tt>*</tt>, <tt>/</tt>, <tt>%</tt>),
|
466
|
+
# and will automatically convert between units if it can:
|
467
|
+
#
|
468
|
+
# p
|
469
|
+
# :width = 1in + 8pt
|
470
|
+
#
|
471
|
+
# is compiled to:
|
472
|
+
#
|
473
|
+
# p {
|
474
|
+
# width: 1.111in; }
|
475
|
+
#
|
476
|
+
# Relational operators
|
477
|
+
# (<tt><</tt>, <tt>></tt>, <tt><=</tt>, <tt>>=</tt>)
|
478
|
+
# are also supported for numbers,
|
479
|
+
# and equality operators
|
480
|
+
# (<tt>==</tt>, <tt>!=</tt>)
|
481
|
+
# are supported for all types.
|
482
|
+
#
|
483
|
+
# Most arithmetic operations are supported for color values,
|
484
|
+
# where they work piecewise:
|
485
|
+
#
|
486
|
+
# p
|
487
|
+
# :color = #010203 + #040506
|
488
|
+
#
|
489
|
+
# is compiled to:
|
490
|
+
#
|
491
|
+
# p {
|
492
|
+
# color: #050709; }
|
493
|
+
#
|
494
|
+
# Some arithmetic operations even work between numbers and colors:
|
495
|
+
#
|
496
|
+
# p
|
497
|
+
# :color = #010203 * 2
|
498
|
+
#
|
499
|
+
# is compiled to:
|
500
|
+
#
|
501
|
+
# p {
|
502
|
+
# color: #020406; }
|
503
|
+
#
|
504
|
+
# The <tt>+</tt> operation can be used to concatenate strings:
|
505
|
+
#
|
506
|
+
# p
|
507
|
+
# :cursor = "e" + "-resize"
|
508
|
+
#
|
509
|
+
# is compiled to:
|
510
|
+
#
|
511
|
+
# p {
|
512
|
+
# cursor: e-resize; }
|
513
|
+
#
|
514
|
+
# Within a string of text, #{} style interpolation can be used to
|
515
|
+
# place dynamic values within the string:
|
516
|
+
#
|
517
|
+
# p
|
518
|
+
# :border = "#{5px + 10pt} solid #ccc"
|
519
|
+
#
|
520
|
+
# Finally, SassScript supports +and+, +or+, and +not+ operators
|
521
|
+
# for boolean values.
|
522
|
+
#
|
523
|
+
# === Parentheses
|
524
|
+
#
|
525
|
+
# Parentheses can be used to affect the order of operations:
|
526
|
+
#
|
527
|
+
# p
|
528
|
+
# :width = 1em + (2em * 3)
|
529
|
+
#
|
530
|
+
# is compiled to:
|
531
|
+
#
|
532
|
+
# p {
|
533
|
+
# width: 7em; }
|
534
|
+
#
|
535
|
+
# === Functions
|
536
|
+
#
|
537
|
+
# SassScript defines some useful functions
|
538
|
+
# that are called using the normal CSS function syntax:
|
539
|
+
#
|
540
|
+
# p
|
541
|
+
# :color = hsl(0, 100%, 50%)
|
542
|
+
#
|
543
|
+
# is compiled to:
|
544
|
+
#
|
545
|
+
# #main {
|
546
|
+
# color: #ff0000; }
|
547
|
+
#
|
548
|
+
# The following functions are provided: +hsl+, +percentage+, +round+, +ceil+, +floor+, and +abs+.
|
549
|
+
# You can define additional functions in ruby.
|
550
|
+
#
|
551
|
+
# See Sass::Script::Functions for more information.
|
552
|
+
#
|
553
|
+
# === Interpolation
|
554
|
+
#
|
555
|
+
# You can also use SassScript variables in selectors
|
556
|
+
# and attribute names using #{} interpolation syntax:
|
557
|
+
#
|
558
|
+
# !name = foo
|
559
|
+
# !attr = border
|
560
|
+
# p.#{!name}
|
561
|
+
# #{attr}-color: blue
|
562
|
+
#
|
563
|
+
# is compiled to:
|
564
|
+
#
|
565
|
+
# p.foo {
|
566
|
+
# border-color: blue; }
|
567
|
+
#
|
568
|
+
# === Optional Assignment
|
569
|
+
#
|
570
|
+
# You can assign to variables if they aren't already assigned
|
571
|
+
# using the ||= assignment operator. This means that if the
|
572
|
+
# variable has already been assigned to, it won't be re-assigned,
|
573
|
+
# but if it doesn't have a value yet, it will be given one.
|
574
|
+
#
|
575
|
+
# For example:
|
576
|
+
#
|
577
|
+
# !content = "First content"
|
578
|
+
# !content ||= "Second content?"
|
579
|
+
# !new_content ||= "First time reference"
|
580
|
+
#
|
581
|
+
# #main
|
582
|
+
# content = !content
|
583
|
+
# new-content = !new_content
|
584
|
+
#
|
585
|
+
# is compiled to:
|
586
|
+
#
|
587
|
+
# #main {
|
588
|
+
# content: First content;
|
589
|
+
# new-content: First time reference; }
|
590
|
+
#
|
591
|
+
# == Control Structures
|
592
|
+
#
|
593
|
+
# SassScript supports basic control structures for looping and conditionals
|
594
|
+
# using the same syntax as directives.
|
595
|
+
#
|
596
|
+
# === if
|
597
|
+
#
|
598
|
+
# The "@if" statement takes a SassScript expression
|
599
|
+
# and prints the code nested beneath it if the expression returns
|
600
|
+
# anything other than +false+:
|
601
|
+
#
|
602
|
+
# p
|
603
|
+
# @if 1 + 1 == 2
|
604
|
+
# :border 1px solid
|
605
|
+
# @if 5 < 3
|
606
|
+
# :border 2px dotted
|
607
|
+
#
|
608
|
+
# is compiled to:
|
609
|
+
#
|
610
|
+
# p {
|
611
|
+
# border: 1px solid; }
|
612
|
+
#
|
613
|
+
# The "@if" statement can be followed by several "@else if" statements
|
614
|
+
# and one "@else" statement.
|
615
|
+
# If the "@if" statement fails,
|
616
|
+
# the "@else if" statements are tried in order
|
617
|
+
# until one succeeds or the "@else" is reached.
|
618
|
+
# For example:
|
619
|
+
#
|
620
|
+
# !type = "monster"
|
621
|
+
# p
|
622
|
+
# @if !type == "ocean"
|
623
|
+
# :color blue
|
624
|
+
# @else if !type == "matador"
|
625
|
+
# :color red
|
626
|
+
# @else if !type == "monster"
|
627
|
+
# :color green
|
628
|
+
# @else
|
629
|
+
# :color black
|
630
|
+
#
|
631
|
+
# is compiled to:
|
632
|
+
#
|
633
|
+
# p {
|
634
|
+
# color: green; }
|
635
|
+
#
|
636
|
+
# === for
|
637
|
+
#
|
638
|
+
# The "@for" statement has two forms:
|
639
|
+
# "@for <var> from <start> to <end>" or
|
640
|
+
# "@for <var> from <start> through <end>".
|
641
|
+
# <var> is a variable name, like <tt>!i</tt>,
|
642
|
+
# and <start> and <end> are SassScript expressions
|
643
|
+
# that should return integers.
|
644
|
+
#
|
645
|
+
# The "@for" statement sets <var> to each number
|
646
|
+
# from <start> to <end>,
|
647
|
+
# including <end> if "through" is used.
|
648
|
+
# For example:
|
649
|
+
#
|
650
|
+
# @for !i from 1 through 3
|
651
|
+
# .item-#{!i}
|
652
|
+
# :width = 2em * !i
|
653
|
+
#
|
654
|
+
# is compiled to:
|
655
|
+
#
|
656
|
+
# .item-1 {
|
657
|
+
# width: 2em; }
|
658
|
+
# .item-2 {
|
659
|
+
# width: 4em; }
|
660
|
+
# .item-3 {
|
661
|
+
# width: 6em; }
|
662
|
+
#
|
663
|
+
# === while
|
664
|
+
#
|
665
|
+
# The "@while" statement repeatedly loops over the nested
|
666
|
+
# block until the statement evaluates to false. This can
|
667
|
+
# be used to achieve more complex looping than the @for
|
668
|
+
# statement is capable of.
|
669
|
+
# For example:
|
670
|
+
# !i = 6
|
671
|
+
# @while !i > 0
|
672
|
+
# .item-#{!i}
|
673
|
+
# :width = 2em * !i
|
674
|
+
# !i = !i - 2
|
675
|
+
#
|
676
|
+
# is compiled to:
|
677
|
+
#
|
678
|
+
# .item-6 {
|
679
|
+
# width: 12em; }
|
680
|
+
#
|
681
|
+
# .item-4 {
|
682
|
+
# width: 8em; }
|
683
|
+
#
|
684
|
+
# .item-2 {
|
685
|
+
# width: 4em; }
|
686
|
+
#
|
687
|
+
# == Mixins
|
688
|
+
#
|
689
|
+
# Mixins enable you to define groups of CSS attributes and
|
690
|
+
# then include them inline in any number of selectors
|
691
|
+
# throughout the document. This allows you to keep your
|
692
|
+
# stylesheets DRY and also avoid placing presentation
|
693
|
+
# classes in your markup.
|
694
|
+
#
|
695
|
+
# === Defining a Mixin
|
696
|
+
#
|
697
|
+
# To define a mixin you use a slightly modified form of selector syntax.
|
698
|
+
# For example the 'large-text' mixin is defined as follows:
|
699
|
+
#
|
700
|
+
# =large-text
|
701
|
+
# :font
|
702
|
+
# :family Arial
|
703
|
+
# :size 20px
|
704
|
+
# :weight bold
|
705
|
+
# :color #ff0000
|
706
|
+
#
|
707
|
+
# The initial '=' marks this as a mixin rather than a standard selector.
|
708
|
+
# The CSS rules that follow won't be included until the mixin is referenced later on.
|
709
|
+
# Anything you can put into a standard selector,
|
710
|
+
# you can put into a mixin definition. e.g.
|
711
|
+
#
|
712
|
+
# =clearfix
|
713
|
+
# display: inline-block
|
714
|
+
# &:after
|
715
|
+
# content: "."
|
716
|
+
# display: block
|
717
|
+
# height: 0
|
718
|
+
# clear: both
|
719
|
+
# visibility: hidden
|
720
|
+
# * html &
|
721
|
+
# height: 1px
|
722
|
+
#
|
723
|
+
#
|
724
|
+
# === Mixing it in
|
725
|
+
#
|
726
|
+
# Inlining a defined mixin is simple,
|
727
|
+
# just prepend a '+' symbol to the name of a mixin defined earlier in the document.
|
728
|
+
# So to inline the 'large-text' defined earlier,
|
729
|
+
# we include the statment '+large-text' in our selector definition thus:
|
730
|
+
#
|
731
|
+
# .page-title
|
732
|
+
# +large-text
|
733
|
+
# :padding 4px
|
734
|
+
# :margin
|
735
|
+
# :top 10px
|
736
|
+
#
|
737
|
+
#
|
738
|
+
# This will produce the following CSS output:
|
739
|
+
#
|
740
|
+
# .page-title {
|
741
|
+
# font-family: Arial;
|
742
|
+
# font-size: 20px;
|
743
|
+
# font-weight: bold;
|
744
|
+
# color: #ff0000;
|
745
|
+
# padding: 4px;
|
746
|
+
# margin-top: 10px;
|
747
|
+
# }
|
748
|
+
#
|
749
|
+
# Any number of mixins may be defined and there is no limit on
|
750
|
+
# the number that can be included in a particular selector.
|
751
|
+
#
|
752
|
+
# Mixin definitions can also include references to other mixins.
|
753
|
+
# E.g.
|
754
|
+
#
|
755
|
+
# =compound
|
756
|
+
# +highlighted-background
|
757
|
+
# +header-text
|
758
|
+
#
|
759
|
+
# =highlighted-background
|
760
|
+
# background:
|
761
|
+
# color: #fc0
|
762
|
+
# =header-text
|
763
|
+
# font:
|
764
|
+
# size: 20px
|
765
|
+
#
|
766
|
+
# Mixins that only define descendent selectors, can be safely mixed
|
767
|
+
# into the top most level of a document.
|
768
|
+
#
|
769
|
+
# === Arguments
|
770
|
+
#
|
771
|
+
# Mixins can take arguments which can be used with SassScript:
|
772
|
+
#
|
773
|
+
# =sexy-border(!color)
|
774
|
+
# :border
|
775
|
+
# :color = !color
|
776
|
+
# :width 1in
|
777
|
+
# :style dashed
|
778
|
+
# p
|
779
|
+
# +sexy-border("blue")
|
780
|
+
#
|
781
|
+
# is compiled to:
|
782
|
+
#
|
783
|
+
# p {
|
784
|
+
# border-color: #0000ff;
|
785
|
+
# border-width: 1in;
|
786
|
+
# border-style: dashed; }
|
787
|
+
#
|
788
|
+
# Mixins can also specify default values for their arguments:
|
789
|
+
#
|
790
|
+
# =sexy-border(!color, !width = 1in)
|
791
|
+
# :border
|
792
|
+
# :color = !color
|
793
|
+
# :width = !width
|
794
|
+
# :style dashed
|
795
|
+
# p
|
796
|
+
# +sexy-border("blue")
|
797
|
+
#
|
798
|
+
# is compiled to:
|
799
|
+
#
|
800
|
+
# p {
|
801
|
+
# border-color: #0000ff;
|
802
|
+
# border-width: 1in;
|
803
|
+
# border-style: dashed; }
|
804
|
+
#
|
805
|
+
# == Comments
|
806
|
+
#
|
807
|
+
# === Silent Comments
|
808
|
+
#
|
809
|
+
# It's simple to add "silent" comments,
|
810
|
+
# which don't output anything to the CSS document,
|
811
|
+
# to a Sass document.
|
812
|
+
# Simply use the familiar C-style notation for a one-line comment, "//",
|
813
|
+
# at the normal indentation level and all text following it won't be output.
|
814
|
+
# For example:
|
815
|
+
#
|
816
|
+
# // A very awesome rule.
|
817
|
+
# #awesome.rule
|
818
|
+
# // An equally awesome attribute.
|
819
|
+
# :awesomeness very
|
820
|
+
#
|
821
|
+
# becomes
|
822
|
+
#
|
823
|
+
# #awesome.rule {
|
824
|
+
# awesomeness: very; }
|
825
|
+
#
|
826
|
+
# You can also nest text beneath a comment to comment out a whole block.
|
827
|
+
# For example:
|
828
|
+
#
|
829
|
+
# // A very awesome rule
|
830
|
+
# #awesome.rule
|
831
|
+
# // Don't use these attributes
|
832
|
+
# color: green
|
833
|
+
# font-size: 10em
|
834
|
+
# color: red
|
835
|
+
#
|
836
|
+
# becomes
|
837
|
+
#
|
838
|
+
# #awesome.rule {
|
839
|
+
# color: red; }
|
840
|
+
#
|
841
|
+
# === Loud Comments
|
842
|
+
#
|
843
|
+
# "Loud" comments are just as easy as silent ones.
|
844
|
+
# These comments output to the document as CSS comments,
|
845
|
+
# and thus use the same opening sequence: "/*".
|
846
|
+
# For example:
|
847
|
+
#
|
848
|
+
# /* A very awesome rule.
|
849
|
+
# #awesome.rule
|
850
|
+
# /* An equally awesome attribute.
|
851
|
+
# :awesomeness very
|
852
|
+
#
|
853
|
+
# becomes
|
854
|
+
#
|
855
|
+
# /* A very awesome rule. */
|
856
|
+
# #awesome.rule {
|
857
|
+
# /* An equally awesome attribute. */
|
858
|
+
# awesomeness: very; }
|
859
|
+
#
|
860
|
+
# You can also nest content beneath loud comments. For example:
|
861
|
+
#
|
862
|
+
# #pbj
|
863
|
+
# /* This rule describes
|
864
|
+
# the styling of the element
|
865
|
+
# that represents
|
866
|
+
# a peanut butter and jelly sandwich.
|
867
|
+
# :background-image url(/images/pbj.png)
|
868
|
+
# :color red
|
869
|
+
#
|
870
|
+
# becomes
|
871
|
+
#
|
872
|
+
# #pbj {
|
873
|
+
# /* This rule describes
|
874
|
+
# * the styling of the element
|
875
|
+
# * that represents
|
876
|
+
# * a peanut butter and jelly sandwich. */
|
877
|
+
# background-image: url(/images/pbj.png);
|
878
|
+
# color: red; }
|
879
|
+
#
|
880
|
+
# == Output Style
|
881
|
+
#
|
882
|
+
# Although the default CSS style that Sass outputs is very nice,
|
883
|
+
# and reflects the structure of the document in a similar way that Sass does,
|
884
|
+
# sometimes it's good to have other formats available.
|
885
|
+
#
|
886
|
+
# Sass allows you to choose between three different output styles
|
887
|
+
# by setting the <tt>:style</tt> option.
|
888
|
+
# In Rails, this is done by setting <tt>Sass::Plugin.options[:style]</tt>;
|
889
|
+
# outside Rails, it's done by passing an options hash with </tt>:style</tt> set.
|
890
|
+
#
|
891
|
+
# === <tt>:nested</tt>
|
892
|
+
#
|
893
|
+
# Nested style is the default Sass style,
|
894
|
+
# because it reflects the structure of the document
|
895
|
+
# in much the same way Sass does.
|
896
|
+
# Each attribute has its own line,
|
897
|
+
# but the indentation isn't constant.
|
898
|
+
# Each rule is indented based on how deeply it's nested.
|
899
|
+
# For example:
|
900
|
+
#
|
901
|
+
# #main {
|
902
|
+
# color: #fff;
|
903
|
+
# background-color: #000; }
|
904
|
+
# #main p {
|
905
|
+
# width: 10em; }
|
906
|
+
#
|
907
|
+
# .huge {
|
908
|
+
# font-size: 10em;
|
909
|
+
# font-weight: bold;
|
910
|
+
# text-decoration: underline; }
|
911
|
+
#
|
912
|
+
# Nested style is very useful when looking at large CSS files
|
913
|
+
# for the same reason Sass is useful for making them:
|
914
|
+
# it allows you to very easily grasp the structure of the file
|
915
|
+
# without actually reading anything.
|
916
|
+
#
|
917
|
+
# === <tt>:expanded</tt>
|
918
|
+
#
|
919
|
+
# Expanded is the typical human-made CSS style,
|
920
|
+
# with each attribute and rule taking up one line.
|
921
|
+
# Attributes are indented within the rules,
|
922
|
+
# but the rules aren't indented in any special way.
|
923
|
+
# For example:
|
924
|
+
#
|
925
|
+
# #main {
|
926
|
+
# color: #fff;
|
927
|
+
# background-color: #000;
|
928
|
+
# }
|
929
|
+
# #main p {
|
930
|
+
# width: 10em;
|
931
|
+
# }
|
932
|
+
#
|
933
|
+
# .huge {
|
934
|
+
# font-size: 10em;
|
935
|
+
# font-weight: bold;
|
936
|
+
# text-decoration: underline;
|
937
|
+
# }
|
938
|
+
#
|
939
|
+
# === <tt>:compact</tt>
|
940
|
+
#
|
941
|
+
# Compact style, as the name would imply,
|
942
|
+
# takes up less space than Nested or Expanded.
|
943
|
+
# However, it's also harder to read.
|
944
|
+
# Each CSS rule takes up only one line,
|
945
|
+
# with every attribute defined on that line.
|
946
|
+
# Nested rules are placed next to each other with no newline,
|
947
|
+
# while groups of rules have newlines between them.
|
948
|
+
# For example:
|
949
|
+
#
|
950
|
+
# #main { color: #fff; background-color: #000; }
|
951
|
+
# #main p { width: 10em; }
|
952
|
+
#
|
953
|
+
# .huge { font-size: 10em; font-weight: bold; text-decoration: underline; }
|
954
|
+
#
|
955
|
+
# === <tt>:compressed</tt>
|
956
|
+
#
|
957
|
+
# Compressed style takes up the minimum amount of space possible,
|
958
|
+
# having no whitespace except that necessary to separate selectors
|
959
|
+
# and a newline at the end of the file.
|
960
|
+
# It's not meant to be human-readable.
|
961
|
+
# For example:
|
962
|
+
#
|
963
|
+
# #main{color:#fff;background-color:#000}#main p{width:10em}.huge{font-size:10em;font-weight:bold;text-decoration:underline}
|
964
|
+
#
|
965
|
+
# == Sass Options
|
966
|
+
#
|
967
|
+
# Options can be set by setting the <tt>Sass::Plugin.options</tt> hash
|
968
|
+
# in <tt>environment.rb</tt> in Rails...
|
969
|
+
#
|
970
|
+
# Sass::Plugin.options[:style] = :compact
|
971
|
+
#
|
972
|
+
# ...or by setting the <tt>Merb::Plugin.config[:sass]</tt> hash in <tt>init.rb</tt> in Merb...
|
973
|
+
#
|
974
|
+
# Merb::Plugin.config[:sass][:style] = :compact
|
975
|
+
#
|
976
|
+
# ...or by passing an options hash to Sass::Engine.new.
|
977
|
+
# Available options are:
|
978
|
+
#
|
979
|
+
# [<tt>:style</tt>] Sets the style of the CSS output.
|
980
|
+
# See the section on Output Style, above.
|
981
|
+
#
|
982
|
+
# [<tt>:attribute_syntax</tt>] Forces the document to use one syntax for attributes.
|
983
|
+
# If the correct syntax isn't used, an error is thrown.
|
984
|
+
# <tt>:normal</tt> forces the use of a colon
|
985
|
+
# before the attribute name.
|
986
|
+
# For example: <tt>:color #0f3</tt>
|
987
|
+
# or <tt>:width = !main_width</tt>.
|
988
|
+
# <tt>:alternate</tt> forces the use of a colon or equals sign
|
989
|
+
# after the attribute name.
|
990
|
+
# For example: <tt>color: #0f3</tt>
|
991
|
+
# or <tt>width = !main_width</tt>.
|
992
|
+
# By default, either syntax is valid.
|
993
|
+
#
|
994
|
+
# [<tt>:never_update</tt>] Whether the CSS files should never be updated,
|
995
|
+
# even if the template file changes.
|
996
|
+
# Setting this to true may give small performance gains.
|
997
|
+
# It always defaults to false.
|
998
|
+
# Only has meaning within Ruby on Rails or Merb.
|
999
|
+
#
|
1000
|
+
# [<tt>:always_update</tt>] Whether the CSS files should be updated every
|
1001
|
+
# time a controller is accessed,
|
1002
|
+
# as opposed to only when the template has been modified.
|
1003
|
+
# Defaults to false.
|
1004
|
+
# Only has meaning within Ruby on Rails or Merb.
|
1005
|
+
#
|
1006
|
+
# [<tt>:always_check</tt>] Whether a Sass template should be checked for updates every
|
1007
|
+
# time a controller is accessed,
|
1008
|
+
# as opposed to only when the Rails server starts.
|
1009
|
+
# If a Sass template has been updated,
|
1010
|
+
# it will be recompiled and will overwrite the corresponding CSS file.
|
1011
|
+
# Defaults to false in production mode, true otherwise.
|
1012
|
+
# Only has meaning within Ruby on Rails or Merb.
|
1013
|
+
#
|
1014
|
+
# [<tt>:full_exception</tt>] Whether an error in the Sass code
|
1015
|
+
# should cause Sass to provide a detailed description.
|
1016
|
+
# If set to true, the specific error will be displayed
|
1017
|
+
# along with a line number and source snippet.
|
1018
|
+
# Otherwise, a simple uninformative error message will be displayed.
|
1019
|
+
# Defaults to false in production mode, true otherwise.
|
1020
|
+
# Only has meaning within Ruby on Rails or Merb.
|
1021
|
+
#
|
1022
|
+
# [<tt>:template_location</tt>] A path to the root sass template directory for you application.
|
1023
|
+
# If a hash, :css_location is ignored and this option designates
|
1024
|
+
# both a mapping between input and output directories.
|
1025
|
+
# May also be given a list of 2-element lists, instead of a hash.
|
1026
|
+
# Defaults to <tt>RAILS_ROOT + "/public/stylesheets/sass"</tt>
|
1027
|
+
# or <tt>MERB_ROOT + "/public/stylesheets/sass"</tt>.
|
1028
|
+
# Only has meaning within Ruby on Rails or Merb.
|
1029
|
+
# This will be derived from the :css_location path list if not provided
|
1030
|
+
# by appending a folder of "sass" to each corresponding css location.
|
1031
|
+
#
|
1032
|
+
# [<tt>:css_location</tt>] The path where CSS output should be written to.
|
1033
|
+
# This option is ignored when :template_location is a Hash.
|
1034
|
+
# Defaults to <tt>RAILS_ROOT + "/public/stylesheets"</tt>
|
1035
|
+
# or <tt>MERB_ROOT + "/public/stylesheets"</tt>.
|
1036
|
+
# Only has meaning within Ruby on Rails or Merb.
|
1037
|
+
#
|
1038
|
+
# [<tt>:filename</tt>] The filename of the file being rendered.
|
1039
|
+
# This is used solely for reporting errors,
|
1040
|
+
# and is automatically set when using Rails or Merb.
|
1041
|
+
#
|
1042
|
+
# [<tt>:load_paths</tt>] An array of filesystem paths which should be searched
|
1043
|
+
# for Sass templates imported with the "@import" directive.
|
1044
|
+
# This defaults to the working directory and, in Rails or Merb,
|
1045
|
+
# whatever <tt>:template_location</tt> is.
|
1046
|
+
#
|
1047
|
+
# [<tt>:line_numbers</tt>] When set to true, causes the line number and file
|
1048
|
+
# where a selector is defined to be emitted into the compiled CSS
|
1049
|
+
# as a comment. Useful for debugging especially when using imports
|
1050
|
+
# and mixins.
|
1051
|
+
module Sass
|
1052
|
+
extend Haml::Version
|
1053
|
+
|
1054
|
+
# A string representing the version of Sass.
|
1055
|
+
# A more fine-grained representation is available from Sass.version.
|
1056
|
+
VERSION = version[:string] unless defined?(Sass::VERSION)
|
1057
|
+
|
1058
|
+
end
|
1059
|
+
|
1060
|
+
require 'haml/util'
|
1061
|
+
require 'sass/engine'
|
1062
|
+
require 'sass/plugin' if defined?(Merb::Plugins)
|