Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Freezing Haml

  • Loading branch information...
commit 2b0ab95eaf8e0d5746ca3c0b62fa51633a8d0c54 1 parent 5b0446b
@merbjedi merbjedi authored
Showing with 11,580 additions and 35 deletions.
  1. +0 −4 config/environment.rb
  2. +0 −31 lib/github_gem.rb
  3. +138 −0 vendor/plugins/haml/FAQ
  4. +20 −0 vendor/plugins/haml/MIT-LICENSE
  5. +319 −0 vendor/plugins/haml/README.rdoc
  6. +146 −0 vendor/plugins/haml/Rakefile
  7. +1 −0  vendor/plugins/haml/VERSION
  8. +7 −0 vendor/plugins/haml/bin/css2sass
  9. +8 −0 vendor/plugins/haml/bin/haml
  10. +7 −0 vendor/plugins/haml/bin/html2haml
  11. +8 −0 vendor/plugins/haml/bin/sass
  12. +7 −0 vendor/plugins/haml/init.rb
  13. +1,029 −0 vendor/plugins/haml/lib/haml.rb
  14. +236 −0 vendor/plugins/haml/lib/haml/buffer.rb
  15. +257 −0 vendor/plugins/haml/lib/haml/engine.rb
  16. +23 −0 vendor/plugins/haml/lib/haml/error.rb
  17. +347 −0 vendor/plugins/haml/lib/haml/exec.rb
  18. +264 −0 vendor/plugins/haml/lib/haml/filters.rb
  19. +415 −0 vendor/plugins/haml/lib/haml/helpers.rb
  20. +45 −0 vendor/plugins/haml/lib/haml/helpers/action_view_extensions.rb
  21. +134 −0 vendor/plugins/haml/lib/haml/helpers/action_view_mods.rb
  22. +188 −0 vendor/plugins/haml/lib/haml/html.rb
  23. +807 −0 vendor/plugins/haml/lib/haml/precompiler.rb
  24. +43 −0 vendor/plugins/haml/lib/haml/template.rb
  25. +58 −0 vendor/plugins/haml/lib/haml/template/patch.rb
  26. +72 −0 vendor/plugins/haml/lib/haml/template/plugin.rb
  27. +833 −0 vendor/plugins/haml/lib/sass.rb
  28. +245 −0 vendor/plugins/haml/lib/sass/constant.rb
  29. +101 −0 vendor/plugins/haml/lib/sass/constant/color.rb
  30. +53 −0 vendor/plugins/haml/lib/sass/constant/literal.rb
  31. +87 −0 vendor/plugins/haml/lib/sass/constant/number.rb
  32. +30 −0 vendor/plugins/haml/lib/sass/constant/operation.rb
  33. +22 −0 vendor/plugins/haml/lib/sass/constant/string.rb
  34. +393 −0 vendor/plugins/haml/lib/sass/css.rb
  35. +459 −0 vendor/plugins/haml/lib/sass/engine.rb
  36. +35 −0 vendor/plugins/haml/lib/sass/error.rb
  37. +165 −0 vendor/plugins/haml/lib/sass/plugin.rb
  38. +56 −0 vendor/plugins/haml/lib/sass/plugin/merb.rb
  39. +24 −0 vendor/plugins/haml/lib/sass/plugin/rails.rb
  40. +53 −0 vendor/plugins/haml/lib/sass/tree/attr_node.rb
  41. +20 −0 vendor/plugins/haml/lib/sass/tree/comment_node.rb
  42. +46 −0 vendor/plugins/haml/lib/sass/tree/directive_node.rb
  43. +42 −0 vendor/plugins/haml/lib/sass/tree/node.rb
  44. +89 −0 vendor/plugins/haml/lib/sass/tree/rule_node.rb
  45. +16 −0 vendor/plugins/haml/lib/sass/tree/value_node.rb
  46. +82 −0 vendor/plugins/haml/test/benchmark.rb
  47. +586 −0 vendor/plugins/haml/test/haml/engine_test.rb
  48. +187 −0 vendor/plugins/haml/test/haml/helper_test.rb
  49. +60 −0 vendor/plugins/haml/test/haml/html2haml_test.rb
  50. +52 −0 vendor/plugins/haml/test/haml/markaby/standard.mab
  51. +6 −0 vendor/plugins/haml/test/haml/mocks/article.rb
  52. +15 −0 vendor/plugins/haml/test/haml/results/content_for_layout.xhtml
  53. +9 −0 vendor/plugins/haml/test/haml/results/eval_suppressed.xhtml
  54. +86 −0 vendor/plugins/haml/test/haml/results/filters.xhtml
  55. +94 −0 vendor/plugins/haml/test/haml/results/helpers.xhtml
  56. +10 −0 vendor/plugins/haml/test/haml/results/helpful.xhtml
  57. +63 −0 vendor/plugins/haml/test/haml/results/just_stuff.xhtml
  58. +12 −0 vendor/plugins/haml/test/haml/results/list.xhtml
  59. +34 −0 vendor/plugins/haml/test/haml/results/nuke_inner_whitespace.xhtml
  60. +148 −0 vendor/plugins/haml/test/haml/results/nuke_outer_whitespace.xhtml
  61. +20 −0 vendor/plugins/haml/test/haml/results/original_engine.xhtml
  62. +21 −0 vendor/plugins/haml/test/haml/results/partials.xhtml
  63. +74 −0 vendor/plugins/haml/test/haml/results/silent_script.xhtml
  64. +42 −0 vendor/plugins/haml/test/haml/results/standard.xhtml
  65. +23 −0 vendor/plugins/haml/test/haml/results/tag_parsing.xhtml
  66. +5 −0 vendor/plugins/haml/test/haml/results/very_basic.xhtml
  67. +86 −0 vendor/plugins/haml/test/haml/results/whitespace_handling.xhtml
  68. +12 −0 vendor/plugins/haml/test/haml/rhtml/_av_partial_1.rhtml
  69. +8 −0 vendor/plugins/haml/test/haml/rhtml/_av_partial_2.rhtml
  70. +62 −0 vendor/plugins/haml/test/haml/rhtml/action_view.rhtml
  71. +54 −0 vendor/plugins/haml/test/haml/rhtml/standard.rhtml
  72. +168 −0 vendor/plugins/haml/test/haml/template_test.rb
  73. +9 −0 vendor/plugins/haml/test/haml/templates/_av_partial_1.haml
  74. +5 −0 vendor/plugins/haml/test/haml/templates/_av_partial_2.haml
  75. +8 −0 vendor/plugins/haml/test/haml/templates/_partial.haml
  76. +3 −0  vendor/plugins/haml/test/haml/templates/_text_area.haml
  77. +47 −0 vendor/plugins/haml/test/haml/templates/action_view.haml
  78. +8 −0 vendor/plugins/haml/test/haml/templates/breakage.haml
  79. +10 −0 vendor/plugins/haml/test/haml/templates/content_for_layout.haml
  80. +11 −0 vendor/plugins/haml/test/haml/templates/eval_suppressed.haml
  81. +94 −0 vendor/plugins/haml/test/haml/templates/filters.haml
  82. +69 −0 vendor/plugins/haml/test/haml/templates/helpers.haml
  83. +11 −0 vendor/plugins/haml/test/haml/templates/helpful.haml
  84. +77 −0 vendor/plugins/haml/test/haml/templates/just_stuff.haml
  85. +12 −0 vendor/plugins/haml/test/haml/templates/list.haml
  86. +26 −0 vendor/plugins/haml/test/haml/templates/nuke_inner_whitespace.haml
  87. +144 −0 vendor/plugins/haml/test/haml/templates/nuke_outer_whitespace.haml
  88. +17 −0 vendor/plugins/haml/test/haml/templates/original_engine.haml
  89. +1 −0  vendor/plugins/haml/test/haml/templates/partialize.haml
  90. +12 −0 vendor/plugins/haml/test/haml/templates/partials.haml
  91. +40 −0 vendor/plugins/haml/test/haml/templates/silent_script.haml
  92. +42 −0 vendor/plugins/haml/test/haml/templates/standard.haml
  93. +21 −0 vendor/plugins/haml/test/haml/templates/tag_parsing.haml
  94. +4 −0 vendor/plugins/haml/test/haml/templates/very_basic.haml
  95. +87 −0 vendor/plugins/haml/test/haml/templates/whitespace_handling.haml
  96. +15 −0 vendor/plugins/haml/test/haml/test_helper.rb
  97. +276 −0 vendor/plugins/haml/test/sass/engine_test.rb
  98. +159 −0 vendor/plugins/haml/test/sass/plugin_test.rb
  99. +4 −0 vendor/plugins/haml/test/sass/results/alt.css
  100. +9 −0 vendor/plugins/haml/test/sass/results/basic.css
  101. +5 −0 vendor/plugins/haml/test/sass/results/compact.css
  102. +87 −0 vendor/plugins/haml/test/sass/results/complex.css
  103. +1 −0  vendor/plugins/haml/test/sass/results/compressed.css
  104. +14 −0 vendor/plugins/haml/test/sass/results/constants.css
  105. +19 −0 vendor/plugins/haml/test/sass/results/expanded.css
  106. +29 −0 vendor/plugins/haml/test/sass/results/import.css
  107. +95 −0 vendor/plugins/haml/test/sass/results/mixins.css
  108. +24 −0 vendor/plugins/haml/test/sass/results/multiline.css
  109. +22 −0 vendor/plugins/haml/test/sass/results/nested.css
  110. +13 −0 vendor/plugins/haml/test/sass/results/parent_ref.css
  111. +1 −0  vendor/plugins/haml/test/sass/results/subdir/nested_subdir/nested_subdir.css
  112. +1 −0  vendor/plugins/haml/test/sass/results/subdir/subdir.css
  113. +2 −0  vendor/plugins/haml/test/sass/templates/_partial.sass
  114. +16 −0 vendor/plugins/haml/test/sass/templates/alt.sass
  115. +23 −0 vendor/plugins/haml/test/sass/templates/basic.sass
  116. +2 −0  vendor/plugins/haml/test/sass/templates/bork.sass
  117. +2 −0  vendor/plugins/haml/test/sass/templates/bork2.sass
  118. +17 −0 vendor/plugins/haml/test/sass/templates/compact.sass
  119. +310 −0 vendor/plugins/haml/test/sass/templates/complex.sass
  120. +15 −0 vendor/plugins/haml/test/sass/templates/compressed.sass
  121. +97 −0 vendor/plugins/haml/test/sass/templates/constants.sass
  122. +17 −0 vendor/plugins/haml/test/sass/templates/expanded.sass
  123. +11 −0 vendor/plugins/haml/test/sass/templates/import.sass
  124. +14 −0 vendor/plugins/haml/test/sass/templates/importee.sass
  125. +76 −0 vendor/plugins/haml/test/sass/templates/mixins.sass
  126. +20 −0 vendor/plugins/haml/test/sass/templates/multiline.sass
  127. +25 −0 vendor/plugins/haml/test/sass/templates/nested.sass
  128. +25 −0 vendor/plugins/haml/test/sass/templates/parent_ref.sass
  129. +3 −0  vendor/plugins/haml/test/sass/templates/subdir/nested_subdir/nested_subdir.sass
  130. +6 −0 vendor/plugins/haml/test/sass/templates/subdir/subdir.sass
View
4 config/environment.rb
@@ -10,7 +10,6 @@
# Bootstrap the Rails environment, frameworks, and default configuration
require File.join(File.dirname(__FILE__), 'boot')
-require 'github_gem'
Rails::Initializer.run do |config|
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
@@ -66,8 +65,5 @@
# Activate observers that should always be running
# config.active_record.observers = :cacher, :garbage_collector
- # Gem Requirements
- config.gem "haml", :version => ">= 2.0.0"
-
end
View
31 lib/github_gem.rb
@@ -1,31 +0,0 @@
-require 'active_support'
-
-module Rails
- class Configuration
-
- # Adds a single Gem dependency from GitHub
- #
- # # declare a github gem plugin
- # config.github_gem 'jcnetdev-better_partials'
- #
- # # equivalent to:
- # config.gem 'jcnetdev-better_partials', :lib => 'better_partials', :source => 'http://gems.github.com'
- def github_gem(name, options = {})
-
- # set lib name
- name_parts = name.split("-")
- if name_parts.size > 1
- lib = name.gsub("#{name_parts.first}-", "")
- else
- lib = name
- end
-
- # set defaults
- options.reverse_merge!(:lib => lib, :source => 'http://gems.github.com')
-
- # add rails dependency
- @gems << Rails::GemDependency.new(name, options)
- end
-
- end
-end
View
138 vendor/plugins/haml/FAQ
@@ -0,0 +1,138 @@
+= Frequently Asked Questions
+
+== Haml
+
+=== How do I put a punctuation mark after an element, like "<tt>I like <strong>cake</strong>!</tt>"?
+
+Expressing the structure of a document
+and expressing inline formatting are two very different problems.
+Haml is mostly designed for structure,
+so the best way to deal with formatting is to leave it to other languages
+that are designed for it.
+You could use Textile:
+
+ %p
+ :textile
+ I like *cake*!
+
+or Markdown:
+
+ %p
+ :markdown
+ I like **cake**!
+
+or plain old XHTML:
+
+ %p I like <strong>cake</strong>!
+
+If you're inserting something that's generated by a helper, like a link,
+then it's even easier:
+
+ %p== I like #{link_to 'chocolate', 'http://franschocolates.com'}!
+
+=== How do I stop Haml from indenting the contents of my +pre+ and +textarea+ tags?
+
+Because Haml automatically indents the HTML source code,
+the contents of whitespace-sensitive tags like +pre+ and +textarea+
+can get screwed up.
+The solution is to replace the newlines inside these tags
+with HTML newline entities (<tt>&#x000A;</tt>),
+which Haml does using the Haml::Helpers#preserve and Haml::Helpers#find_and_preserve helpers.
+
+Normally, Haml will do this for you automatically
+when you're using a tag that needs it
+(this can be customized using the <tt>:preserve</tt> option;
+see the Options section of the {Haml reference}(../classes/Haml.html)).
+For example,
+
+ %p
+ %textarea= "Foo\nBar"
+
+will be compiled to
+
+ <p>
+ <textarea>Foo&#x000A;Bar</textarea>
+ </p>
+
+However, if a helper is generating the tag,
+Haml can't detect that and so you'll have to call +find_and_preserve+ yourself.
+You can also use <tt>~</tt>, which is the same as <tt>=</tt>
+except that it automatically runs +find_and_preserve+ on its input.
+For example:
+
+ %p= find_and_preserve "<textarea>Foo\nBar</textarea>"
+
+is the same as
+
+ %p~ "<textarea>Foo\nBar</textarea>"
+
+and renders
+
+ <p><textarea>Foo&#x000A;Bar</textarea></p>
+
+=== How do I make my long lines of Ruby code look nicer in my Haml document?
+
+Put them in a helper or your model.
+
+Haml purposefully makes it annoying to put lots of Ruby code into your templates,
+because lots of code doesn't belong in the view.
+If you take that huge +link_to_remote+ call
+and move it to a +update_sidebar_link+ helper,
+it'll make your view both easier to read and more semantic.
+
+If you absolutely must put lots of code in your template,
+Haml offers a somewhat awkward multiline-continuation tool.
+Put a <tt>|</tt> (pipe character) at the end of each line you want to be merged into one
+(including the last line!).
+For example:
+
+ %p= @this.is(way.too.much). |
+ code("and I should"). |
+ really_move.it.into( |
+ :a => @helper) |
+
+=== I have Haml installed. Why is Rails (only looking for <tt>.html.erb</tt> files | rendering Haml files as plain text | rendering Haml files as blank pages)?
+
+There are several reasons these things might be happening.
+First of all, make sure vendor/plugins/haml really exists
+and has an init.rb file in there.
+Then try restarting Mongrel or WEBrick or whatever you might be using.
+
+Finally, if none of these work,
+chances are you've got some localization plugin like Globalize installed.
+Such plugins often don't play nicely with Haml.
+Luckily, there's usually an easy fix.
+For Globalize, just edit globalize/lib/globalize/rails/action_view.rb
+and change
+
+ @@re_extension = /\.(rjs|rhtml|rxml)$/
+
+to
+
+ @@re_extension = /\.(rjs|rhtml|rxml|erb|builder|haml)$/
+
+For other plugins, a little searching will probably turn up a way to fix them as well.
+
+== Sass
+
+=== Can I use a variable from my controller in my Sass file?
+
+No. Sass files aren't views.
+They're compiled once into static CSS files,
+then left along until they're changed and need to be compiled again.
+Not only don't you want to be running a full request cycle
+every time someone requests a stylesheet,
+but it's not a great idea to put much logic in there anyway
+due to how browsers handle them.
+
+If you really need some sort of dynamic CSS,
+the best thing to do is put only the snippet you need to dynamically set
+in the +head+ of your HTML document.
+
+== You still haven't answered my question!
+
+Sorry! Try looking at the Haml or Sass references,
+in the doucmentation for the haml and Sass modules, respectively.
+If you can't find an answer there,
+feel free to ask in #haml on irc.freenode.net
+or send an email to the {mailing list}[http://groups.google.com/group/haml?hl=en].
View
20 vendor/plugins/haml/MIT-LICENSE
@@ -0,0 +1,20 @@
+Copyright (c) 2006-2008 Hampton Catlin
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
319 vendor/plugins/haml/README.rdoc
@@ -0,0 +1,319 @@
+= Haml and Sass
+
+Haml and Sass are templating engines
+for the two most common types of documents on the web:
+HTML and CSS, respectively.
+They are designed to make it both easier and more pleasant
+to code HTML and CSS documents,
+by eliminating redundancy,
+reflecting the underlying structure that the document represents,
+and providing elegant, easily understandable, and powerful syntax.
+
+== Using
+
+There are several ways to use Haml and Sass.
+They can be used as a plugins for Rails or Merb,
+or embedded on their own in other applications.
+The first step of all of these is to install the Haml gem:
+
+ gem install haml
+
+To install Haml and Sass as a Rails plugin,
+just run <tt>haml --rails path/to/rails/app</tt>
+and both Haml and Sass will be installed.
+Views with the <tt>.haml</tt> (or <tt>.html.haml</tt> for edge)
+extension will automatically use Haml.
+Sass is a little more complicated;
+<tt>.sass</tt> files should be placed in public/stylesheets/sass,
+where they'll be automatically compiled
+to corresponding CSS files in public/stylesheets when needed
+(the Sass template directory is customizable...
+see the Sass module docs for details).
+
+For Merb, <tt>.html.haml</tt> views will work without any further modification.
+To enable Sass, you also need to add it add a dependency.
+To do so, just add
+
+ dependency "haml"
+
+to config/dependencies.rb.
+Then it'll work just like it does in Rails.
+
+To use Haml and Sass programatically,
+check out the RDocs for the Haml and Sass modules.
+
+== Formatting
+
+=== Haml
+
+The most basic element of Haml
+is a shorthand for creating HTML tags:
+
+ %tagname{ :attr1 => 'value1', :attr2 => 'value2' } Contents
+
+No end-tag is needed; Haml handles that automatically.
+Adding <tt>class</tt> and <tt>id</tt> attributes is even easier.
+Haml uses the same syntax as the CSS that styles the document:
+
+ %tagname#id.class
+
+In fact, when you're using the <tt><div></tt> tag,
+it becomes <em>even easier</em>.
+Because <tt><div></tt> is such a common element,
+a tag without a name defaults to a div. So
+
+ #foo Hello!
+
+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.
+Again, a closing tag is automatically added.
+For example:
+
+ %ul
+ %li Salt
+ %li Pepper
+
+becomes:
+
+ <ul>
+ <li>Salt</li>
+ <li>Pepper</li>
+ </ul>
+
+You can also put plain text as a child of an element:
+
+ %p
+ Hello,
+ World!
+
+It's even possible to embed Ruby code into Haml documents.
+An equals sign, <tt>=</tt>, will output the result of the code.
+A hyphen, <tt>-</tt>, will run the code but not output the result.
+You can even use control statements
+like <tt>if</tt> and <tt>while</tt>:
+
+ %p
+ Date/Time:
+ - now = DateTime.now
+ %strong= now
+ - if now > DateTime.parse("December 31, 2006")
+ = "Happy new " + "year!"
+
+Haml provides far more tools than those presented here.
+Check out the reference documentation in the Haml module.
+
+=== Sass
+
+At its most basic,
+Sass is just another way of writing CSS.
+Although it's very much like normal CSS,
+the basic syntax offers a few helpful features:
+tabulation (using *two spaces*)
+indicates the attributes in a rule,
+rather than non-DRY brackets;
+and newlines indicate the end of an attribute,
+rather than a semicolon.
+For example:
+
+ #main
+ :background-color #f00
+ :width 98%
+
+becomes:
+
+ #main {
+ background-color: #f00;
+ width: 98% }
+
+However, Sass provides much more than a way to make CSS look nice.
+In CSS, it's important to have accurate selectors,
+so your styles don't just apply to everything.
+However, in order to do this,
+you need to use nested element selectors.
+These get very ugly very quickly.
+I'm sure everyone's had to write something like
+"#main .sidebar .top p h1 a",
+followed by
+"#main .sidebar .top p h1 a:visited" and
+"#main .sidebar .top p h1 a:hover".
+Well, Sass gets rid of that.
+Like Haml, it uses indentation to indicate the structure of the document.
+So, what was:
+
+ #main {
+ width: 90%;
+ }
+ #main p {
+ border-style: solid;
+ border-width: 1px;
+ border-color: #00f;
+ }
+ #main p a {
+ text-decoration: none;
+ font-weight: bold;
+ }
+ #main p a:hover {
+ text-decoration: underline;
+ }
+
+becomes:
+
+ #main
+ :width 90%
+ p
+ :border-style solid
+ :border-width 1px
+ :border-color #00f
+ a
+ :text-decoration none
+ :font-weight bold
+ a:hover
+ :text-decoration underline
+
+Pretty nice, no? Well, it gets better.
+One of the main complaints against CSS is that it doesn't allow constants.
+What if have a color or a width you re-use all the time?
+In CSS, you just have to re-type it each time,
+which is a nightmare when you decide to change it later.
+Not so for Sass!
+You can use the "!" character to set constants.
+Then, if you put "=" after your attribute name,
+you can set it to a constant.
+For example:
+
+ !note_bg= #55aaff
+
+ #main
+ :width 70%
+ .note
+ :background-color= !note_bg
+ p
+ :width 5em
+ :background-color= !note_bg
+
+becomes:
+
+ #main {
+ width: 70%; }
+ #main .note {
+ background-color: #55aaff; }
+ #main p {
+ width: 5em;
+ background-color: #55aaff; }
+
+You can even do simple arithmetic operations with constants,
+adding numbers and even colors together:
+
+ !main_bg= #46ar12
+ !main_width= 40em
+
+ #main
+ :background-color= !main_bg
+ :width= !main_width
+ .sidebar
+ :background-color= !main_bg + #333333
+ :width= !main_width - 25em
+
+becomes:
+
+ #main {
+ background-color: #46a312;
+ width: 40em; }
+ #main .sidebar {
+ background-color: #79d645;
+ width: 15em; }
+
+Taking the idea of constants a bit further are mixins.
+These let you group whole swathes of CSS attributes into a single
+directive and then include those anywhere you want:
+
+ =blue-border
+ :border
+ :color blue
+ :width 2px
+ :style dotted
+
+ .comment
+ +blue-border
+ :padding 2px
+ :margin 10px 0
+
+ .reply
+ +blue-border
+
+becomes:
+
+ .comment {
+ border-color: blue;
+ border-width: 2px;
+ border-style: dotted;
+ padding: 2px;
+ margin: 10px 0;
+ }
+
+ .reply {
+ border-color: blue;
+ border-width: 2px;
+ border-style: dotted;
+ }
+
+A comprehensive list of features is in
+the documentation for the Sass module.
+
+== Executables
+
+The Haml gem includes several executables that are useful
+for dealing with Haml and Sass from the command line.
+
+=== +haml+
+
+The +haml+ executable transforms a source Haml file into HTML.
+See <tt>haml --help</tt> for further information and options.
+
+=== +sass+
+
+The +sass+ executable transforms a source Sass file into CSS.
+See <tt>sass --help</tt> for further information and options.
+
+=== <tt>html2haml</tt>
+
+The <tt>html2haml</tt> executable attempts to transform HTML,
+optionally with ERB markup, into Haml code.
+Since HTML is so variable, this transformation is not always perfect;
+it's a good idea to have a human check the output of this tool.
+See <tt>html2haml --help</tt> for further information and options.
+
+=== <tt>css2sass</tt>
+
+The <tt>css2sass</tt> executable attempts to transform CSS into Sass code.
+This transformation attempts to use Sass nesting where possible.
+See <tt>css2sass --help</tt> for further information and options.
+
+== Authors
+
+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
+is a partner at Unspace Interactive.
+
+Nathan Weizenbaum is the primary maintainer and architect of the "modern" Ruby
+implementation of Haml. His hard work has kept the project alive by endlessly
+answering forum posts, fixing bugs, refactoring, finding speed improvements,
+writing documentation, implementing new features, and getting Hampton
+coffee (a fitting task for a boy-genius). Nathan lives in Seattle, Washington and
+while not being a student at University of Washington he consults for
+Unspace Interactive and Microsoft.
+
+If you use this software, you must pay Hampton a compliment. And
+buy Nathan some jelly beans. Maybe pet a kitten. Yeah. Pet that kitty.
+
+Some of the work on Haml was supported by Unspace Interactive.
+
+Beyond that, the implementation is licensed under the MIT License.
+Ok, fine, I guess that means compliments aren't *required*.
View
146 vendor/plugins/haml/Rakefile
@@ -0,0 +1,146 @@
+require 'rubygems'
+require 'rake'
+
+# ----- Benchmarking -----
+
+desc <<END
+Benchmark haml against ERb.
+ TIMES=n sets the number of runs. Defaults to 1000.
+END
+task :benchmark do
+ sh "ruby test/benchmark.rb #{ENV['TIMES']}"
+end
+
+# ----- Default: Testing ------
+
+task :default => :test
+
+require 'rake/testtask'
+
+Rake::TestTask.new do |t|
+ t.libs << 'lib'
+ t.pattern = 'test/**/*_test.rb'
+ t.verbose = true
+end
+Rake::Task[:test].send(:add_comment, <<END)
+To run with an alternate version of Rails, make test/rails a symlink to that version.
+END
+
+# ----- Packaging -----
+
+require 'rake/gempackagetask'
+load 'haml.gemspec'
+
+Rake::GemPackageTask.new(HAML_GEMSPEC) do |pkg|
+ if Rake.application.top_level_tasks.include?('release')
+ pkg.need_tar_gz = true
+ pkg.need_tar_bz2 = true
+ pkg.need_zip = true
+ end
+end
+
+task :revision_file do
+ require 'lib/haml'
+
+ if Haml.version[:rev] && !Rake.application.top_level_tasks.include?('release')
+ File.open('REVISION', 'w') { |f| f.puts Haml.version[:rev] }
+ elsif Rake.application.top_level_tasks.include?('release')
+ File.open('REVISION', 'w') { |f| f.puts "(release)" }
+ else
+ File.open('REVISION', 'w') { |f| f.puts "(unknown)" }
+ end
+end
+Rake::Task[:package].prerequisites.insert(0, :revision_file)
+
+# We also need to get rid of this file after packaging.
+Rake::Task[:package].enhance { File.delete('REVISION') if File.exists?('REVISION') }
+
+task :install => [:package] do
+ sudo = RUBY_PLATFORM =~ /win32/ ? '' : 'sudo'
+ sh %{#{sudo} gem install --no-ri pkg/haml-#{File.read('VERSION').strip}}
+end
+
+task :release => [:package] do
+ name, version = ENV['NAME'], ENV['VERSION']
+ raise "Must supply NAME and VERSION for release task." unless name && version
+ sh %{rubyforge login}
+ sh %{rubyforge add_release haml haml "#{name} (v#{version})" pkg/haml-#{version}.gem}
+ sh %{rubyforge add_file haml haml "#{name} (v#{version})" pkg/haml-#{version}.tar.gz}
+ sh %{rubyforge add_file haml haml "#{name} (v#{version})" pkg/haml-#{version}.tar.bz2}
+ sh %{rubyforge add_file haml haml "#{name} (v#{version})" pkg/haml-#{version}.zip}
+end
+
+# ----- Documentation -----
+
+begin
+ require 'hanna/rdoctask'
+rescue LoadError
+ require 'rake/rdoctask'
+end
+
+Rake::RDocTask.new do |rdoc|
+ rdoc.title = 'Haml/Sass'
+ rdoc.options << '--line-numbers' << '--inline-source'
+ rdoc.rdoc_files.include(*FileList.new('*') do |list|
+ list.exclude(/(^|[^.a-z])[a-z]+/)
+ list.exclude('TODO')
+ end.to_a)
+ rdoc.rdoc_files.include('lib/**/*.rb')
+ rdoc.rdoc_files.exclude('TODO')
+ rdoc.rdoc_files.exclude('lib/haml/buffer.rb')
+ rdoc.rdoc_files.exclude('lib/sass/tree/*')
+ rdoc.rdoc_dir = 'rdoc'
+ rdoc.main = 'README.rdoc'
+end
+
+# ----- Coverage -----
+
+begin
+ require 'rcov/rcovtask'
+
+ Rcov::RcovTask.new do |t|
+ t.test_files = FileList['test/**/*_test.rb']
+ t.rcov_opts << '-x' << '"^\/"'
+ if ENV['NON_NATIVE']
+ t.rcov_opts << "--no-rcovrt"
+ end
+ t.verbose = true
+ end
+rescue LoadError; end
+
+# ----- Profiling -----
+
+begin
+ require 'ruby-prof'
+
+ desc <<END
+Run a profile of haml.
+ ENGINE=str sets the engine to be profiled. Defaults to Haml.
+ TIMES=n sets the number of runs. Defaults to 1000.
+ FILE=str sets the file to profile.
+ Defaults to 'standard' for Haml and 'complex' for Sass.
+ OUTPUT=str sets the ruby-prof output format.
+ Can be Flat, CallInfo, or Graph. Defaults to Flat. Defaults to Flat.
+END
+ task :profile do
+ engine = (ENV['ENGINE'] || 'haml').downcase
+ times = (ENV['TIMES'] || '1000').to_i
+ file = ENV['FILE']
+
+ if engine == 'sass'
+ require 'lib/sass'
+
+ file = File.read("#{File.dirname(__FILE__)}/test/sass/templates/#{file || 'complex'}.sass")
+ result = RubyProf.profile { times.times { Sass::Engine.new(file).render } }
+ else
+ require 'lib/haml'
+
+ file = File.read("#{File.dirname(__FILE__)}/test/haml/templates/#{file || 'standard'}.haml")
+ obj = Object.new
+ Haml::Engine.new(file).def_method(obj, :render)
+ result = RubyProf.profile { times.times { obj.render } }
+ end
+
+ RubyProf.const_get("#{(ENV['OUTPUT'] || 'Flat').capitalize}Printer").new(result).print
+ end
+rescue LoadError; end
View
1  vendor/plugins/haml/VERSION
@@ -0,0 +1 @@
+2.0.0
View
7 vendor/plugins/haml/bin/css2sass
@@ -0,0 +1,7 @@
+#!/usr/bin/env ruby
+
+require File.dirname(__FILE__) + '/../lib/haml'
+require 'haml/exec'
+
+opts = Haml::Exec::CSS2Sass.new(ARGV)
+opts.parse!
View
8 vendor/plugins/haml/bin/haml
@@ -0,0 +1,8 @@
+#!/usr/bin/env ruby
+# The command line Haml parser.
+
+require File.dirname(__FILE__) + '/../lib/haml'
+require 'haml/exec'
+
+opts = Haml::Exec::Haml.new(ARGV)
+opts.parse!
View
7 vendor/plugins/haml/bin/html2haml
@@ -0,0 +1,7 @@
+#!/usr/bin/env ruby
+
+require File.dirname(__FILE__) + '/../lib/haml'
+require 'haml/exec'
+
+opts = Haml::Exec::HTML2Haml.new(ARGV)
+opts.parse!
View
8 vendor/plugins/haml/bin/sass
@@ -0,0 +1,8 @@
+#!/usr/bin/env ruby
+# The command line Sass parser.
+
+require File.dirname(__FILE__) + '/../lib/haml'
+require 'haml/exec'
+
+opts = Haml::Exec::Sass.new(ARGV)
+opts.parse!
View
7 vendor/plugins/haml/init.rb
@@ -0,0 +1,7 @@
+begin
+ require File.join(File.dirname(__FILE__), 'lib', 'haml') # From here
+rescue LoadError
+ require 'haml' # From gem
+end
+
+Haml.init_rails(binding)
View
1,029 vendor/plugins/haml/lib/haml.rb
@@ -0,0 +1,1029 @@
+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,
+# because it is actually an abstract description of the XHTML,
+# with some code to generate dynamic content.
+#
+# == Features
+#
+# * Whitespace active
+# * Well-formatted markup
+# * DRY
+# * Follows CSS conventions
+# * Integrates Ruby code
+# * Implements Rails templates with the .haml extension
+#
+# == Using Haml
+#
+# Haml can be used in two 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.
+# The first step for all of these is to install the Haml gem:
+#
+# gem install haml
+#
+# 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.
+#
+# Once it's installed, all view files with the ".haml" extension
+# (or ".html.haml" for Merb or edge Rails)
+# will be compiled using Haml.
+#
+# You can access instance variables in Haml templates
+# 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>
+# <a href='/'>Home</a>
+# </div>
+# </div>
+#
+# === Ruby Module
+#
+# Haml can also be used completely separately from Rails and ActionView.
+# To do this, install the gem with RubyGems:
+#
+# gem install haml
+#
+# You can then use it by including the "haml" gem in Ruby code,
+# and using Haml::Engine like so:
+#
+# engine = Haml::Engine.new("%p Haml code!")
+# 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,
+# so logic will work in it and local variables may be used.
+# Quote characters within the attribute
+# 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>
+# </head>
+#
+# ===== Attribute Methods
+#
+# A Ruby method call that returns a hash
+# can be substituted for the hash contents.
+# For example, Haml::Helpers defines the following method:
+#
+# def html_attrs(lang = 'en-US')
+# {:xmlns => "http://www.w3.org/1999/xhtml", 'xml:lang' => lang, :lang => lang}
+# end
+#
+# This can then be used in Haml, like so:
+#
+# %html{html_attrs('fr-fr')}
+#
+# This is compiled to:
+#
+# <html lang='fr-fr' xml:lang='fr=fr' xmlns='http://www.w3.org/1999/xhtml'>
+# </html>
+#
+# You can use as many such attribute methods as you want
+# by separating them with commas,
+# like a Ruby argument list.
+# All the hashes will me merged together, from left to right.
+# For example, if you defined
+#
+# def hash1
+# {:bread => 'white', :filling => 'peanut butter and jelly'}
+# end
+#
+# def hash2
+# {:bread => 'whole wheat'}
+# end
+#
+# then
+#
+# %sandwich{hash1, hash2, :delicious => true}/
+#
+# would compile to:
+#
+# <sandwich bread='whole wheat' delicious='true' filling='peanut butter and jelly' />
+#
+# ===== Boolean Attributes
+#
+# Some attributes, such as "checked" for <tt>input</tt> tags or "selected" for <tt>option</tt> tags,
+# are "boolean" in the sense that their values don't matter -
+# it only matters whether or not they're present.
+# In HTML (but not XHTML), these attributes can be written as
+#
+# <input selected>
+#
+# To do this in Haml, just assign a Ruby true value to the attribute:
+#
+# %input{:selected => true}
+#
+# 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.
+# In both XHTML and HTML
+#
+# %input{:selected => false}
+#
+# 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
+# (transformed to use underlines rather than camel case)
+# and the id is set to the object's class, followed by its id.
+# Because the id of an object is normally an obscure implementation detail,
+# this is most useful for elements that represent instances of Models.
+# Additionally, the second argument (if present) will be used as a prefix for
+# both the id and class attributes.
+# For example:
+#
+# # file: app/controllers/users_controller.rb
+#
+# def show
+# @user = CrazyUser.find(15)
+# end
+#
+# -# file: app/views/users/show.haml
+#
+# %div[@user, :greeting]
+# %bar[290]/
+# Hello!
+#
+# is compiled to:
+#
+# <div class="greeting_crazy_user" id="greeting_crazy_user_15">
+# <bar class="fixnum" id="fixnum_581" />
+# Hello!
+# </div>
+#
+# ==== /
+#
+# 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' />
+#
+# Some tags are automatically closed, as long as they have no content.
+# +meta+, +img+, +link+, +script+, +br+, and +hr+ tags are closed by default.
+# This list can be customized by setting the <tt>:autoclose</tt> option (see below).
+# For example:
+#
+# %br
+# %meta{'http-equiv' => 'Content-Type', :content => 'text/html'}
+#
+# is also compiled to:
+#
+# <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.
+# Multiple class names can be specified in a similar way to CSS,
+# 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
+# Doogie Howser Comes Out
+# .article.date
+# 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>
+# <div class="article date">2006-11-05</div>
+# <div class="article entry">
+# Neil Patrick Harris would like to dispel any rumors that he is straight
+# </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>
+#
+# ==== > and <
+#
+# <tt>></tt> and <tt><</tt> give you more control over the whitespace near a tag.
+# <tt>></tt> will remove all whitespace surrounding a tag,
+# while <tt><</tt> will remove all whitespace immediately within a tag.
+# You can think of them as alligators eating the whitespace:
+# <tt>></tt> faces out of the tag and eats the whitespace on the outside,
+# and <tt><</tt> faces into the tag and eats the whitespace on the inside.
+# They're placed at the end of a tag definition,
+# after class, id, and attribute declarations
+# but before <tt>/</tt> or <tt>=</tt>.
+# For example:
+#
+# %blockquote<
+# %div
+# Foo!
+#
+# is compiled to:
+#
+# <blockquote><div>
+# Foo!
+# </div></blockquote>
+#
+# And:
+#
+# %img
+# %img>
+# %img
+#
+# is compiled to:
+#
+# <img /><img /><img />
+#
+# And:
+#
+# %p<= "Foo\nBar"
+#
+# is compiled to:
+#
+# <p>Foo
+# Bar</p>
+#
+# And finally:
+#
+# %img
+# %pre><
+# foo
+# bar
+# %img
+#
+# is compiled to:
+#
+# <img /><pre>foo
+# bar</pre><img />
+#
+# ==== =
+#
+# <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.
+# It works the same as <tt>=</tt> without a tag:
+# it inserts the result of the Ruby code into the template.
+# 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>
+#
+# ==== ~
+#
+# ~ works just like =, except that it runs Haml::Helpers#find_and_preserve on its input.
+# For example,
+#
+# ~ "Foo\n<pre>Bar\nBaz</pre>"
+#
+# is the same as:
+#
+# = find_and_preserve("Foo\n<pre>Bar\nBaz</pre>")
+#
+# and is compiled to:
+#
+# Foo
+# <pre>Bar&#x000A;Baz</pre>
+#
+# See also Whitespace Preservation, below.
+#
+# === 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
+# %head
+# %title Myspace
+# %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>
+# <head>
+# <title>Myspace</title>
+# </head>
+# <body>
+# <h1>I am the international space station</h1>
+# <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 |
+# probably make it |
+# 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.
+# </hoo>
+# </whoo>
+#
+# ==== :
+#
+# The colon character designates a filter.
+# This allows you to pass an indented block of text as input
+# to another filtering program and add the result to the output of Haml.
+# The syntax is simply a colon followed by the name of the filter.
+# For example,
+#
+# %p
+# :markdown
+# Textile
+# =======
+#
+# Hello, *World*
+#
+# is compiled to
+#
+# <p>
+# <h1>Textile</h1>
+#
+# <p>Hello, <em>World</em></p>
+# </p>
+#
+# Filters can have Ruby code interpolated, like with ==.
+# For example,
+#
+# - flavor = "raspberry"
+# #content
+# :textile
+# I *really* prefer _#{h flavor}_ jam.
+#
+# is compiled to
+#
+# <div id='content'>
+# <p>I <strong>really</strong> prefer <em>raspberry</em> jam.</p>
+# </div>
+#
+# Haml has the following filters defined:
+#
+# [plain] Does not parse the filtered text.
+# This is useful for large blocks of text without HTML tags,
+# when you don't want lines starting with <tt>.</tt> or <tt>-</tt>
+# to be parsed.
+#
+# [javascript] Surrounds the filtered text with <script> and CDATA tags.
+# Useful for including inline Javascript.
+#
+# [escaped] Works the same as plain, but HTML-escapes the text
+# before placing it in the document.
+#
+# [ruby] Parses the filtered text with the normal Ruby interpreter.
+# All output sent to <tt>$stdout</tt>, like with +puts+,
+# is output into the Haml document.
+# Not available if the <tt>suppress_eval</tt> option is set to true.
+# The Ruby code is evaluated in the same context as the Haml template.
+#
+# [preserve] Inserts the filtered text into the template with whitespace preserved.
+# <tt>preserve</tt>d blocks of text aren't indented,
+# and newlines are replaced with the HTML escape code for newlines,
+# to preserve nice-looking output.
+# See also Whitespace Preservation, below.
+#
+# [erb] Parses the filtered text with ERB, like an RHTML template.
+# Not available if the <tt>suppress_eval</tt> option is set to true.
+# Embedded Ruby code is evaluated in the same context as the Haml template.
+#
+# [sass] Parses the filtered text with Sass to produce CSS output.
+#
+# [redcloth] Parses the filtered text with RedCloth (http://whytheluckystiff.net/ruby/redcloth),
+# which uses both Textile and Markdown syntax.
+# Only works if RedCloth is installed.
+#
+# [textile] Parses the filtered text with Textile (http://www.textism.com/tools/textile).
+# Only works if RedCloth is installed.
+#
+# [markdown] Parses the filtered text with Markdown (http://daringfireball.net/projects/markdown).
+# Only works if RedCloth or BlueCloth (http://www.deveiate.org/projects/BlueCloth)
+# is installed
+# (BlueCloth takes precedence if both are installed).
+#
+# You can also define your own filters (see Haml::Filters).
+#
+# === 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
+# </p>
+#
+# If the <tt>:escape_html</tt> option is set, <tt>=</tt> will sanitize any
+# HTML-sensitive characters generated by the script. For example:
+#
+# = '<script>alert("I\'m evil!");</script>'
+#
+# would be compiled to
+#
+# &lt;script&gt;alert(&quot;I'm evil!&quot;);&lt;/script&gt;
+#
+# ==== -
+#
+# 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,
+# similarly to Ruby string interpolation.
+# For example,
+#
+# %p== This is #{h quality} cake!
+#
+# is the same as
+#
+# %p= "This is #{h quality} cake!"
+#
+# and might compile to
+#
+# <p>This is scrumptious cake!</p>
+#
+# Backslashes can be used to escape "#{" strings,
+# but they don't act as escapes anywhere else in the string.
+# For example:
+#
+# %p
+# == \\ Look at \\#{h word} lack of backslash: \#{foo}
+#
+# might compile to
+#
+# <p>
+# \\ Look at \yon lack of backslash: #{foo}
+# </p>
+#
+# ==== &=
+#
+# An ampersand followed by one or two equals characters
+# evaluates Ruby code just like the equals without the ampersand,
+# but sanitizes any HTML-sensitive characters in the result of the code.
+# For example:
+#
+# &= "I like cheese & crackers"
+#
+# compiles to
+#
+# I like cheese &amp; crackers
+#
+# If the <tt>:escape_html</tt> option is set,
+# &= behaves identically to =.
+#
+# ==== !=
+#
+# An exclamation mark followed by one or two equals characters
+# evaluates Ruby code just like the equals would,
+# but never sanitizes the HTML.
+#
+# By default, the single equals doesn't sanitize HTML either.
+# However, if the <tt>:escape_html</tt> option is set, = will sanitize the HTML, but != still won't.
+# For example, if <tt>:escape_html</tt> is set:
+#
+# = "I feel <strong>!"
+# != "I feel <strong>!"
+#
+# compiles to
+#
+# I feel &lt;strong&gt;!
+# 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
+# after a silent script command.
+# 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>
+# <p>
+# 43
+# </p>
+# <p>
+# 44
+# </p>
+# <p>
+# 45
+# </p>
+# <p>
+# 46
+# </p>
+#
+# Another example:
+#
+# %p
+# - case 2
+# - when 1
+# = "1!"
+# - when 2
+# = "2?"
+# - when 3
+# = "3."
+#
+# is compiled to:
+#
+# <p>
+# 2?
+# </p>
+#
+# ==== -#
+#
+# The hyphen followed immediately by the pound sign
+# signifies a silent comment.
+# Any text following this isn't rendered in the resulting document
+# at all.
+#
+# For example:
+#
+# %p foo
+# -# This is a comment
+# %p bar
+#
+# is compiled to:
+#
+# <p>foo</p>
+# <p>bar</p>
+#
+# You can also nest text beneath a silent comment.
+# None of this text will be rendered.
+# For example:
+#
+# %p foo
+# -#
+# This won't be displayed
+# Nor will this
+# %p bar
+#
+# is compiled to:
+#
+# <p>foo</p>
+# <p>bar</p>
+#
+# == Other Useful Things
+#
+# === Whitespace Preservation
+#
+# Sometimes you don't want Haml to indent all your text.
+# For example, tags like +pre+ and +textarea+ are whitespace-sensitive;
+# indenting the text makes them render wrong.
+#
+# Haml deals with this by "preserving" newlines before they're put into the document --
+# converting them to the XHTML whitespace escape code, <tt>&#x000A;</tt>.
+# Then Haml won't try to re-format the indentation.
+#
+# Literal +textarea+ and +pre+ tags automatically preserve their content.
+# Dynamically can't be caught automatically,
+# and so should be passed through Haml::Helpers#find_and_preserve or the <tt>~</tt> command,
+# which has the same effect (see above).
+#
+# Blocks of literal text can be preserved using the :preserve filter (see above).
+#
+# === Helpers
+#
+# Haml offers a bunch of helpers that are useful
+# for doing stuff like preserving whitespace,
+# 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.
+# Available options are:
+#
+# [<tt>:output</tt>] Determines the output format. The default is :xhtml.
+# Other options are :html4 and :html5, which are
+# identical to :xhtml except there are no self-closing tags,
+# XML prolog is ignored and correct DOCTYPEs are generated.
+#
+# [<tt>:escape_html</tt>] Sets whether or not to escape HTML-sensitive characters in script.
+# If this is true, = behaves like &=;
+# otherwise, it behaves like !=.
+# <b>Note that this escapes tag attributes.</b>
+# Defaults to false.
+#
+# [<tt>:suppress_eval</tt>] Whether or not attribute hashes and Ruby scripts
+# 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
+# (e.g. by replacing them with <tt>&apos;</tt>) if
+# the character is an apostrophe or a quotation mark.
+#
+# [<tt>:filename</tt>] The name of the Haml file being parsed.
+# This is only used as information when exceptions are raised.
+# This is automatically assigned when working through ActionView,
+# so it's really only useful for the user to assign
+# when dealing with Haml programatically.
+#
+# [<tt>:line</tt>] The line offset of the Haml template being parsed.
+# This is useful for inline templates,
+# similar to the last argument to Kernel#eval.
+#
+# [<tt>:autoclose</tt>] A list of tag names that should be automatically self-closed
+# if they have no content.
+# Defaults to <tt>['meta', 'img', 'link', 'br', 'hr', 'input', 'area', 'param', 'col', 'base']</tt>.
+#
+# [<tt>:preserve</tt>] A list of tag names that should automatically have their newlines preserved
+# using the Haml::Helpers#preserve helper.
+# This means that any content given on the same line as the tag will be preserved.
+# For example:
+#
+# %textarea= "Foo\nBar"
+#
+# compiles to:
+#
+# <textarea>Foo&&#x000A;Bar</textarea>
+#
+# Defaults to <tt>['textarea', 'pre']</tt>.
+#
+# See also Whitespace Preservation, above.
+#
+module Haml
+ # Returns a hash representing the version of Haml.
+ # The :major, :minor, and :teeny keys have their respective numbers.
+ # The :string key contains a human-readable string representation of the version.
+ # If Haml is checked out from Git,
+ # the :rev key will have the revision hash.
+ def self.version
+ return @@version if defined?(@@version)
+
+ numbers = File.read(scope('VERSION')).strip.split('.').map { |n| n.to_i }
+ @@version = {
+ :major => numbers[0],
+ :minor => numbers[1],
+ :teeny => numbers[2]
+ }
+ @@version[:string] = [:major, :minor, :teeny].map { |comp| @@version[comp] }.compact.join('.')
+
+ if File.exists?(scope('REVISION'))
+ rev = File.read(scope('REVISION')).strip
+ rev = nil if rev !~ /[a-f0-9]+/
+ end
+
+ if rev.nil? && File.exists?(scope('.git/HEAD'))
+ rev = File.read(scope('.git/HEAD')).strip
+ if rev =~ /^ref: (.*)$/
+ rev = File.read(scope(".git/#{$1}")).strip
+ end
+ end
+
+ if rev
+ @@version[:rev] = rev
+ @@version[:string] << "." << rev[0...7]
+ end
+
+ @@version
+ end
+
+ # Returns the path of file relative to the Haml root.
+ def self.scope(file) # :nodoc:
+ File.join(File.dirname(__FILE__), '..', file)
+ end
+
+ # A string representing the version of Haml.
+ # A more fine-grained representation is generated by Haml.version.
+ VERSION = version[:string] unless defined?(Haml::VERSION)
+
+ # This method is called by init.rb,
+ # which is run by Rails on startup.
+ # We use it rather than putting stuff straight into init.rb
+ # so we can change the initialization behavior
+ # without modifying the file itself.
+ def self.init_rails(binding)
+ %w[haml/template sass sass/plugin].each(&method(:require))
+ end
+end
+
+require 'haml/engine'
View
236 vendor/plugins/haml/lib/haml/buffer.rb
@@ -0,0 +1,236 @@
+module Haml
+ # This class is used only internally. It holds the buffer of XHTML that
+ # is eventually output by Haml::Engine's to_html method. It's called
+ # from within the precompiled code, and helps reduce the amount of
+ # processing done within instance_eval'd code.
+ class Buffer
+ include Haml::Helpers
+
+ # The string that holds the compiled XHTML. This is aliased as
+ # _erbout for compatibility with ERB-specific code.
+ attr_accessor :buffer
+
+ # The options hash passed in from Haml::Engine.
+ attr_accessor :options
+
+ # The Buffer for the enclosing Haml document.
+ # This is set for partials and similar sorts of nested templates.
+ # It's nil at the top level (see #toplevel?).
+ attr_accessor :upper
+
+ # See #active?
+ attr_writer :active
+
+ # True if the format is XHTML
+ def xhtml?
+ not html?
+ end
+
+ # True if the format is any flavor of HTML
+ def html?
+ html4? or html5?
+ end
+
+ # True if the format is HTML4
+ def html4?
+ @options[:format] == :html4
+ end
+
+ # True if the format is HTML5
+ def html5?
+ @options[:format] == :html5
+ end
+
+ # True if this buffer is a top-level template,
+ # as opposed to a nested partial.
+ def toplevel?
+ upper.nil?
+ end
+
+ # True if this buffer is currently being used to render a Haml template.
+ # However, this returns false if a subtemplate is being rendered,
+ # even if it's a subtemplate of this buffer's template.
+ def active?
+ @active
+ end
+
+ # Gets the current tabulation of the document.
+ def tabulation
+ @real_tabs + @tabulation
+ end
+
+ # Sets the current tabulation of the document.
+ def tabulation=(val)
+ val = val - @real_tabs
+ @tabulation = val > -1 ? val : 0
+ end
+
+ # Creates a new buffer.
+ def initialize(upper = nil, options = {})
+ @active = true
+ @upper = upper
+ @options = {
+ :attr_wrapper => "'",
+ :ugly => false,
+ :format => :xhtml
+ }.merge options
+ @buffer = ""
+ @tabulation = 0
+
+ # The number of tabs that Engine thinks we should have
+ # @real_tabs + @tabulation is the number of tabs actually output
+ @real_tabs = 0
+ end
+
+ # Renders +text+ with the proper tabulation. This also deals with
+ # making a possible one-line tag one line or not.
+ def push_text(text, dont_tab_up = false, tab_change = 0)
+ if @tabulation > 0 && !@options[:ugly]
+ # Have to push every line in by the extra user set tabulation.
+ # Don't push lines with just whitespace, though,
+ # because that screws up precompiled indentation.
+ text.gsub!(/^(?!\s+$)/m, tabs)
+ text.sub!(tabs, '') if dont_tab_up
+ end
+
+ @buffer << text
+ @real_tabs += tab_change
+ @dont_tab_up_next_line = false
+ end
+
+ # Properly formats the output of a script that was run in the
+ # instance_eval.
+ def push_script(result, preserve_script, in_tag = false, preserve_tag = false,
+ escape_html = false, nuke_inner_whitespace = false)
+ tabulation = @real_tabs
+
+ if preserve_tag
+ result = Haml::Helpers.preserve(result)
+ elsif preserve_script
+ result = Haml::Helpers.find_and_preserve(result, options[:preserve])
+ end
+
+ result = result.to_s.rstrip
+ result = html_escape(result) if escape_html
+
+ has_newline = result.include?("\n")
+ if in_tag && (@options[:ugly] || !has_newline || preserve_tag)
+ @buffer << result
+ @real_tabs -= 1
+ return
+ end
+
+ @buffer << "\n" if in_tag && !nuke_inner_whitespace
+
+ # Precompiled tabulation may be wrong
+ if @tabulation > 0 && !in_tag
+ result = tabs + result
+ end
+
+ if has_newline && !@options[:ugly]
+ result = result.gsub "\n", "\n" + tabs(tabulation)
+
+ # Add tabulation if it wasn't precompiled
+ result = tabs(tabulation) + result if in_tag && !nuke_inner_whitespace
+ end
+ @buffer << "#{result}"
+ @buffer << "\n" unless nuke_inner_whitespace
+
+ if in_tag && !nuke_inner_whitespace
+ # We never get here if @options[:ugly] is true
+ @buffer << tabs(tabulation-1)
+ @real_tabs -= 1
+ end
+ nil
+ end
+
+ # Takes the various information about the opening tag for an
+ # element, formats it, and adds it to the buffer.
+ def open_tag(name, self_closing, try_one_line, preserve_tag, escape_html, class_id,
+ nuke_outer_whitespace, nuke_inner_whitespace, 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) }
+ self.class.merge_attrs(attributes, attributes_hash)
+ end
+ self.class.merge_attrs(attributes, parse_object_ref(obj_ref)) if obj_ref
+
+ if self_closing
+ str = " />" + (nuke_outer_whitespace ? "" : "\n")
+ else
+ str = ">" + (try_one_line || preserve_tag || nuke_inner_whitespace ? "" : "\n")
+ end
+
+ attributes = Precompiler.build_attributes(html?, @options[:attr_wrapper], attributes)
+ @buffer << "#{nuke_outer_whitespace || @options[:ugly] ? '' : tabs(tabulation)}<#{name}#{attributes}#{str}"
+
+ if content
+ @buffer << "#{content}</#{name}>" << (nuke_outer_whitespace ? "" : "\n")
+ return
+ end
+
+ @real_tabs += 1 unless self_closing || nuke_inner_whitespace
+ end
+
+ def self.merge_attrs(to, from)
+ if to['id'] && from['id']
+ to['id'] << '_' << from.delete('id')
+ elsif to['id'] || from['id']
+ from['id'] ||= to['id']
+ end
+
+ if to['class'] && from['class']
+ # Make sure we don't duplicate class names
+ from['class'] = (from['class'].split(' ') | to['class'].split(' ')).join(' ')
+ elsif to['class'] || from['class']
+ from['class'] ||= to['class']
+ end
+
+ to.merge!(from)
+ end
+
+ private
+
+ # Some of these methods are exposed as public class methods
+ # so they can be re-used in helpers.
+
+ @@tab_cache = {}
+ # Gets <tt>count</tt> tabs. Mostly for internal use.
+ def tabs(count = 0)
+ tabs = count + @tabulation
+ @@tab_cache[tabs] ||= ' ' * tabs
+ end
+
+ # Takes an array of objects and uses the class and id of the first
+ # one to create an attributes hash.
+ # The second object, if present, is used as a prefix,
+ # just like you can do with dom_id() and dom_class() in Rails
+ def parse_object_ref(ref)
+ prefix = ref[1]
+ ref = ref[0]
+ # Let's make sure the value isn't nil. If it is, return the default Hash.
+ return {} if ref.nil?
+ class_name = underscore(ref.class)
+ id = "#{class_name}_#{ref.id || 'new'}"
+ if prefix
+ class_name = "#{ prefix }_#{ class_name}"
+ id = "#{ prefix }_#{ id }"
+ end
+
+ {'id' => id, 'class' => class_name}
+ end
+
+ # Changes a word from camel case to underscores.
+ # Based on the method of the same name in Rails' Inflector,
+ # but copied here so it'll run properly without Rails.
+ def underscore(camel_cased_word)
+ camel_cased_word.to_s.gsub(/::/, '_').
+ gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
+ gsub(/([a-z\d])([A-Z])/,'\1_\2').
+ tr("-", "_").
+ downcase
+ end
+ end
+end
View
257 vendor/plugins/haml/lib/haml/engine.rb
@@ -0,0 +1,257 @@
+require 'haml/helpers'
+require 'haml/buffer'
+require 'haml/precompiler'
+require 'haml/filters'
+require 'haml/error'
+
+module Haml
+ # This is the class where all the parsing and processing of the Haml
+ # template is done. It can be directly used by the user by creating a
+ # new instance and calling <tt>to_html</tt> to render the template. For example:
+ #
+ # template = File.read('templates/really_cool_template.haml')
+ # haml_engine = Haml::Engine.new(template)
+ # output = haml_engine.to_html
+ # puts output
+ class Engine
+ include Precompiler
+
+ # Allow reading and writing of the options hash
+ attr :options, true
+
+ # This string contains the source code that is evaluated
+ # to produce the Haml document.
+ attr :precompiled, true
+
+ # True if the format is XHTML
+ def xhtml?
+ not html?
+ end
+
+ # True if the format is any flavor of HTML
+ def html?
+ html4? or html5?
+ end
+
+ # True if the format is HTML4
+ def html4?
+ @options[:format] == :html4
+ end
+
+ # True if the format is HTML5
+ def html5?
+ @options[:format] == :html5
+ end
+
+ # Creates a new instace of Haml::Engine that will compile the given
+ # template string when <tt>render</tt> is called.
+ # See README.rdoc for available options.
+ #
+ #--
+ # When adding options, remember to add information about them
+ # to README.rdoc!
+ #++
+ #
+ def initialize(template, options = {})
+ @options = {
+ :suppress_eval => false,
+ :attr_wrapper => "'",
+
+ # Don't forget to update the docs in lib/haml.rb if you update these
+ :autoclose => %w[meta img link br hr input area param col base],
+ :preserve => %w[textarea pre],
+
+ :filename => '(haml)',
+ :line => 1,
+ :ugly => false,
+ :format => :xhtml,
+ :escape_html => false
+ }
+ @options.merge! options
+
+ unless [:xhtml, :html4, :html5].include?(@options[:format])
+ raise Haml::Error, "Invalid format #{@options[:format].inspect}"
+ end
+
+ @template = template.rstrip #String
+ @to_close_stack = []
+ @output_tabs = 0
+ @template_tabs = 0
+ @index = 0
+ @flat_spaces = -1
+ @newlines = 0
+
+ if @options[:filters]
+ warn <<END
+DEPRECATION WARNING:
+The Haml :filters option is deprecated and will be removed in version 2.1.
+Filters are now automatically registered.
+END
+ end
+
+ precompile
+ rescue Haml::Error
+ $!.backtrace.unshift "#{@options[:filename]}:#{@index + $!.line_offset + @options[:line] - 1}" if @index
+ raise
+ end
+
+ # Processes the template and returns the result as a string.
+ #
+ # +scope+ is the context in which the template is evaluated.
+ # 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
+ # (all prefixed with "haml").
+ # For example:
+ #
+ # s = "foobar"
+ # Haml::Engine.new("%p= upcase").render(s) #=> "<p>FOOBAR</p>"
+ #
+ # # s now extends Haml::Helpers
+ # s.responds_to?(:html_attrs) #=> true
+ #
+ # +locals+ is a hash of local variables to make available to the template.
+ # For example:
+ #
+ # Haml::Engine.new("%p= foo").render(Object.new, :foo => "Hello, world!") #=> "<p>Hello, world!</p>"
+ #
+ # If a block is passed to render,
+ # that block is run when +yield+ is called
+ # within the template.
+ #
+ # Due to some Ruby quirks,
+ # if scope is a Binding or Proc object and a block is given,
+ # the evaluation context may not be quite what the user expects.
+ # In particular, it's equivalent to passing <tt>eval("self", scope)</tt> as scope.
+ # This won't have an effect in most cases,
+ # but if you're relying on local variables defined in the context of scope,
+ # they won't work.
+ def render(scope = Object.new, locals = {}, &block)
+ buffer = Haml::Buffer.new(scope.instance_variable_get('@haml_buffer'), options_for_buffer)
+
+ if scope.is_a?(Binding) || scope.is_a?(Proc)
+ scope_object = eval("self", scope)
+ scope = scope_object.instance_eval{binding} if block_given?
+ else
+ scope_object = scope
+ scope = scope_object.instance_eval{binding}
+ end
+
+ set_locals(locals.merge(:_hamlout => buffer, :_erbout => buffer.buffer), scope, scope_object)
+
+ scope_object.instance_eval do
+ extend Haml::Helpers
+ @haml_buffer = buffer
+ end
+
+ eval(@precompiled, scope, @options[:filename], @options[:line])
+
+ # Get rid of the current buffer
+ scope_object.instance_eval do
+ @haml_buffer = buffer.upper
+ end
+
+ buffer.buffer
+ end
+ alias_method :to_html, :render
+
+ # Returns a proc that, when called,
+ # renders the template and returns the result as a string.
+ #
+ # +scope+ works the same as it does for render.
+ #
+ # The first argument of the returned proc 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.
+ # This is done with the +local_names+ argument.
+ # For example:
+ #
+ # # This works
+ # Haml::Engine.new("%p= foo").render_proc(Object.new, :foo).call :foo => "Hello!"
+ # #=> "<p>Hello!</p>"
+ #
+ # # This doesn't
+ # Haml::Engine.new("%p= foo").render_proc.call :foo => "Hello!"
+ # #=> NameError: undefined local variable or method `foo'
+ #
+ # The proc doesn't take a block;
+ # any yields in the template will fail.
+ def render_proc(scope = Object.new, *local_names)
+ if scope.is_a?(Binding) || scope.is_a?(Proc)
+ scope_object = eval("self", scope)
+ else
+ scope_object = scope
+ scope = scope_object.instance_eval{binding}
+ end
+
+ eval("Proc.new { |*_haml_locals| _haml_locals = _haml_locals[0] || {};" +
+ precompiled_with_ambles(local_names) + "}\n", scope, @options[:filename], @options[:line])
+ end
+
+ # Defines a method on +object+
+ # with the given name
+ # that renders the template and returns the result as a string.
+ #
+ # If +object+ is a class or module,
+ # the method will instead by defined as an instance method.
+ # For example:
+ #
+ # t = Time.now
+ # Haml::Engine.new("%p\n Today's date is\n .date= self.to_s").def_method(t, :render)
+ # t.render #=> "<p>\n Today's date is\n <div class='date'>Fri Nov 23 18:28:29 -0800 2007</div>\n</p>\n"
+ #
+ # 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.
+ # This is done with the +local_names+ argument.
+ # For example:
+ #
+ # # This works
+ # obj = Object.new
+ # Haml::Engine.new("%p= foo").def_method(obj, :render, :foo)
+ # obj.render(:foo => "Hello!") #=> "<p>Hello!</p>"
+ #
+ # # This doesn't
+ # 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
+ # (all prefixed with "haml").
+ def def_method(object, name, *local_names)
+ method = object.is_a?(Module) ? :module_eval : :instance_eval
+
+ object.send(method, "def #{name}(_haml_locals = {}); #{precompiled_with_ambles(local_names)}; end",
+ @options[:filename], @options[:line])
+ end
+
+ private
+
+ def set_locals(locals, scope, scope_object)
+ scope_object.send(:instance_variable_set, '@_haml_locals', locals)
+ set_locals = locals.keys.map { |k| "#{k} = @_haml_locals[#{k.inspect}]" }.join("\n")
+ eval(set_locals, scope)
+ end
+
+ # Returns a hash of options that Haml::Buffer cares about.
+ # This should remain loadable from #inspect.
+ def options_for_buffer
+ {
+ :autoclose => @options[:autoclose],
+ :preserve => @options[:preserve],
+ :attr_wrapper => @options[:attr_wrapper],
+ :ugly => @options[:ugly],
+ :format => @options[:format]
+ }
+ end
+ end
+end
View
23 vendor/plugins/haml/lib/haml/error.rb
@@ -0,0 +1,23 @@
+module Haml
+ # An exception raised by Haml code.
+ class Error < Exception
+ # :stopdoc:
+
+ # By default, an error is taken to refer to the line of the template
+ # that was being processed when the exception was raised.
+ # However, if line_offset is non-zero, it's added to that line number
+ # to get the line to report for the error.
+ attr_reader :line_offset
+
+ def initialize(message = nil, line_offset = 0)
+ super(message)
+ @line_offset = line_offset
+ end
+ # :startdoc:
+ end
+
+ # SyntaxError is the type of exception raised when Haml encounters an
+ # ill-formatted document.
+ # It's not particularly interesting, except in that it includes Haml::Error.
+ class SyntaxError < Haml::Error; end
+end
View
347 vendor/plugins/haml/lib/haml/exec.rb
@@ -0,0 +1,347 @@
+require File.dirname(__FILE__) + '/../haml'
+require 'optparse'
+
+module Haml
+ # This module contains code for working with the
+ # haml, sass, and haml2html executables,
+ # such as command-line parsing stuff.
+ # It shouldn't need to be invoked by client code.
+ module Exec # :nodoc:
+ # A class that encapsulates the executable code
+ # for all three executables.
+ class Generic # :nodoc:
+ def initialize(args)
+ @args = args
+ @options = {}
+ end
+
+ def parse!
+ begin
+ @opts = OptionParser.new(&method(:set_opts))
+ @opts.parse!(@args)
+
+ process_result
+
+ @options
+ rescue Exception => e
+ raise e if e.is_a? SystemExit
+
+ $stderr.print "#{e.class} on line #{get_line e}: " if @options[:trace]
+ $stderr.puts e.message
+
+ e.backtrace[1..-1].each { |t| $stderr.puts " #{t}" } if @options[:trace]
+
+ exit 1
+ end
+ exit 0
+ end
+
+ def to_s
+ @opts.to_s
+ end
+
+ protected
+
+ def get_line(exception)
+ # SyntaxErrors have weird line reporting
+ # when there's trailing whitespace,
+ # which there is for Haml documents.
+ return exception.message.scan(/:(\d+)/)[0] if exception.is_a?(::SyntaxError)
+ exception.backtrace[0].scan(/:(\d+)/)[0]
+ end
+
+ private
+
+ def set_opts(opts)
+ opts.on('-s', '--stdin', :NONE, 'Read input from standard input instead of an input file') do
+ @options[:input] = $stdin
+ end
+
+ opts.on('--trace', :NONE, 'Show a full traceback on error') do
+ @options[:trace] = true
+ end
+
+ opts.on_tail("-?", "-h", "--help", "Show this message") do
+ puts opts
+ exit
+ end
+
+ opts.on_tail("-v", "--version", "Print version") do
+ puts("Haml #{::Haml.version[:string]}")
+ exit
+ end
+ end
+
+ def process_result
+ input, output = @options[:input], @options[:output]
+ input_file, output_file = if input
+ [nil, open_file(ARGV[0], 'w')]
+ else
+ [open_file(ARGV[0]), open_file(ARGV[1], 'w')]
+ end
+
+ input ||= input_file
+ output ||= output_file
+ input ||= $stdin
+ output ||= $stdout
+
+ @options[:input], @options[:output] = input, output
+ end
+
+ def open_file(filename, flag = 'r')
+ return if filename.nil?
+ File.open(filename, flag)
+ end
+ end
+
+ # A class encapsulating the executable functionality
+ # specific to Haml and Sass.
+ class HamlSass < Generic # :nodoc:
+ def initialize(args)
+ super
+ @options[:for_engine] = {}
+ end
+
+ private
+
+ def set_opts(opts)
+ opts.banner = <<END
+Usage: #{@name.downcase} [options] [INPUT] [OUTPUT]
+
+Description:
+ Uses the #{@name} engine to parse the specified template
+ and outputs the result to the specified file.
+
+Options:
+END
+
+ opts.on('--rails RAILS_DIR', "Install Haml and Sass from the Gem to a Rails project") do |dir|
+ original_dir = dir
+
+ dir = File.join(dir, 'vendor', 'plugins')
+
+ unless File.exists?(dir)
+ puts "Directory #{dir} doesn't exist"
+ exit
+ end
+
+ dir = File.join(dir, 'haml')
+
+ if File.exists?(dir)
+ puts "Directory #{dir} already exists."
+ exit
+ end
+
+ begin
+ Dir.mkdir(dir)
+ rescue SystemCallError
+ puts "Cannot create #{dir}"
+ exit
+ end
+
+ File.open(File.join(dir, 'init.rb'), 'w') do |file|
+ file.puts "require 'rubygems'"
+ file << File.read(File.dirname(__FILE__) + "/../../init.rb")
+ end
+
+ puts "Haml plugin added to #{original_dir}"
+ exit
+ end
+
+ opts.on('-c', '--check', "Just check syntax, don't evaluate.") do
+ require 'stringio'
+ @options[:check_syntax] = true
+ @options[:output] = StringIO.new
+ end
+
+ super
+ end
+
+ def process_result
+ super
+ require File.dirname(__FILE__) + "/../#{@name.downcase}"
+ end
+ end
+
+ # A class encapsulating executable functionality
+ # specific to Sass.
+ class Sass < HamlSass # :nodoc: