PageRenderTime 42ms CodeModel.GetById 18ms app.highlight 21ms RepoModel.GetById 1ms app.codeStats 0ms

/scalate-jruby/src/main/resources/haml-3.0.25/README.md

http://github.com/scalate/scalate
Markdown | 298 lines | 221 code | 77 blank | 0 comment | 0 complexity | c23b131d33e33dcbeaa7141b6ff290e6 MD5 | raw file
  1# Haml and Sass
  2
  3Haml and Sass are templating engines
  4for the two most common types of documents on the web:
  5HTML and CSS, respectively.
  6They are designed to make it both easier and more pleasant
  7to code HTML and CSS documents,
  8by eliminating redundancy,
  9reflecting the underlying structure that the document represents,
 10and providing elegant, easily understandable, and powerful syntax.
 11
 12## Using
 13
 14Haml and Sass can be used from the command line
 15or as part of a Ruby web framework.
 16The first step is to install the gem:
 17
 18    gem install haml
 19
 20After you convert some HTML to Haml or some CSS to Sass,
 21you can run
 22
 23    haml document.haml
 24    sass style.scss
 25
 26to compile them.
 27For more information on these commands, check out
 28
 29    haml --help
 30    sass --help
 31
 32To install Haml and Sass in Rails 2,
 33just add `config.gem "haml"` to `config/environment.rb`.
 34In Rails 3, add `gem "haml"` to your Gemfile instead.
 35and both Haml and Sass will be installed.
 36Views with the `.html.haml` extension will automatically use Haml.
 37Sass is a little more complicated;
 38`.sass` files should be placed in `public/stylesheets/sass`,
 39where they'll be automatically compiled
 40to corresponding CSS files in `public/stylesheets` when needed
 41(the Sass template directory is customizable...
 42see [the Sass reference](http://sass-lang.com/docs/yardoc/file.SASS_REFERENCE.html#template_location-option) for details).
 43
 44For Merb, `.html.haml` views will work without any further modification.
 45To enable Sass, you also need to add a dependency.
 46To do so, just add
 47
 48    dependency "merb-haml"
 49
 50to `config/dependencies.rb` (or `config/init.rb` in a flat/very flat Merb application).
 51Then it'll work just like it does in Rails.
 52
 53Sass can also be used with any Rack-enabled web framework.
 54To do so, just add
 55
 56    require 'sass/plugin/rack'
 57    use Sass::Plugin::Rack
 58
 59to `config.ru`.
 60Then any Sass files in `public/stylesheets/sass`
 61will be compiled CSS files in `public/stylesheets` on every request.
 62
 63To use Haml and Sass programatically,
 64check out the [YARD documentation](http://haml-lang.com/docs/yardoc/).
 65
 66## Formatting
 67
 68### Haml
 69
 70The most basic element of Haml
 71is a shorthand for creating HTML:
 72
 73    %tagname{:attr1 => 'value1', :attr2 => 'value2'} Contents
 74
 75No end-tag is needed; Haml handles that automatically.
 76If you prefer HTML-style attributes, you can also use:
 77
 78    %tagname(attr1='value1' attr2='value2') Contents
 79
 80Adding `class` and `id` attributes is even easier.
 81Haml uses the same syntax as the CSS that styles the document:
 82
 83    %tagname#id.class
 84
 85In fact, when you're using the `<div>` tag,
 86it becomes _even easier_.
 87Because `<div>` is such a common element,
 88a tag without a name defaults to a div. So
 89
 90    #foo Hello!
 91
 92becomes
 93
 94    <div id='foo'>Hello!</div>
 95
 96Haml uses indentation
 97to bring the individual elements to represent the HTML structure.
 98A tag's children are indented beneath than the parent tag.
 99Again, a closing tag is automatically added.
100For example:
101
102    %ul
103      %li Salt
104      %li Pepper
105
106becomes:
107
108    <ul>
109      <li>Salt</li>
110      <li>Pepper</li>
111    </ul>
112
113You can also put plain text as a child of an element:
114
115    %p
116      Hello,
117      World!
118
119It's also possible to embed Ruby code into Haml documents.
120An equals sign, `=`, will output the result of the code.
121A hyphen, `-`, will run the code but not output the result.
122You can even use control statements
123like `if` and `while`:
124
125    %p
126      Date/Time:
127      - now = DateTime.now
128      %strong= now
129      - if now > DateTime.parse("December 31, 2006")
130        = "Happy new " + "year!"
131
132Haml provides far more tools than those presented here.
133Check out the [reference documentation](http://beta.haml-lang.com/docs/yardoc/file.HAML_REFERENCE.html)
134for full details.
135
136#### Indentation
137
138Haml's indentation can be made up of one or more tabs or spaces.
139However, indentation must be consistent within a given document.
140Hard tabs and spaces can't be mixed,
141and the same number of tabs or spaces must be used throughout.
142
143### Sass
144
145Sass is an extension of CSS
146that adds power and elegance to the basic language.
147It allows you to use [variables][vars], [nested rules][nested],
148[mixins][mixins], [inline imports][imports],
149and more, all with a fully CSS-compatible syntax.
150Sass helps keep large stylesheets well-organized,
151and get small stylesheets up and running quickly,
152particularly with the help of
153[the Compass style library](http://compass-style.org).
154
155[vars]:    http://beta.sass-lang.com/docs/yardoc/file.SASS_REFERENCE.html#variables_
156[nested]:  http://beta.sass-lang.com/docs/yardoc/file.SASS_REFERENCE.html#nested_rules_
157[mixins]:  http://beta.sass-lang.com/docs/yardoc/file.SASS_REFERENCE.html#mixins
158[imports]: http://beta.sass-lang.com/docs/yardoc/file.SASS_REFERENCE.html#import
159
160Sass has two syntaxes.
161The one presented here, known as "SCSS" (for "Sassy CSS"),
162is fully CSS-compatible.
163The other (older) syntax, known as the indented syntax or just "Sass",
164is whitespace-sensitive and indentation-based.
165For more information, see the [reference documentation][syntax].
166
167[syntax]: http://beta.sass-lang.com/docs/yardoc/file.SASS_REFERENCE.html#syntax
168
169To run the following examples and see the CSS they produce,
170put them in a file called `test.scss` and run `sass test.scss`.
171
172#### Nesting
173
174Sass avoids repetition by nesting selectors within one another.
175The same thing works for properties.
176
177    table.hl {
178      margin: 2em 0;
179      td.ln { text-align: right; }
180    }
181
182    li {
183      font: {
184        family: serif;
185        weight: bold;
186        size: 1.2em;
187      }
188    }
189
190#### Variables
191
192Use the same color all over the place?
193Need to do some math with height and width and text size?
194Sass supports variables, math operations, and many useful functions.
195
196    $blue: #3bbfce;
197    $margin: 16px;
198
199    .content_navigation {
200      border-color: $blue;
201      color: darken($blue, 10%);
202    }
203
204    .border {
205      padding: $margin / 2;
206      margin: $margin / 2;
207      border-color: $blue;
208    }
209
210#### Mixins
211
212Even more powerful than variables,
213mixins allow you to re-use whole chunks of CSS,
214properties or selectors.
215You can even give them arguments. 
216
217    @mixin table-scaffolding {
218      th {
219        text-align: center;
220        font-weight: bold;
221      }
222      td, th { padding: 2px; }
223    }
224
225    @mixin left($dist) {
226      float: left;
227      margin-left: $dist;
228    }
229
230    #data {
231      @include left(10px);
232      @include table-scaffolding;
233    }
234
235A comprehensive list of features is available
236in the [Sass reference](http://beta.sass-lang.com/docs/yardoc/file.SASS_REFERENCE.html).
237
238## Executables
239
240The Haml gem includes several executables that are useful
241for dealing with Haml and Sass from the command line.
242
243### `haml`
244
245The `haml` executable transforms a source Haml file into HTML.
246See `haml --help` for further information and options.
247
248### `sass`
249
250The `sass` executable transforms a source Sass file into CSS.
251See `sass --help` for further information and options.
252
253### `html2haml`
254
255The `html2haml` executable attempts to transform HTML,
256optionally with ERB markup, into Haml code.
257Since HTML is so variable, this transformation is not always perfect;
258it's a good idea to have a human check the output of this tool.
259See `html2haml --help` for further information and options.
260
261### `sass-convert`
262
263The `sass-convert` executable converts between CSS, Sass, and SCSS.
264When converting from CSS to Sass or SCSS,
265nesting is applied where appropriate.
266See `sass-convert --help` for further information and options.
267
268## Authors
269
270Haml and Sass were created by [Hampton Catlin](http://hamptoncatlin.com)
271(hcatlin) and he is the author of the original implementation. However, Hampton
272doesn't even know his way around the code anymore and now occasionally consults
273on the language issues.  Hampton lives in Jacksonville, Florida and is the lead
274mobile developer for Wikimedia.
275
276[Nathan Weizenbaum](http://nex-3.com) is the primary developer and architect of
277the "modern" Ruby implementation of Haml. His hard work has kept the project
278alive by endlessly answering forum posts, fixing bugs, refactoring, finding
279speed improvements, writing documentation, implementing new features, and
280getting Hampton coffee (a fitting task for a boy-genius). Nathan lives in
281Seattle, Washington and while not being a student at the University of
282Washington or working at an internship, he consults for Unspace Interactive.
283
284[Chris Eppstein](http://acts-as-architect.blogspot.com) is a core contributor to
285Sass and the creator of Compass, the first Sass-based framework. Chris focuses
286on making Sass more powerful, easy to use, and on ways to speed its adoption
287through the web development community. Chris lives in San Jose, California with
288his wife and daughter. He is the Software Architect for
289[Caring.com](http://caring.com), a website devoted to the 34 Million caregivers
290whose parents are sick or elderly, that uses Haml and Sass.
291
292If you use this software, you must pay Hampton a compliment. And
293buy Nathan some jelly beans. Maybe pet a kitten. Yeah. Pet that kitty.
294
295Some of the work on Haml was supported by Unspace Interactive.
296
297Beyond that, the implementation is licensed under the MIT License.
298Okay, fine, I guess that means compliments aren't __required__.