mirror of
https://github.com/haml/haml.git
synced 2022-11-09 12:33:31 -05:00
Get rid of trailing whitespace.
This commit is contained in:
parent
d4d176b138
commit
84fdde13a5
30 changed files with 301 additions and 301 deletions
|
@ -67,7 +67,7 @@ a tag without a name defaults to a div. So
|
|||
becomes
|
||||
|
||||
<div id='foo'>Hello!</div>
|
||||
|
||||
|
||||
Haml uses indentation
|
||||
to bring the individual elements to represent the HTML structure.
|
||||
A tag's children are indented two spaces more than the parent tag.
|
||||
|
@ -235,8 +235,8 @@ the documentation for the Sass module.
|
|||
|
||||
Haml and Sass are designed by Hampton Catlin (hcatlin) and he is the author
|
||||
of the original implementation. However, Hampton doesn't even know his way
|
||||
around the code anymore and mostly just concentrates on the language issues.
|
||||
Hampton lives in Toronto, Ontario (though he's an American by birth) and
|
||||
around the code anymore and mostly just concentrates on the language issues.
|
||||
Hampton lives in Toronto, Ontario (though he's an American by birth) and
|
||||
is a partner at Unspace Interactive.
|
||||
|
||||
Nathan Weizenbaum is the primary maintainer and architect of the "modern" Ruby
|
||||
|
|
12
Rakefile
12
Rakefile
|
@ -68,7 +68,7 @@ END
|
|||
but it can function as a stand-alone templating engine.
|
||||
END
|
||||
#'
|
||||
|
||||
|
||||
readmes = FileList.new('*') do |list|
|
||||
list.exclude(/(^|[^.a-z])[a-z]+/)
|
||||
list.exclude('TODO')
|
||||
|
@ -133,7 +133,7 @@ END
|
|||
rdoc.rdoc_dir = 'rdoc_devel'
|
||||
rdoc.options << '--all'
|
||||
rdoc.rdoc_files.include('test/*.rb')
|
||||
|
||||
|
||||
# Get rid of exclusion rules
|
||||
rdoc.rdoc_files = Rake::FileList.new(*rdoc.rdoc_files.to_a)
|
||||
rdoc.rdoc_files.include('lib/haml/buffer.rb')
|
||||
|
@ -167,17 +167,17 @@ END
|
|||
require 'test/profile'
|
||||
|
||||
engine = ENV['ENGINE'] && ENV['ENGINE'].downcase == 'sass' ? Sass : Haml
|
||||
|
||||
|
||||
puts '-'*51, "Profiling #{engine}", '-'*51
|
||||
|
||||
|
||||
args = []
|
||||
args.push ENV['TIMES'].to_i if ENV['TIMES']
|
||||
args.push ENV['FILE'] if ENV['FILE']
|
||||
|
||||
|
||||
profiler = engine::Profiler.new
|
||||
res = profiler.profile(*args)
|
||||
puts res
|
||||
|
||||
|
||||
puts '-'*51
|
||||
end
|
||||
|
||||
|
|
|
@ -7,10 +7,10 @@
|
|||
;;; functions are similar to those in yaml-mode and python-mode.
|
||||
|
||||
;;; To install, save this somewhere and add the following to your .emacs file:
|
||||
;;;
|
||||
;;;
|
||||
;;; (add-to-list 'load-path "/path/to/haml-mode.el")
|
||||
;;; (require 'haml-mode nil 't)
|
||||
;;;
|
||||
;;;
|
||||
|
||||
;;; Code:
|
||||
|
||||
|
|
278
lib/haml.rb
278
lib/haml.rb
|
@ -2,18 +2,18 @@ dir = File.dirname(__FILE__)
|
|||
$LOAD_PATH << dir unless $LOAD_PATH.include?(dir)
|
||||
|
||||
# = Haml (XHTML Abstraction Markup Language)
|
||||
#
|
||||
#
|
||||
# Haml is a markup language
|
||||
# that's used to cleanly and simply describe the XHTML of any web document,
|
||||
# without the use of inline code.
|
||||
# Haml functions as a replacement
|
||||
# for inline page templating systems such as PHP, ERB, and ASP.
|
||||
# However, Haml avoids the need for explicitly coding XHTML into the template,
|
||||
# for inline page templating systems such as PHP, ERB, and ASP.
|
||||
# However, Haml avoids the need for explicitly coding XHTML into the template,
|
||||
# because it is actually an abstract description of the XHTML,
|
||||
# with some code to generate dynamic content.
|
||||
#
|
||||
#
|
||||
# == Features
|
||||
#
|
||||
#
|
||||
# * Whitespace active
|
||||
# * Well-formatted markup
|
||||
# * DRY
|
||||
|
@ -36,9 +36,9 @@ $LOAD_PATH << dir unless $LOAD_PATH.include?(dir)
|
|||
#
|
||||
# To enable it as a Rails plugin,
|
||||
# then run
|
||||
#
|
||||
#
|
||||
# haml --rails path/to/rails/app
|
||||
#
|
||||
#
|
||||
# Haml is enabled in Merb by default,
|
||||
# so Merb users don't have to do anything more.
|
||||
#
|
||||
|
@ -50,24 +50,24 @@ $LOAD_PATH << dir unless $LOAD_PATH.include?(dir)
|
|||
# the same way you do in ERb templates.
|
||||
# Helper methods are also available in Haml templates.
|
||||
# For example (this example uses Rails, but the principle for Merb is the same):
|
||||
#
|
||||
#
|
||||
# # file: app/controllers/movies_controller.rb
|
||||
#
|
||||
#
|
||||
# class MoviesController < ApplicationController
|
||||
# def index
|
||||
# @title = "Teen Wolf"
|
||||
# end
|
||||
# end
|
||||
#
|
||||
#
|
||||
# -# file: app/views/movies/index.haml
|
||||
#
|
||||
#
|
||||
# #content
|
||||
# .title
|
||||
# %h1= @title
|
||||
# = link_to 'Home', home_url
|
||||
#
|
||||
#
|
||||
# may be compiled to:
|
||||
#
|
||||
#
|
||||
# <div id='content'>
|
||||
# <div class='title'>
|
||||
# <h1>Teen Wolf</h1>
|
||||
|
@ -89,41 +89,41 @@ $LOAD_PATH << dir unless $LOAD_PATH.include?(dir)
|
|||
# engine.render #=> "<p>Haml code!</p>\n"
|
||||
#
|
||||
# == Characters with meaning to Haml
|
||||
#
|
||||
#
|
||||
# Various characters, when placed at a certain point in a line,
|
||||
# instruct Haml to render different types of things.
|
||||
#
|
||||
#
|
||||
# === XHTML Tags
|
||||
#
|
||||
#
|
||||
# These characters render XHTML tags.
|
||||
#
|
||||
#
|
||||
# ==== %
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
# The percent character is placed at the beginning of a line.
|
||||
# It's followed immediately by the name of an element,
|
||||
# then optionally by modifiers (see below), a space,
|
||||
# and text to be rendered inside the element.
|
||||
# It creates an element in the form of <tt><element></element></tt>.
|
||||
# For example:
|
||||
#
|
||||
#
|
||||
# %one
|
||||
# %two
|
||||
# %three Hey there
|
||||
#
|
||||
#
|
||||
# is compiled to:
|
||||
#
|
||||
#
|
||||
# <one>
|
||||
# <two>
|
||||
# <three>Hey there</three>
|
||||
# </two>
|
||||
# </one>
|
||||
#
|
||||
#
|
||||
# Any string is a valid element name;
|
||||
# Haml will automatically generate opening and closing tags for any element.
|
||||
#
|
||||
#
|
||||
# ==== {}
|
||||
#
|
||||
#
|
||||
# Brackets represent a Ruby hash
|
||||
# that is used for specifying the attributes of an element.
|
||||
# It is literally evaluated as a Ruby hash,
|
||||
|
@ -132,13 +132,13 @@ $LOAD_PATH << dir unless $LOAD_PATH.include?(dir)
|
|||
# will be replaced by appropriate escape sequences.
|
||||
# The hash is placed after the tag is defined.
|
||||
# For example:
|
||||
#
|
||||
#
|
||||
# %head{ :name => "doc_head" }
|
||||
# %script{ 'type' => "text/" + "javascript",
|
||||
# :src => "javascripts/script_#{2 + 7}" }
|
||||
#
|
||||
#
|
||||
# is compiled to:
|
||||
#
|
||||
#
|
||||
# <head name="doc_head">
|
||||
# <script src='javascripts/script_9' type='text/javascript'>
|
||||
# </script>
|
||||
|
@ -200,7 +200,7 @@ $LOAD_PATH << dir unless $LOAD_PATH.include?(dir)
|
|||
#
|
||||
# In XHTML, the only valid value for these attributes is the name of the attribute.
|
||||
# Thus this will render in XHTML as
|
||||
#
|
||||
#
|
||||
# <input selected="selected">
|
||||
#
|
||||
# To set these attributes to false, simply assign them to a Ruby false value.
|
||||
|
@ -211,9 +211,9 @@ $LOAD_PATH << dir unless $LOAD_PATH.include?(dir)
|
|||
# will just render as
|
||||
#
|
||||
# <input>
|
||||
#
|
||||
#
|
||||
# ==== []
|
||||
#
|
||||
#
|
||||
# Square brackets follow a tag definition and contain a Ruby object
|
||||
# that is used to set the class and id of that tag.
|
||||
# The class is set to the object's class
|
||||
|
@ -222,40 +222,40 @@ $LOAD_PATH << dir unless $LOAD_PATH.include?(dir)
|
|||
# Because the id of an object is normally an obscure implementation detail,
|
||||
# this is most useful for elements that represent instances of Models.
|
||||
# For example:
|
||||
#
|
||||
#
|
||||
# # file: app/controllers/users_controller.rb
|
||||
#
|
||||
#
|
||||
# def show
|
||||
# @user = CrazyUser.find(15)
|
||||
# end
|
||||
#
|
||||
#
|
||||
# -# file: app/views/users/show.haml
|
||||
#
|
||||
#
|
||||
# %div[@user]
|
||||
# %bar[290]/
|
||||
# Hello!
|
||||
#
|
||||
#
|
||||
# is compiled to:
|
||||
#
|
||||
#
|
||||
# <div class="crazy_user" id="crazy_user_15">
|
||||
# <bar class="fixnum" id="fixnum_581" />
|
||||
# Hello!
|
||||
# </div>
|
||||
#
|
||||
#
|
||||
# This is based off of DHH's SimplyHelpful syntax,
|
||||
# as presented at RailsConf Europe 2006.
|
||||
#
|
||||
#
|
||||
# ==== /
|
||||
#
|
||||
#
|
||||
# The forward slash character, when placed at the end of a tag definition,
|
||||
# causes the tag to be self-closed.
|
||||
# For example:
|
||||
#
|
||||
#
|
||||
# %br/
|
||||
# %meta{'http-equiv' => 'Content-Type', :content => 'text/html'}/
|
||||
#
|
||||
#
|
||||
# is compiled to:
|
||||
#
|
||||
#
|
||||
# <br />
|
||||
# <meta http-equiv='Content-Type' content='text/html' />
|
||||
#
|
||||
|
@ -271,9 +271,9 @@ $LOAD_PATH << dir unless $LOAD_PATH.include?(dir)
|
|||
#
|
||||
# <br />
|
||||
# <meta http-equiv='Content-Type' content='text/html' />
|
||||
#
|
||||
#
|
||||
# ==== . and #
|
||||
#
|
||||
#
|
||||
# The period and pound sign are borrowed from CSS.
|
||||
# They are used as shortcuts to specify the <tt>class</tt>
|
||||
# and <tt>id</tt> attributes of an element, respectively.
|
||||
|
@ -281,22 +281,22 @@ $LOAD_PATH << dir unless $LOAD_PATH.include?(dir)
|
|||
# by chaining the class names together with periods.
|
||||
# They are placed immediately after the tag and before an attributes hash.
|
||||
# For example:
|
||||
#
|
||||
#
|
||||
# %div#things
|
||||
# %span#rice Chicken Fried
|
||||
# %p.beans{ :food => 'true' } The magical fruit
|
||||
# %h1.class.otherclass#id La La La
|
||||
#
|
||||
#
|
||||
# is compiled to:
|
||||
#
|
||||
#
|
||||
# <div id='things'>
|
||||
# <span id='rice'>Chicken Fried</span>
|
||||
# <p class='beans' food='true'>The magical fruit</p>
|
||||
# <h1 class='class otherclass' id='id'>La La La</h1>
|
||||
# </div>
|
||||
#
|
||||
#
|
||||
# And,
|
||||
#
|
||||
#
|
||||
# #content
|
||||
# .articles
|
||||
# .article.title
|
||||
|
@ -305,9 +305,9 @@ $LOAD_PATH << dir unless $LOAD_PATH.include?(dir)
|
|||
# 2006-11-05
|
||||
# .article.entry
|
||||
# Neil Patrick Harris would like to dispel any rumors that he is straight
|
||||
#
|
||||
#
|
||||
# is compiled to:
|
||||
#
|
||||
#
|
||||
# <div id="content">
|
||||
# <div class="articles">
|
||||
# <div class="article title">Doogie Howser Comes Out</div>
|
||||
|
@ -317,34 +317,34 @@ $LOAD_PATH << dir unless $LOAD_PATH.include?(dir)
|
|||
# </div>
|
||||
# </div>
|
||||
# </div>
|
||||
#
|
||||
#
|
||||
# ==== Implicit Div Elements
|
||||
#
|
||||
#
|
||||
# Because the div element is used so often, it is the default element.
|
||||
# If you only define a class and/or id using the <tt>.</tt> or <tt>#</tt> syntax,
|
||||
# a div element is automatically used.
|
||||
# For example:
|
||||
#
|
||||
#
|
||||
# #collection
|
||||
# .item
|
||||
# .description What a cool item!
|
||||
#
|
||||
#
|
||||
# is the same as:
|
||||
#
|
||||
#
|
||||
# %div{:id => collection}
|
||||
# %div{:class => 'item'}
|
||||
# %div{:class => 'description'} What a cool item!
|
||||
#
|
||||
#
|
||||
# and is compiled to:
|
||||
#
|
||||
#
|
||||
# <div id='collection'>
|
||||
# <div class='item'>
|
||||
# <div class='description'>What a cool item!</div>
|
||||
# </div>
|
||||
# </div>
|
||||
#
|
||||
#
|
||||
# ==== =
|
||||
#
|
||||
#
|
||||
# <tt>=</tt> is placed at the end of a tag definition,
|
||||
# after class, id, and attribute declarations.
|
||||
# It's just a shortcut for inserting Ruby code into an element.
|
||||
|
@ -353,45 +353,45 @@ $LOAD_PATH << dir unless $LOAD_PATH.include?(dir)
|
|||
# However, if the result is short enough,
|
||||
# it is displayed entirely on one line.
|
||||
# For example:
|
||||
#
|
||||
#
|
||||
# %p= "hello"
|
||||
#
|
||||
#
|
||||
# is not quite the same as:
|
||||
#
|
||||
#
|
||||
# %p
|
||||
# = "hello"
|
||||
#
|
||||
#
|
||||
# It's compiled to:
|
||||
#
|
||||
#
|
||||
# <p>hello</p>
|
||||
#
|
||||
#
|
||||
# === XHTML Helpers
|
||||
#
|
||||
#
|
||||
# ==== No Special Character
|
||||
#
|
||||
#
|
||||
# If no special character appears at the beginning of a line,
|
||||
# the line is rendered as plain text.
|
||||
# For example:
|
||||
#
|
||||
#
|
||||
# %gee
|
||||
# %whiz
|
||||
# Wow this is cool!
|
||||
#
|
||||
#
|
||||
# is compiled to:
|
||||
#
|
||||
#
|
||||
# <gee>
|
||||
# <whiz>
|
||||
# Wow this is cool!
|
||||
# </whiz>
|
||||
# </gee>
|
||||
#
|
||||
#
|
||||
# ==== !!!
|
||||
#
|
||||
#
|
||||
# When describing XHTML documents with Haml,
|
||||
# you can have a document type or XML prolog generated automatically
|
||||
# by including the characters <tt>!!!</tt>.
|
||||
# For example:
|
||||
#
|
||||
#
|
||||
# !!! XML
|
||||
# !!!
|
||||
# %html
|
||||
|
@ -400,9 +400,9 @@ $LOAD_PATH << dir unless $LOAD_PATH.include?(dir)
|
|||
# %body
|
||||
# %h1 I am the international space station
|
||||
# %p Sign my guestbook
|
||||
#
|
||||
#
|
||||
# is compiled to:
|
||||
#
|
||||
#
|
||||
# <?xml version="1.0" encoding="utf-8" ?>
|
||||
# <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
# <html>
|
||||
|
@ -414,112 +414,112 @@ $LOAD_PATH << dir unless $LOAD_PATH.include?(dir)
|
|||
# <p>Sign my guestbook</p>
|
||||
# </body>
|
||||
# </html>
|
||||
#
|
||||
#
|
||||
# You can also specify the version and type of XHTML after the <tt>!!!</tt>.
|
||||
# XHTML 1.0 Strict, Transitional, and Frameset and XHTML 1.1 are supported.
|
||||
# The default version is 1.0 and the default type is Transitional.
|
||||
# For example:
|
||||
#
|
||||
#
|
||||
# !!! 1.1
|
||||
#
|
||||
#
|
||||
# is compiled to:
|
||||
#
|
||||
#
|
||||
# <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
|
||||
#
|
||||
#
|
||||
# and
|
||||
#
|
||||
#
|
||||
# !!! Strict
|
||||
#
|
||||
#
|
||||
# is compiled to:
|
||||
#
|
||||
#
|
||||
# <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
#
|
||||
#
|
||||
# If you're not using the UTF-8 character set for your document,
|
||||
# you can specify which encoding should appear
|
||||
# in the XML prolog in a similar way.
|
||||
# For example:
|
||||
#
|
||||
#
|
||||
# !!! XML iso-8859-1
|
||||
#
|
||||
#
|
||||
# is compiled to:
|
||||
#
|
||||
#
|
||||
# <?xml version="1.0" encoding="iso-8859-1" ?>
|
||||
#
|
||||
#
|
||||
# ==== /
|
||||
#
|
||||
#
|
||||
# The forward slash character, when placed at the beginning of a line,
|
||||
# wraps all text after it in an HTML comment.
|
||||
# For example:
|
||||
#
|
||||
#
|
||||
# %peanutbutterjelly
|
||||
# / This is the peanutbutterjelly element
|
||||
# I like sandwiches!
|
||||
#
|
||||
#
|
||||
# is compiled to:
|
||||
#
|
||||
#
|
||||
# <peanutbutterjelly>
|
||||
# <!-- This is the peanutbutterjelly element -->
|
||||
# I like sandwiches!
|
||||
# </peanutbutterjelly>
|
||||
#
|
||||
#
|
||||
# The forward slash can also wrap indented sections of code. For example:
|
||||
#
|
||||
#
|
||||
# /
|
||||
# %p This doesn't render...
|
||||
# %div
|
||||
# %h1 Because it's commented out!
|
||||
#
|
||||
#
|
||||
# is compiled to:
|
||||
#
|
||||
#
|
||||
# <!--
|
||||
# <p>This doesn't render...</p>
|
||||
# <div>
|
||||
# <h1>Because it's commented out!</h1>
|
||||
# </div>
|
||||
# -->
|
||||
#
|
||||
#
|
||||
# You can also use Internet Explorer conditional comments
|
||||
# (about)[http://www.quirksmode.org/css/condcom.html]
|
||||
# by enclosing the condition in square brackets after the <tt>/</tt>.
|
||||
# For example:
|
||||
#
|
||||
#
|
||||
# /[if IE]
|
||||
# %a{ :href => 'http://www.mozilla.com/en-US/firefox/' }
|
||||
# %h1 Get Firefox
|
||||
#
|
||||
#
|
||||
# is compiled to:
|
||||
#
|
||||
#
|
||||
# <!--[if IE]>
|
||||
# <a href='http://www.mozilla.com/en-US/firefox/'>
|
||||
# <h1>Get Firefox</h1>
|
||||
# </a>
|
||||
# <![endif]-->
|
||||
#
|
||||
#
|
||||
# ==== \
|
||||
#
|
||||
#
|
||||
# The backslash character escapes the first character of a line,
|
||||
# allowing use of otherwise interpreted characters as plain text.
|
||||
# For example:
|
||||
#
|
||||
#
|
||||
# %title
|
||||
# = @title
|
||||
# \- MySite
|
||||
#
|
||||
#
|
||||
# is compiled to:
|
||||
#
|
||||
#
|
||||
# <title>
|
||||
# MyPage
|
||||
# - MySite
|
||||
# </title>
|
||||
#
|
||||
#
|
||||
# ==== |
|
||||
#
|
||||
#
|
||||
# The pipe character designates a multiline string.
|
||||
# It's placed at the end of a line
|
||||
# and means that all following lines that end with <tt>|</tt>
|
||||
# will be evaluated as though they were on the same line.
|
||||
# For example:
|
||||
#
|
||||
#
|
||||
# %whoo
|
||||
# %hoo I think this might get |
|
||||
# pretty long so I should |
|
||||
|
@ -527,9 +527,9 @@ $LOAD_PATH << dir unless $LOAD_PATH.include?(dir)
|
|||
# multiline so it doesn't |
|
||||
# look awful. |
|
||||
# %p This is short.
|
||||
#
|
||||
#
|
||||
# is compiled to:
|
||||
#
|
||||
#
|
||||
# <whoo>
|
||||
# <hoo>
|
||||
# I think this might get pretty long so I should probably make it multiline so it doesn't look awful.
|
||||
|
@ -613,21 +613,21 @@ $LOAD_PATH << dir unless $LOAD_PATH.include?(dir)
|
|||
# (BlueCloth takes precedence if both are installed).
|
||||
#
|
||||
# You can also define your own filters (see Setting Options, below).
|
||||
#
|
||||
#
|
||||
# === Ruby evaluators
|
||||
#
|
||||
#
|
||||
# ==== =
|
||||
#
|
||||
#
|
||||
# The equals character is followed by Ruby code,
|
||||
# which is evaluated and the output inserted into the document as plain text.
|
||||
# For example:
|
||||
#
|
||||
#
|
||||
# %p
|
||||
# = ['hi', 'there', 'reader!'].join " "
|
||||
# = "yo"
|
||||
#
|
||||
#
|
||||
# is compiled to:
|
||||
#
|
||||
#
|
||||
# <p>
|
||||
# hi there reader!
|
||||
# yo
|
||||
|
@ -642,29 +642,29 @@ $LOAD_PATH << dir unless $LOAD_PATH.include?(dir)
|
|||
# would be compiled to
|
||||
#
|
||||
# <script>alert("I'm evil!");</script>
|
||||
#
|
||||
#
|
||||
# ==== -
|
||||
#
|
||||
#
|
||||
# The hyphen character makes the text following it into "silent script":
|
||||
# Ruby script that is evaluated, but not output.
|
||||
#
|
||||
#
|
||||
# <b>It is not recommended that you use this widely;
|
||||
# almost all processing code and logic should be restricted
|
||||
# to the Controller, the Helper, or partials.</b>
|
||||
#
|
||||
#
|
||||
# For example:
|
||||
#
|
||||
#
|
||||
# - foo = "hello"
|
||||
# - foo << " there"
|
||||
# - foo << " you!"
|
||||
# %p= foo
|
||||
#
|
||||
#
|
||||
# is compiled to:
|
||||
#
|
||||
#
|
||||
# <p>
|
||||
# hello there you!
|
||||
# </p>
|
||||
#
|
||||
#
|
||||
# ==== ==
|
||||
#
|
||||
# Two equals characters interpolates Ruby code into plain text,
|
||||
|
@ -729,7 +729,7 @@ $LOAD_PATH << dir unless $LOAD_PATH.include?(dir)
|
|||
# I feel <strong>!
|
||||
#
|
||||
# ===== Blocks
|
||||
#
|
||||
#
|
||||
# Ruby blocks, like XHTML tags, don't need to be explicitly closed in Haml.
|
||||
# Rather, they're automatically closed, based on indentation.
|
||||
# A block begins whenever the indentation is increased
|
||||
|
@ -737,13 +737,13 @@ $LOAD_PATH << dir unless $LOAD_PATH.include?(dir)
|
|||
# It ends when the indentation decreases
|
||||
# (as long as it's not an +else+ clause or something similar).
|
||||
# For example:
|
||||
#
|
||||
#
|
||||
# - (42...47).each do |i|
|
||||
# %p= i
|
||||
# %p See, I can count!
|
||||
#
|
||||
#
|
||||
# is compiled to:
|
||||
#
|
||||
#
|
||||
# <p>
|
||||
# 42
|
||||
# </p>
|
||||
|
@ -759,9 +759,9 @@ $LOAD_PATH << dir unless $LOAD_PATH.include?(dir)
|
|||
# <p>
|
||||
# 46
|
||||
# </p>
|
||||
#
|
||||
#
|
||||
# Another example:
|
||||
#
|
||||
#
|
||||
# %p
|
||||
# - case 2
|
||||
# - when 1
|
||||
|
@ -770,9 +770,9 @@ $LOAD_PATH << dir unless $LOAD_PATH.include?(dir)
|
|||
# = "2?"
|
||||
# - when 3
|
||||
# = "3."
|
||||
#
|
||||
#
|
||||
# is compiled to:
|
||||
#
|
||||
#
|
||||
# <p>
|
||||
# 2?
|
||||
# </p>
|
||||
|
@ -783,7 +783,7 @@ $LOAD_PATH << dir unless $LOAD_PATH.include?(dir)
|
|||
# signifies a silent comment.
|
||||
# Any text following this isn't rendered in the resulting document
|
||||
# at all.
|
||||
#
|
||||
#
|
||||
# For example:
|
||||
#
|
||||
# %p foo
|
||||
|
@ -809,7 +809,7 @@ $LOAD_PATH << dir unless $LOAD_PATH.include?(dir)
|
|||
#
|
||||
# <p>foo</p>
|
||||
# <p>bar</p>
|
||||
#
|
||||
#
|
||||
# == Other Useful Things
|
||||
#
|
||||
# === Helpers
|
||||
|
@ -819,9 +819,9 @@ $LOAD_PATH << dir unless $LOAD_PATH.include?(dir)
|
|||
# creating nicely indented output for user-defined helpers,
|
||||
# and other useful things.
|
||||
# The helpers are all documented in the Haml::Helpers and Haml::Helpers::ActionViewExtensions modules.
|
||||
#
|
||||
#
|
||||
# === Haml Options
|
||||
#
|
||||
#
|
||||
# Options can be set by setting the hash <tt>Haml::Template.options</tt>
|
||||
# from <tt>environment.rb</tt> in Rails,
|
||||
# or by passing an options hash to Haml::Engine.
|
||||
|
@ -842,7 +842,7 @@ $LOAD_PATH << dir unless $LOAD_PATH.include?(dir)
|
|||
# designated by <tt>=</tt> or <tt>~</tt> should be
|
||||
# evaluated. If this is true, said scripts are
|
||||
# rendered as empty strings. Defaults to false.
|
||||
#
|
||||
#
|
||||
# [<tt>:attr_wrapper</tt>] The character that should wrap element attributes.
|
||||
# This defaults to <tt>'</tt> (an apostrophe). Characters
|
||||
# of this type within the attributes will be escaped
|
||||
|
|
|
@ -71,7 +71,7 @@ module Haml
|
|||
# Have to push every line in by the extra user set tabulation
|
||||
text.gsub!(/^/m, ' ' * @tabulation)
|
||||
end
|
||||
|
||||
|
||||
@buffer << text
|
||||
@real_tabs += tab_change
|
||||
end
|
||||
|
@ -86,13 +86,13 @@ module Haml
|
|||
elsif preserve_script
|
||||
result = Haml::Helpers.find_and_preserve(result)
|
||||
end
|
||||
|
||||
|
||||
result = result.to_s
|
||||
while result[-1] == ?\n
|
||||
# String#chomp is slow
|
||||
result = result[0...-1]
|
||||
end
|
||||
|
||||
|
||||
result = html_escape(result) if escape_html
|
||||
|
||||
if close_tag && (@options[:ugly] || Buffer.one_liner?(result) || preserve_tag)
|
||||
|
@ -102,10 +102,10 @@ module Haml
|
|||
if close_tag
|
||||
@buffer << "\n"
|
||||
end
|
||||
|
||||
|
||||
result = result.gsub(/^/m, tabs(tabulation)) unless @options[:ugly]
|
||||
@buffer << "#{result}\n"
|
||||
|
||||
|
||||
if close_tag
|
||||
# We never get here if @options[:ugly] is true
|
||||
@buffer << "#{tabs(tabulation-1)}</#{close_tag}>\n"
|
||||
|
@ -119,7 +119,7 @@ module Haml
|
|||
# element, formats it, and adds it to the buffer.
|
||||
def open_tag(name, atomic, try_one_line, preserve_tag, escape_html, class_id, obj_ref, content, *attributes_hashes)
|
||||
tabulation = @real_tabs
|
||||
|
||||
|
||||
attributes = class_id
|
||||
attributes_hashes.each do |attributes_hash|
|
||||
attributes_hash.keys.each { |key| attributes_hash[key.to_s] = attributes_hash.delete(key) }
|
||||
|
|
|
@ -116,7 +116,7 @@ END
|
|||
# If it's a Binding or Proc object,
|
||||
# Haml uses it as the second argument to Kernel#eval;
|
||||
# otherwise, Haml just uses its #instance_eval context.
|
||||
#
|
||||
#
|
||||
# Note that Haml modifies the evaluation context
|
||||
# (either the scope object or the "self" object of the scope binding).
|
||||
# It extends Haml::Helpers, and various instance variables are set
|
||||
|
@ -225,7 +225,7 @@ END
|
|||
#
|
||||
# Haml::Engine.new(".upcased= upcase").def_method(String, :upcased_div)
|
||||
# "foobar".upcased_div #=> "<div class='upcased'>FOOBAR</div>\n"
|
||||
#
|
||||
#
|
||||
# The first argument of the defined method is a hash of local variable names to values.
|
||||
# However, due to an unfortunate Ruby quirk,
|
||||
# the local variables which can be assigned must be pre-declared.
|
||||
|
@ -241,7 +241,7 @@ END
|
|||
# obj = Object.new
|
||||
# Haml::Engine.new("%p= foo").def_method(obj, :render)
|
||||
# obj.render(:foo => "Hello!") #=> NameError: undefined local variable or method `foo'
|
||||
#
|
||||
#
|
||||
# Note that Haml modifies the evaluation context
|
||||
# (either the scope object or the "self" object of the scope binding).
|
||||
# It extends Haml::Helpers, and various instance variables are set
|
||||
|
|
|
@ -21,7 +21,7 @@ module Haml
|
|||
@opts.parse!(@args)
|
||||
|
||||
process_result
|
||||
|
||||
|
||||
@options
|
||||
rescue Exception => e
|
||||
raise e if e.is_a? SystemExit
|
||||
|
@ -45,7 +45,7 @@ module Haml
|
|||
def get_line(exception)
|
||||
exception.backtrace[0].scan(/:(\d+)/)[0]
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
|
||||
def set_opts(opts)
|
||||
|
@ -110,7 +110,7 @@ Description:
|
|||
|
||||
Options:
|
||||
END
|
||||
|
||||
|
||||
opts.on('--rails RAILS_DIR', "Install Haml and Sass from the Gem to a Rails project") do |dir|
|
||||
original_dir = dir
|
||||
|
||||
|
@ -218,7 +218,7 @@ END
|
|||
'Output format. Can be xhtml (default), html4, or html5.') do |name|
|
||||
@options[:for_engine][:format] = name.to_sym
|
||||
end
|
||||
|
||||
|
||||
opts.on('-e', '--escape-html',
|
||||
'Escape HTML characters (like ampersands and angle brackets) by default.') do
|
||||
@options[:for_engine][:escape_html] = true
|
||||
|
|
|
@ -93,7 +93,7 @@ module Haml
|
|||
#
|
||||
# ...
|
||||
# end
|
||||
#
|
||||
#
|
||||
def lazy_require(*reqs)
|
||||
@lazy_requires = reqs
|
||||
end
|
||||
|
@ -110,7 +110,7 @@ module Haml
|
|||
return
|
||||
rescue LoadError; end # RCov doesn't see this, but it is run
|
||||
end
|
||||
|
||||
|
||||
begin
|
||||
@required = @lazy_requires[-1]
|
||||
require @required
|
||||
|
@ -210,7 +210,7 @@ END
|
|||
precompiler.send(:push_silent, src)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
module RedCloth
|
||||
include Base
|
||||
lazy_require 'redcloth'
|
||||
|
@ -219,7 +219,7 @@ END
|
|||
::RedCloth.new(text).to_html
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
# Uses RedCloth to provide only Textile (not Markdown) parsing
|
||||
module Textile
|
||||
include Base
|
||||
|
|
|
@ -35,7 +35,7 @@ module Haml
|
|||
# end
|
||||
# context.init_haml_helpers
|
||||
# context.haml_tag :p, "Stuff"
|
||||
#
|
||||
#
|
||||
def init_haml_helpers
|
||||
@haml_is_haml = true
|
||||
@haml_stack = [Haml::Buffer.new(Haml::Engine.new('').send(:options_for_buffer))]
|
||||
|
@ -45,7 +45,7 @@ module Haml
|
|||
# call-seq:
|
||||
# find_and_preserve(input)
|
||||
# find_and_preserve {...}
|
||||
#
|
||||
#
|
||||
# Isolates the whitespace-sensitive tags in the string and uses preserve
|
||||
# to convert any endlines inside them into HTML entities for endlines.
|
||||
def find_and_preserve(input = '', &block)
|
||||
|
@ -107,14 +107,14 @@ module Haml
|
|||
def list_of(array, &block) # :yields: item
|
||||
to_return = array.collect do |i|
|
||||
result = capture_haml(i, &block)
|
||||
|
||||
|
||||
if result.count("\n") > 1
|
||||
result.gsub!("\n", "\n ")
|
||||
result = "\n #{result.strip}\n"
|
||||
else
|
||||
result.strip!
|
||||
end
|
||||
|
||||
|
||||
"<li>#{result}</li>"
|
||||
end
|
||||
to_return.join("\n")
|
||||
|
@ -163,7 +163,7 @@ module Haml
|
|||
def tab_down(i = 1)
|
||||
haml_buffer.tabulation -= i
|
||||
end
|
||||
|
||||
|
||||
# Surrounds the given block of Haml code with the given characters,
|
||||
# with no whitespace in between.
|
||||
# For example:
|
||||
|
@ -187,10 +187,10 @@ module Haml
|
|||
def surround(front, back = nil, &block)
|
||||
back ||= front
|
||||
output = capture_haml(&block)
|
||||
|
||||
|
||||
"#{front}#{output.chomp}#{back}\n"
|
||||
end
|
||||
|
||||
|
||||
# Prepends the given character to the beginning of the Haml block,
|
||||
# with no whitespace between.
|
||||
# For example:
|
||||
|
@ -205,7 +205,7 @@ module Haml
|
|||
def precede(char, &block)
|
||||
"#{char}#{capture_haml(&block).chomp}\n"
|
||||
end
|
||||
|
||||
|
||||
# Appends the given character to the end of the Haml block,
|
||||
# with no whitespace between.
|
||||
# For example:
|
||||
|
@ -222,7 +222,7 @@ module Haml
|
|||
def succeed(char, &block)
|
||||
"#{capture_haml(&block).chomp}#{char}\n"
|
||||
end
|
||||
|
||||
|
||||
# Captures the result of the given block of Haml code,
|
||||
# gets rid of the excess indentation,
|
||||
# and returns it as a string.
|
||||
|
@ -254,7 +254,7 @@ module Haml
|
|||
# between when the opening and closing tags are output.
|
||||
# If the block is a Haml block or outputs text using puts,
|
||||
# the text will be properly indented.
|
||||
#
|
||||
#
|
||||
# For example,
|
||||
#
|
||||
# haml_tag :table do
|
||||
|
@ -331,7 +331,7 @@ END
|
|||
def html_escape(text)
|
||||
text.to_s.gsub(/[><&]/) { |s| HTML_ESCAPE[s] }
|
||||
end
|
||||
|
||||
|
||||
# Escapes HTML entities in <tt>text</tt>, but without escaping an ampersand
|
||||
# that is already part of an escaped entity.
|
||||
def escape_once(text)
|
||||
|
@ -344,7 +344,7 @@ END
|
|||
def haml_buffer
|
||||
@haml_stack[-1]
|
||||
end
|
||||
|
||||
|
||||
# Gives a proc the same local "_hamlout" and "_erbout" variables
|
||||
# that the current template has.
|
||||
def haml_bind_proc(&proc)
|
||||
|
@ -352,23 +352,23 @@ END
|
|||
_erbout = _hamlout.buffer
|
||||
proc { |*args| proc.call(*args) }
|
||||
end
|
||||
|
||||
|
||||
# Performs the function of capture_haml, assuming <tt>local_buffer</tt>
|
||||
# is where the output of block goes.
|
||||
def capture_haml_with_buffer(local_buffer, *args, &block)
|
||||
position = local_buffer.length
|
||||
|
||||
|
||||
block.call *args
|
||||
|
||||
|
||||
captured = local_buffer.slice!(position..-1)
|
||||
|
||||
|
||||
min_tabs = nil
|
||||
captured.each do |line|
|
||||
tabs = line.index(/[^ ]/)
|
||||
min_tabs ||= tabs
|
||||
min_tabs = min_tabs > tabs ? tabs : min_tabs
|
||||
end
|
||||
|
||||
|
||||
result = captured.map do |line|
|
||||
line[min_tabs..-1]
|
||||
end
|
||||
|
@ -376,7 +376,7 @@ END
|
|||
end
|
||||
|
||||
# Returns whether or not the current template is a Haml template.
|
||||
#
|
||||
#
|
||||
# This function, unlike other Haml::Helpers functions,
|
||||
# also works in other ActionView templates,
|
||||
# where it will always return false.
|
||||
|
|
|
@ -31,7 +31,7 @@ if defined?(ActionView)
|
|||
#
|
||||
# .entry
|
||||
# :color #00f
|
||||
#
|
||||
#
|
||||
def page_class
|
||||
controller.controller_name + " " + controller.action_name
|
||||
end
|
||||
|
|
|
@ -50,7 +50,7 @@ if defined?(ActionView) and not defined?(Merb::Plugins)
|
|||
alias_method :concat, :concat_with_haml
|
||||
end
|
||||
|
||||
module TagHelper
|
||||
module TagHelper
|
||||
def content_tag_with_haml(name, *args, &block)
|
||||
content = content_tag_without_haml(name, *args, &block)
|
||||
|
||||
|
@ -105,7 +105,7 @@ if defined?(ActionView) and not defined?(Merb::Plugins)
|
|||
module FormHelper
|
||||
def form_for_with_haml(object_name, *args, &proc)
|
||||
if block_given? && is_haml?
|
||||
oldproc = proc
|
||||
oldproc = proc
|
||||
proc = haml_bind_proc do |*args|
|
||||
tab_up
|
||||
oldproc.call(*args)
|
||||
|
|
|
@ -59,7 +59,7 @@ module Haml
|
|||
String.new
|
||||
else
|
||||
lines = text.split("\n")
|
||||
|
||||
|
||||
lines.map do |line|
|
||||
line.strip!
|
||||
"#{tabulate(tabs)}#{'\\' if Haml::Engine::SPECIAL_CHARACTERS.include?(line[0])}#{line}\n"
|
||||
|
@ -73,7 +73,7 @@ module Haml
|
|||
def self.options
|
||||
@@options
|
||||
end
|
||||
|
||||
|
||||
TEXT_REGEXP = /^(\s*).*$/
|
||||
|
||||
class ::Hpricot::Doc
|
||||
|
@ -129,14 +129,14 @@ module Haml
|
|||
|
||||
class ::Hpricot::Elem
|
||||
def to_haml(tabs = 0)
|
||||
output = "#{tabulate(tabs)}"
|
||||
output = "#{tabulate(tabs)}"
|
||||
if HTML.options[:rhtml] && name[0...5] == 'haml:'
|
||||
return output + HTML.send("haml_tag_#{name[5..-1]}",
|
||||
CGI.unescapeHTML(self.innerHTML))
|
||||
end
|
||||
|
||||
output += "%#{name}" unless name == 'div' && (attributes.include?('id') || attributes.include?('class'))
|
||||
|
||||
|
||||
if attributes
|
||||
output += "##{attributes['id']}" if attributes['id']
|
||||
attributes['class'].split(' ').each { |c| output += ".#{c}" } if attributes['class']
|
||||
|
@ -144,10 +144,10 @@ module Haml
|
|||
remove_attribute('class')
|
||||
output += haml_attributes if attributes.length > 0
|
||||
end
|
||||
|
||||
|
||||
output += "/" if children.length == 0
|
||||
output += "\n"
|
||||
|
||||
|
||||
self.children.each do |child|
|
||||
output += child.to_haml(tabs + 1)
|
||||
end
|
||||
|
|
|
@ -180,7 +180,7 @@ END
|
|||
close until @to_close_stack.empty?
|
||||
flush_merged_text
|
||||
end
|
||||
|
||||
|
||||
# Processes and deals with lowering indentation.
|
||||
def process_indent(line)
|
||||
return unless line.tabs <= @template_tabs && @template_tabs > 0
|
||||
|
@ -228,7 +228,7 @@ END
|
|||
else push_plain text
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
# Returns whether or not the text is a silent script text with one
|
||||
# of Ruby's mid-block keywords.
|
||||
def mid_block_keyword?(text)
|
||||
|
@ -248,7 +248,7 @@ END
|
|||
@multiline.text << text[0...-1]
|
||||
return true
|
||||
end
|
||||
|
||||
|
||||
# A multiline string has just been activated, start adding the lines
|
||||
if is_multiline?(text) && (MULTILINE_STARTERS.include? text[0])
|
||||
@multiline = Line.new text[0...-1], nil, line.index, nil, line.tabs
|
||||
|
@ -273,7 +273,7 @@ END
|
|||
# Evaluates <tt>text</tt> in the context of the scope object, but
|
||||
# does not output the result.
|
||||
def push_silent(text, can_suppress = false)
|
||||
flush_merged_text
|
||||
flush_merged_text
|
||||
return if can_suppress && options[:suppress_eval]
|
||||
@precompiled << "#{text};"
|
||||
end
|
||||
|
@ -291,11 +291,11 @@ END
|
|||
@merged_text << text
|
||||
@try_one_liner = false
|
||||
end
|
||||
|
||||
|
||||
def push_text(text, tab_change = 0, try_one_liner = false)
|
||||
push_merged_text("#{text}\n", tab_change, try_one_liner)
|
||||
end
|
||||
|
||||
|
||||
def flush_merged_text
|
||||
return if @merged_text.empty?
|
||||
|
||||
|
@ -305,7 +305,7 @@ END
|
|||
@merged_text = ''
|
||||
@tab_change = 0
|
||||
@try_one_liner = false
|
||||
end
|
||||
end
|
||||
|
||||
# Renders a block of text as plain text.
|
||||
# Also checks for an illegally opened block.
|
||||
|
@ -343,12 +343,12 @@ END
|
|||
@precompiled << out
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
# Causes <tt>text</tt> to be evaluated, and Haml::Helpers#find_and_flatten
|
||||
# to be run on it afterwards.
|
||||
def push_flat_script(text)
|
||||
flush_merged_text
|
||||
|
||||
|
||||
raise SyntaxError.new("Tag has no content.") if text.empty?
|
||||
push_script(text, true)
|
||||
end
|
||||
|
@ -394,7 +394,7 @@ END
|
|||
close_tag = has_conditional ? "<![endif]-->" : "-->"
|
||||
push_text(close_tag, -1)
|
||||
end
|
||||
|
||||
|
||||
# Closes a loud Ruby block.
|
||||
def close_loud(command)
|
||||
push_silent 'end', true
|
||||
|
@ -414,7 +414,7 @@ END
|
|||
@haml_comment = false
|
||||
@template_tabs -= 1
|
||||
end
|
||||
|
||||
|
||||
# Iterates through the classes and ids supplied through <tt>.</tt>
|
||||
# and <tt>#</tt> syntax, and returns a hash with them as attributes,
|
||||
# that can then be merged with another attributes hash.
|
||||
|
@ -443,8 +443,8 @@ END
|
|||
# $5 holds the value matched by a string
|
||||
$2 || $5
|
||||
end
|
||||
|
||||
def parse_static_hash(text)
|
||||
|
||||
def parse_static_hash(text)
|
||||
return {} unless text
|
||||
|
||||
attributes = {}
|
||||
|
@ -466,7 +466,7 @@ END
|
|||
def self.build_attributes(is_html, attr_wrapper, attributes = {})
|
||||
quote_escape = attr_wrapper == '"' ? """ : "'"
|
||||
other_quote_char = attr_wrapper == '"' ? "'" : '"'
|
||||
|
||||
|
||||
result = attributes.collect do |attr, value|
|
||||
next if value.nil?
|
||||
|
||||
|
@ -495,7 +495,7 @@ END
|
|||
attributes_string = Precompiler.build_attributes(html?, @options[:attr_wrapper], attributes)
|
||||
"<#{name}#{attributes_string}#{self_close && xhtml? ? ' /' : ''}>"
|
||||
end
|
||||
|
||||
|
||||
# Parses a line into tag_name, attributes, attributes_hash, object_ref, action, value
|
||||
def parse_tag(line)
|
||||
raise SyntaxError.new("Invalid tag: \"#{line}\"") unless match = line.scan(/[%]([-:\w]+)([-\w\.\#]*)(.*)/)[0]
|
||||
|
@ -517,7 +517,7 @@ END
|
|||
# render that tag to <tt>@precompiled</tt>.
|
||||
def render_tag(line)
|
||||
tag_name, attributes, attributes_hash, object_ref, action, value = parse_tag(line)
|
||||
|
||||
|
||||
raise SyntaxError.new("Illegal element: classes and ids must have values.") if attributes =~ /[\.#](\.|#|\z)/
|
||||
|
||||
preserve_tag = options[:preserve].include?(tag_name)
|
||||
|
@ -581,7 +581,7 @@ END
|
|||
@output_tabs += 1
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
if parse
|
||||
flush_merged_text
|
||||
push_script(value, preserve_script, tag_name, preserve_tag, escape_html)
|
||||
|
@ -599,13 +599,13 @@ END
|
|||
conditional, content = line.scan(COMMENT_REGEX)[0]
|
||||
content.strip!
|
||||
conditional << ">" if conditional
|
||||
|
||||
|
||||
if @block_opened && !content.empty?
|
||||
raise SyntaxError.new('Illegal Nesting: Nesting within a tag that already has content is illegal.')
|
||||
end
|
||||
|
||||
open = "<!--#{conditional} "
|
||||
|
||||
|
||||
# Render it statically if possible
|
||||
if !content.empty? && Buffer.one_liner?(content)
|
||||
return push_text("#{open}#{content} #{conditional ? "<![endif]-->" : "-->"}")
|
||||
|
@ -619,7 +619,7 @@ END
|
|||
close
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
# Renders an XHTML doctype or XML shebang.
|
||||
def render_doctype(line)
|
||||
raise SyntaxError.new("Illegal Nesting: Nesting within a header command is illegal.") if @block_opened
|
||||
|
@ -639,7 +639,7 @@ END
|
|||
'<!DOCTYPE html>'
|
||||
else
|
||||
version, type = text.scan(DOCTYPE_REGEX)[0]
|
||||
|
||||
|
||||
if xhtml?
|
||||
if version == "1.1"
|
||||
'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">'
|
||||
|
@ -660,7 +660,7 @@ END
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
# Starts a filtered block.
|
||||
def start_filtered(name)
|
||||
raise SyntaxError.new('Filters must have nested text.') unless @block_opened
|
||||
|
@ -723,7 +723,7 @@ END
|
|||
end
|
||||
[spaces, spaces/2]
|
||||
end
|
||||
|
||||
|
||||
# Pushes value onto <tt>@to_close_stack</tt> and increases
|
||||
# <tt>@template_tabs</tt>.
|
||||
def push_and_tabulate(value)
|
||||
|
|
|
@ -26,7 +26,7 @@ module ActionView
|
|||
def compile_haml(template, file_name, local_assigns)
|
||||
render_symbol = assign_method_name(:haml, template, file_name)
|
||||
locals = local_assigns.keys
|
||||
|
||||
|
||||
@@template_args[render_symbol] ||= {}
|
||||
locals_keys = @@template_args[render_symbol].keys | locals
|
||||
@@template_args[render_symbol] = locals_keys.inject({}) { |h, k| h[k] = true; h }
|
||||
|
|
|
@ -13,7 +13,7 @@ module Haml
|
|||
def compilable?
|
||||
true
|
||||
end
|
||||
|
||||
|
||||
def line_offset
|
||||
self.class.line_offset
|
||||
end
|
||||
|
@ -26,13 +26,13 @@ module Haml
|
|||
options = Haml::Template.options.dup
|
||||
Haml::Engine.new(template, options).send(:precompiled_with_ambles, [])
|
||||
end
|
||||
|
||||
|
||||
def cache_fragment(block, name = {}, options = nil)
|
||||
@view.fragment_for(block, name, options) do
|
||||
eval("_hamlout.buffer", block.binding)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def read_template_file(template_path, extension)
|
||||
File.read(template_path)
|
||||
end
|
||||
|
|
20
lib/sass.rb
20
lib/sass.rb
|
@ -11,7 +11,7 @@ $LOAD_PATH << dir unless $LOAD_PATH.include?(dir)
|
|||
# and implements various features that are useful
|
||||
# for creating manageable stylesheets.
|
||||
#
|
||||
# == Features
|
||||
# == Features
|
||||
#
|
||||
# * Whitespace active
|
||||
# * Well-formatted output
|
||||
|
@ -32,9 +32,9 @@ $LOAD_PATH << dir unless $LOAD_PATH.include?(dir)
|
|||
#
|
||||
# To enable it as a Rails plugin,
|
||||
# then run
|
||||
#
|
||||
#
|
||||
# haml --rails path/to/rails/app
|
||||
#
|
||||
#
|
||||
# To enable Sass in Merb,
|
||||
# add
|
||||
#
|
||||
|
@ -157,12 +157,12 @@ $LOAD_PATH << dir unless $LOAD_PATH.include?(dir)
|
|||
#
|
||||
# #main
|
||||
# :width 97%
|
||||
#
|
||||
#
|
||||
# p, div
|
||||
# :font-size 2em
|
||||
# a
|
||||
# :font-weight bold
|
||||
#
|
||||
#
|
||||
# pre
|
||||
# :font-size 3em
|
||||
#
|
||||
|
@ -668,7 +668,7 @@ $LOAD_PATH << dir unless $LOAD_PATH.include?(dir)
|
|||
# #main { color: #fff; background-color: #000; }
|
||||
# #main p { width: 10em; }
|
||||
#
|
||||
# .huge { font-size: 10em; font-weight: bold; text-decoration: underline; }
|
||||
# .huge { font-size: 10em; font-weight: bold; text-decoration: underline; }
|
||||
#
|
||||
# === <tt>:compressed</tt>
|
||||
#
|
||||
|
@ -678,7 +678,7 @@ $LOAD_PATH << dir unless $LOAD_PATH.include?(dir)
|
|||
# It's not meant to be human-readable.
|
||||
# For example:
|
||||
#
|
||||
# #main{color:#fff;background-color:#000}#main p{width:10em}.huge{font-size:10em;font-weight:bold;text-decoration:underline}
|
||||
# #main{color:#fff;background-color:#000}#main p{width:10em}.huge{font-size:10em;font-weight:bold;text-decoration:underline}
|
||||
#
|
||||
# == Sass Options
|
||||
#
|
||||
|
@ -701,7 +701,7 @@ $LOAD_PATH << dir unless $LOAD_PATH.include?(dir)
|
|||
# For example: <tt>color: #0f3</tt>
|
||||
# or <tt>width = !main_width</tt>.
|
||||
# By default, either syntax is valid.
|
||||
#
|
||||
#
|
||||
# [<tt>:never_update</tt>] Whether the CSS files should never be updated,
|
||||
# even if the template file changes.
|
||||
# Setting this to true may give small performance gains.
|
||||
|
@ -713,7 +713,7 @@ $LOAD_PATH << dir unless $LOAD_PATH.include?(dir)
|
|||
# as opposed to only when the template has been modified.
|
||||
# Defaults to false.
|
||||
# Only has meaning within Ruby on Rails or Merb.
|
||||
#
|
||||
#
|
||||
# [<tt>:always_check</tt>] Whether a Sass template should be checked for updates every
|
||||
# time a controller is accessed,
|
||||
# as opposed to only when the Rails server starts.
|
||||
|
@ -748,7 +748,7 @@ $LOAD_PATH << dir unless $LOAD_PATH.include?(dir)
|
|||
# for Sass templates imported with the "@import" directive.
|
||||
# This defaults to the working directory and, in Rails or Merb,
|
||||
# whatever <tt>:template_location</tt> is.
|
||||
#
|
||||
#
|
||||
module Sass; end
|
||||
|
||||
require 'sass/engine'
|
||||
|
|
|
@ -8,13 +8,13 @@ module Sass
|
|||
|
||||
# Whitespace characters
|
||||
WHITESPACE = [?\ , ?\t, ?\n, ?\r]
|
||||
|
||||
|
||||
# The character used to escape values
|
||||
ESCAPE_CHAR = ?\\
|
||||
|
||||
# The character used to open and close strings
|
||||
STRING_CHAR = ?"
|
||||
|
||||
|
||||
# A mapping of syntactically-significant characters
|
||||
# to parsed symbols
|
||||
SYMBOLS = {
|
||||
|
@ -32,13 +32,13 @@ module Sass
|
|||
|
||||
# The regular expression used to parse constants
|
||||
MATCH = /^#{Regexp.escape(CONSTANT_CHAR.chr)}([^\s#{(SYMBOLS.keys + [ ?= ]).map {|c| Regexp.escape("#{c.chr}") }.join}]+)\s*((?:\|\|)?=)\s*(.+)/
|
||||
|
||||
|
||||
# First-order operations
|
||||
FIRST_ORDER = [:times, :div, :mod]
|
||||
|
||||
|
||||
# Second-order operations
|
||||
SECOND_ORDER = [:plus, :minus]
|
||||
|
||||
|
||||
class << self
|
||||
def parse(value, constants, line)
|
||||
begin
|
||||
|
@ -53,21 +53,21 @@ module Sass
|
|||
raise e
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
|
||||
|
||||
def tokenize(value)
|
||||
escaped = false
|
||||
is_string = false
|
||||
beginning_of_token = true
|
||||
str = ''
|
||||
to_return = []
|
||||
|
||||
|
||||
reset_str = Proc.new do
|
||||
to_return << str unless str.empty?
|
||||
''
|
||||
end
|
||||
|
||||
|
||||
value.each_byte do |byte|
|
||||
unless escaped
|
||||
if byte == ESCAPE_CHAR
|
||||
|
@ -97,7 +97,7 @@ module Sass
|
|||
str = reset_str.call
|
||||
next
|
||||
end
|
||||
|
||||
|
||||
symbol = SYMBOLS[byte]
|
||||
|
||||
# Adjacent values without an operator should be concatenated
|
||||
|
@ -135,28 +135,28 @@ module Sass
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
escaped = false
|
||||
beginning_of_token = false
|
||||
str << byte.chr
|
||||
end
|
||||
|
||||
|
||||
if is_string
|
||||
raise Sass::SyntaxError.new("Unterminated string: #{value.dump}")
|
||||
end
|
||||
str = reset_str.call
|
||||
to_return
|
||||
end
|
||||
|
||||
|
||||
def parenthesize(value)
|
||||
parenthesize_helper(0, value, value.length)[0]
|
||||
end
|
||||
|
||||
|
||||
def parenthesize_helper(i, value, value_len, return_after_expr = false)
|
||||
to_return = []
|
||||
beginning = i
|
||||
token = value[i]
|
||||
|
||||
|
||||
while i < value_len && token != :close
|
||||
if token == :open
|
||||
to_return.push(*value[beginning...i])
|
||||
|
@ -194,13 +194,13 @@ module Sass
|
|||
else
|
||||
i += 1
|
||||
end
|
||||
|
||||
|
||||
token = value[i]
|
||||
end
|
||||
to_return.push(*value[beginning...i])
|
||||
return to_return, i + 1
|
||||
end
|
||||
|
||||
|
||||
#--
|
||||
# TODO: Don't pass around original value;
|
||||
# have Constant.parse automatically add it to exception.
|
||||
|
@ -234,7 +234,7 @@ module Sass
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def get_constant(value, constants)
|
||||
to_return = constants[value]
|
||||
raise SyntaxError.new("Undefined constant: \"!#{value}\"") unless to_return
|
||||
|
|
|
@ -21,9 +21,9 @@ module Sass::Constant # :nodoc:
|
|||
'teal' => 0x008080,
|
||||
'aqua' => 0x00ffff
|
||||
}
|
||||
|
||||
|
||||
REGEXP = /\##{"([0-9a-fA-F]{1,2})" * 3}/
|
||||
|
||||
|
||||
def parse(value)
|
||||
if (value =~ REGEXP)
|
||||
@value = value.scan(REGEXP)[0].map { |num| num.ljust(2, num).to_i(16) }
|
||||
|
@ -32,7 +32,7 @@ module Sass::Constant # :nodoc:
|
|||
@value = (0..2).map{ |n| color >> (n << 3) & 0xff }.reverse
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def plus(other)
|
||||
if other.is_a? Sass::Constant::String
|
||||
Sass::Constant::String.from_value(self.to_s + other.to_s)
|
||||
|
@ -40,7 +40,7 @@ module Sass::Constant # :nodoc:
|
|||
piecewise(other, :+)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def minus(other)
|
||||
if other.is_a? Sass::Constant::String
|
||||
raise NoMethodError.new(nil, :minus)
|
||||
|
@ -48,7 +48,7 @@ module Sass::Constant # :nodoc:
|
|||
piecewise(other, :-)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def times(other)
|
||||
if other.is_a? Sass::Constant::String
|
||||
raise NoMethodError.new(nil, :times)
|
||||
|
@ -56,7 +56,7 @@ module Sass::Constant # :nodoc:
|
|||
piecewise(other, :*)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def div(other)
|
||||
if other.is_a? Sass::Constant::String
|
||||
raise NoMethodError.new(nil, :div)
|
||||
|
@ -64,7 +64,7 @@ module Sass::Constant # :nodoc:
|
|||
piecewise(other, :/)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def mod(other)
|
||||
if other.is_a? Sass::Constant::String
|
||||
raise NoMethodError.new(nil, :mod)
|
||||
|
@ -72,24 +72,24 @@ module Sass::Constant # :nodoc:
|
|||
piecewise(other, :%)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def to_s
|
||||
red, green, blue = @value.map { |num| num.to_s(16).rjust(2, '0') }
|
||||
"##{red}#{green}#{blue}"
|
||||
end
|
||||
|
||||
|
||||
protected
|
||||
|
||||
|
||||
def self.filter_value(value)
|
||||
value.map { |num| num.to_i }
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
|
||||
|
||||
def piecewise(other, operation)
|
||||
other_num = other.is_a? Number
|
||||
other_val = other.value
|
||||
|
||||
|
||||
rgb = []
|
||||
for i in (0...3)
|
||||
res = @value[i].send(operation, other_num ? other_val : other_val[i])
|
||||
|
|
|
@ -13,7 +13,7 @@ class Sass::Constant::Literal # :nodoc:
|
|||
|
||||
# The regular expression matching colors.
|
||||
COLOR = /^\# (?: [\da-f]{3} | [\da-f]{6} ) | #{html_color_matcher}/ix
|
||||
|
||||
|
||||
def self.parse(value)
|
||||
case value
|
||||
when NUMBER
|
||||
|
@ -24,11 +24,11 @@ class Sass::Constant::Literal # :nodoc:
|
|||
Sass::Constant::String.new(value)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def initialize(value = nil)
|
||||
self.parse(value) if value
|
||||
end
|
||||
|
||||
|
||||
def perform
|
||||
self
|
||||
end
|
||||
|
@ -36,15 +36,15 @@ class Sass::Constant::Literal # :nodoc:
|
|||
def concat(other)
|
||||
Sass::Constant::String.from_value("#{self.to_s} #{other.to_s}")
|
||||
end
|
||||
|
||||
|
||||
attr_reader :value
|
||||
|
||||
|
||||
protected
|
||||
|
||||
|
||||
def self.filter_value(value)
|
||||
value
|
||||
end
|
||||
|
||||
|
||||
def self.from_value(value)
|
||||
instance = self.new
|
||||
instance.instance_variable_set('@value', self.filter_value(value))
|
||||
|
|
|
@ -10,7 +10,7 @@ module Sass::Constant # :nodoc:
|
|||
@value = first.empty? ? second.to_i : "#{first}#{second}".to_f
|
||||
@unit = unit unless unit.empty?
|
||||
end
|
||||
|
||||
|
||||
def plus(other)
|
||||
if other.is_a? Number
|
||||
operate(other, :+)
|
||||
|
@ -20,7 +20,7 @@ module Sass::Constant # :nodoc:
|
|||
Sass::Constant::String.from_value(self.to_s + other.to_s)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def minus(other)
|
||||
if other.is_a? Number
|
||||
operate(other, :-)
|
||||
|
@ -28,7 +28,7 @@ module Sass::Constant # :nodoc:
|
|||
raise NoMethodError.new(nil, :minus)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def times(other)
|
||||
if other.is_a? Number
|
||||
operate(other, :*)
|
||||
|
@ -38,7 +38,7 @@ module Sass::Constant # :nodoc:
|
|||
raise NoMethodError.new(nil, :times)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def div(other)
|
||||
if other.is_a? Number
|
||||
operate(other, :/)
|
||||
|
@ -46,7 +46,7 @@ module Sass::Constant # :nodoc:
|
|||
raise NoMethodError.new(nil, :div)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def mod(other)
|
||||
if other.is_a? Number
|
||||
operate(other, :%)
|
||||
|
@ -54,13 +54,13 @@ module Sass::Constant # :nodoc:
|
|||
raise NoMethodError.new(nil, :mod)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def to_s
|
||||
value = @value
|
||||
value = value.to_i if value % 1 == 0.0
|
||||
"#{value}#{@unit}"
|
||||
end
|
||||
|
||||
|
||||
protected
|
||||
|
||||
def self.from_value(value, unit=nil)
|
||||
|
@ -68,7 +68,7 @@ module Sass::Constant # :nodoc:
|
|||
instance.instance_variable_set('@unit', unit)
|
||||
instance
|
||||
end
|
||||
|
||||
|
||||
def operate(other, operation)
|
||||
unit = nil
|
||||
if other.unit.nil?
|
||||
|
|
|
@ -9,13 +9,13 @@ module Sass::Constant # :nodoc:
|
|||
@operand2 = operand2
|
||||
@operator = operator
|
||||
end
|
||||
|
||||
|
||||
def to_s
|
||||
self.perform.to_s
|
||||
end
|
||||
|
||||
|
||||
protected
|
||||
|
||||
|
||||
def perform
|
||||
literal1 = @operand1.perform
|
||||
literal2 = @operand2.perform
|
||||
|
|
|
@ -2,11 +2,11 @@ require 'sass/constant/literal'
|
|||
|
||||
module Sass::Constant # :nodoc:
|
||||
class String < Literal # :nodoc:
|
||||
|
||||
|
||||
def parse(value)
|
||||
@value = value
|
||||
end
|
||||
|
||||
|
||||
def plus(other)
|
||||
Sass::Constant::String.from_value(self.to_s + other.to_s)
|
||||
end
|
||||
|
@ -14,7 +14,7 @@ module Sass::Constant # :nodoc:
|
|||
def funcall(other)
|
||||
Sass::Constant::String.from_value("#{self.to_s}(#{other.to_s})")
|
||||
end
|
||||
|
||||
|
||||
def to_s
|
||||
@value
|
||||
end
|
||||
|
|
|
@ -105,7 +105,7 @@ module Sass
|
|||
build_tree.to_sass
|
||||
rescue Exception => err
|
||||
line = @template.string[0...@template.pos].split("\n").size
|
||||
|
||||
|
||||
err.backtrace.unshift "(css):#{line}"
|
||||
raise err
|
||||
end
|
||||
|
@ -164,12 +164,12 @@ module Sass
|
|||
whitespace
|
||||
|
||||
assert_match /:/
|
||||
|
||||
|
||||
value = ''
|
||||
while @template.scan(/[^;\s\}]+/)
|
||||
value << @template[0] << whitespace
|
||||
end
|
||||
|
||||
|
||||
assert_match /(;|(?=\}))/
|
||||
rule << Tree::AttrNode.new(name, value, nil)
|
||||
end
|
||||
|
@ -244,7 +244,7 @@ module Sass
|
|||
# color: red
|
||||
# baz
|
||||
# color: blue
|
||||
#
|
||||
#
|
||||
def nest_rules(root)
|
||||
rules = OrderedHash.new
|
||||
root.children.select { |c| Tree::RuleNode === c }.each do |child|
|
||||
|
@ -274,7 +274,7 @@ module Sass
|
|||
#
|
||||
# foo bar baz
|
||||
# color: red
|
||||
#
|
||||
#
|
||||
def flatten_rules(root)
|
||||
root.children.each { |child| flatten_rule(child) if child.is_a?(Tree::RuleNode) }
|
||||
end
|
||||
|
|
|
@ -39,7 +39,7 @@ module Sass
|
|||
|
||||
# The character used to denote a compiler directive.
|
||||
DIRECTIVE_CHAR = ?@
|
||||
|
||||
|
||||
# Designates a non-parsed rule.
|
||||
ESCAPE_CHAR = ?\\
|
||||
|
||||
|
|
|
@ -15,13 +15,13 @@ unless defined?(Sass::MERB_LOADED)
|
|||
:always_check => env != "production",
|
||||
:full_exception => env != "production")
|
||||
config = Merb::Plugins.config[:sass] || Merb::Plugins.config["sass"] || {}
|
||||
|
||||
|
||||
if defined? config.symbolize_keys!
|
||||
config.symbolize_keys!
|
||||
end
|
||||
|
||||
Sass::Plugin.options.merge!(config)
|
||||
|
||||
|
||||
if version[0] > 0 || version[1] >= 9
|
||||
|
||||
class Merb::Rack::Application # :nodoc:
|
||||
|
|
|
@ -5,7 +5,7 @@ unless defined?(Sass::RAILS_LOADED)
|
|||
:css_location => RAILS_ROOT + '/public/stylesheets',
|
||||
:always_check => RAILS_ENV != "production",
|
||||
:full_exception => RAILS_ENV != "production")
|
||||
|
||||
|
||||
# :stopdoc:
|
||||
module ActionController
|
||||
class Base
|
||||
|
|
|
@ -3,12 +3,12 @@ require 'sass/tree/node'
|
|||
module Sass::Tree
|
||||
class AttrNode < ValueNode
|
||||
attr_accessor :name
|
||||
|
||||
|
||||
def initialize(name, value, style)
|
||||
@name = name
|
||||
super(value, style)
|
||||
end
|
||||
|
||||
|
||||
def to_s(tabs, parent_name = nil)
|
||||
if value[-1] == ?;
|
||||
raise Sass::SyntaxError.new("Invalid attribute: #{declaration.dump} (This isn't CSS!)", @line)
|
||||
|
@ -34,7 +34,7 @@ module Sass::Tree
|
|||
children.each do |kid|
|
||||
to_return << "#{kid.to_s(tabs, real_name)}" << join_string
|
||||
end
|
||||
|
||||
|
||||
(@style == :compressed && parent_name) ? to_return : to_return[0...-1]
|
||||
end
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ module Sass
|
|||
end
|
||||
@children << child
|
||||
end
|
||||
|
||||
|
||||
def to_s
|
||||
result = String.new
|
||||
children.each do |child|
|
||||
|
|
|
@ -21,7 +21,7 @@ module Sass::Tree
|
|||
def continued?
|
||||
rule[-1] == ?,
|
||||
end
|
||||
|
||||
|
||||
def to_s(tabs, super_rules = nil)
|
||||
attributes = []
|
||||
sub_rules = []
|
||||
|
@ -52,7 +52,7 @@ module Sass::Tree
|
|||
per_rule_indent + r.gsub(/,$/, '').gsub(rule_split, rule_separator).rstrip
|
||||
end.join(line_separator)
|
||||
end
|
||||
|
||||
|
||||
children.each do |child|
|
||||
if child.is_a? RuleNode
|
||||
sub_rules << child
|
||||
|
@ -60,7 +60,7 @@ module Sass::Tree
|
|||
attributes << child
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
to_return = ''
|
||||
if !attributes.empty?
|
||||
old_spaces = ' ' * (tabs - 1)
|
||||
|
@ -77,7 +77,7 @@ module Sass::Tree
|
|||
to_return << "#{total_rule} {\n#{attributes}#{end_attrs}}\n"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
tabs += 1 unless attributes.empty? || @style != :nested
|
||||
sub_rules.each do |sub|
|
||||
to_return << sub.to_s(tabs, total_rule)
|
||||
|
|
|
@ -3,7 +3,7 @@ require 'sass/tree/node'
|
|||
module Sass::Tree
|
||||
class ValueNode < Node
|
||||
attr_accessor :value
|
||||
|
||||
|
||||
def initialize(value, style)
|
||||
@value = value
|
||||
super(style)
|
||||
|
|
Loading…
Reference in a new issue