commit
39d4c54c8f
21
lib/haml.rb
21
lib/haml.rb
|
@ -23,13 +23,10 @@ $LOAD_PATH << dir unless $LOAD_PATH.include?(dir)
|
|||
#
|
||||
# == Using Haml
|
||||
#
|
||||
# Haml can be used in two ways:
|
||||
# Haml can be used in three ways:
|
||||
# as a plugin for Ruby on Rails,
|
||||
# and as a standalone Ruby module.
|
||||
#
|
||||
# Sass can be used in several ways:
|
||||
# As a template engine for Ruby on Rails or Merb,
|
||||
# or as a standalone engine.
|
||||
# as a standalone Ruby module,
|
||||
# and as a command-line tool.
|
||||
# The first step for all of these is to install the Haml gem:
|
||||
#
|
||||
# gem install haml
|
||||
|
@ -39,13 +36,15 @@ $LOAD_PATH << dir unless $LOAD_PATH.include?(dir)
|
|||
#
|
||||
# haml --rails path/to/rails/app
|
||||
#
|
||||
# Haml is enabled in Merb by default,
|
||||
# so Merb users don't have to do anything more.
|
||||
#
|
||||
# Once it's installed, all view files with the ".haml" extension
|
||||
# (or ".html.haml" for Merb or edge Rails)
|
||||
# Once it's installed, all view files with the ".html.haml" extension
|
||||
# will be compiled using Haml.
|
||||
#
|
||||
# To run Haml from the commandline, just use
|
||||
#
|
||||
# haml input.haml output.html
|
||||
#
|
||||
# Use <tt>haml --help</tt> for full documentation.
|
||||
#
|
||||
# You can access instance variables in Haml templates
|
||||
# the same way you do in ERb templates.
|
||||
# Helper methods are also available in Haml templates.
|
||||
|
|
15
lib/sass.rb
15
lib/sass.rb
|
@ -20,9 +20,10 @@ $LOAD_PATH << dir unless $LOAD_PATH.include?(dir)
|
|||
#
|
||||
# == Using Sass
|
||||
#
|
||||
# Sass can be used in several ways:
|
||||
# As a plugin for Ruby on Rails or Merb,
|
||||
# or as a standalone parser.
|
||||
# Sass can be used in three ways:
|
||||
# as a plugin for Ruby on Rails,
|
||||
# as a standalone Ruby module,
|
||||
# and as a command-line tool.
|
||||
# Sass is bundled with Haml,
|
||||
# so if the Haml plugin or RubyGem is installed,
|
||||
# Sass will already be installed as a plugin or gem, respectively.
|
||||
|
@ -42,7 +43,7 @@ $LOAD_PATH << dir unless $LOAD_PATH.include?(dir)
|
|||
#
|
||||
# to config/dependencies.rb.
|
||||
#
|
||||
# Sass templates in Rails and Merb don't quite function in the same way as views,
|
||||
# Sass templates in Rails don't quite function in the same way as views,
|
||||
# because they don't contain dynamic content,
|
||||
# and so only need to be compiled when the template file has been updated.
|
||||
# By default (see options, below),
|
||||
|
@ -50,6 +51,12 @@ $LOAD_PATH << dir unless $LOAD_PATH.include?(dir)
|
|||
# Then, whenever necessary, they're compiled into corresponding CSS files in public/stylesheets.
|
||||
# For instance, public/stylesheets/sass/main.sass would be compiled to public/stylesheets/main.css.
|
||||
#
|
||||
# To run Sass from the commandline, just use
|
||||
#
|
||||
# sass input.sass output.css
|
||||
#
|
||||
# Use <tt>sass --help</tt> for full documentation.
|
||||
#
|
||||
# Using Sass in Ruby code is very simple.
|
||||
# After installing the Haml gem,
|
||||
# you can use it by running <tt>require "sass"</tt>
|
||||
|
|
|
@ -18,7 +18,7 @@ module Sass
|
|||
end
|
||||
|
||||
class ValueNode
|
||||
def to_sass(tabs)
|
||||
def to_sass(tabs, opts = {})
|
||||
"#{value}\n"
|
||||
end
|
||||
end
|
||||
|
@ -40,6 +40,12 @@ module Sass
|
|||
"#{' ' * tabs}#{opts[:alternate] ? '' : ':'}#{name}#{opts[:alternate] ? ':' : ''} #{value}\n"
|
||||
end
|
||||
end
|
||||
|
||||
class DirectiveNode
|
||||
def to_sass(tabs, opts = {})
|
||||
"#{' ' * tabs}#{value}#{children.map {|c| c.to_sass(tabs + 1, opts)}}\n"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# This class is based on the Ruby 1.9 ordered hashes.
|
||||
|
@ -132,7 +138,6 @@ module Sass
|
|||
def build_tree
|
||||
root = Tree::Node.new({})
|
||||
whitespace
|
||||
directives root
|
||||
rules root
|
||||
expand_commas root
|
||||
parent_ref_rules root
|
||||
|
@ -142,37 +147,33 @@ module Sass
|
|||
root
|
||||
end
|
||||
|
||||
def directives(root)
|
||||
while @template.scan(/@/)
|
||||
name = @template.scan /[^\s;]+/
|
||||
def rules(root)
|
||||
while r = rule
|
||||
root << r
|
||||
whitespace
|
||||
value = @template.scan /[^;]+/
|
||||
assert_match /;/
|
||||
whitespace
|
||||
|
||||
if name == "import" && value =~ /^(url\()?"?([^\s\(\)\"]+)\.css"?\)?$/
|
||||
value = $2
|
||||
end
|
||||
|
||||
root << Tree::ValueNode.new("@#{name} #{value};", {})
|
||||
end
|
||||
end
|
||||
|
||||
def rules(root)
|
||||
rules = []
|
||||
while @template.scan(/[^\{\s]+/)
|
||||
rules << @template[0]
|
||||
def rule
|
||||
return unless rule = @template.scan(/[^\{\};]+/)
|
||||
rule.strip!
|
||||
directive = rule[0] == ?@
|
||||
|
||||
if directive
|
||||
node = Tree::DirectiveNode.new(rule, {})
|
||||
return node if @template.scan(/;/)
|
||||
|
||||
assert_match /\{/
|
||||
whitespace
|
||||
|
||||
if @template.scan(/\{/)
|
||||
result = Tree::RuleNode.new(rules.join(' '), {})
|
||||
root << result
|
||||
rules = []
|
||||
|
||||
whitespace
|
||||
attributes(result)
|
||||
end
|
||||
rules(node)
|
||||
return node
|
||||
end
|
||||
|
||||
assert_match /\{/
|
||||
node = Tree::RuleNode.new(rule, {})
|
||||
attributes(node)
|
||||
return node
|
||||
end
|
||||
|
||||
def attributes(rule)
|
||||
|
|
Loading…
Reference in New Issue