Module: Stylish
- Defined in:
- lib/stylish/color.rb,
lib/stylish.rb,
lib/stylish/core.rb,
lib/stylish/tree.rb,
lib/stylish/image.rb,
lib/stylish/generate.rb,
lib/stylish/background.rb,
lib/stylish/stylesheet.rb,
lib/stylish/formattable.rb
Overview
:nodoc:
Defined Under Namespace
Modules: Formattable, Generate, Tree Classes: Background, Color, Comment, Declaration, Declarations, Image, Rule, Selector, Selectors, Stylesheet
Constant Summary collapse
- STYLISH_PATH =
File.(File.dirname(__FILE__)) + '/stylish/'
- PCT =
Regular expressions matching a percentage, and matching only a percentage.
/-?(0\.)?\d+%/
- PERCENTAGE =
/^#{PCT}$/
- HTML_ELEMENTS =
A list of all valid HTML5 elements. Used primarily in the stylesheet generation DSL as method names.
[:html, :head, :title, :base, :link, :meta, :style, :script, :noscript, :eventsource, :body, :section, :nav, :article, :aside, :header, :footer, :address, :p, :hr, :br, :pre, :dialog, :blockquote, :ol, :ul, :li, :dl, :dt, :dd, :a, :q, :cite, :em, :strong, :small, :mark, :dfn, :abbr, :time, :progress, :meter, :code, :var, :samp, :kbd, :sub, :sup, :span, :i, :b, :bdo, :ruby, :rt, :rp, :ins, :del, :figure, :img, :iframe, :embed, :object, :param, :video, :audio, :source, :canvas, :map, :area, :table, :caption, :colgroup, :col, :tbody, :thead, :tfoot, :tr, :td, :th, :form, :fieldset, :label, :input, :button, :select, :datalist, :optgroup, :option, :textarea, :output, :details, :datagrid, :command, :bb, :menu, :legend, :div, :h1, :h2, :h3, :h4, :h5, :h6]
Class Method Summary collapse
-
.generate(options = {}, &block) ⇒ Object
The generate method is the starting point for the stylesheet generation DSL.
Class Method Details
.generate(options = {}, &block) ⇒ Object
The generate method is the starting point for the stylesheet generation DSL. The method should be passed a block, and the various DSL methods then called within that context, e.g. as follows:
style = Stylish.generate do
body :margin => "1em"
rule ".error" do
p :color => "#f00"
em :font_weight => "bold"
end
end
When serialised, the generated stylesheet would look like this:
body {margin:1em;}
.error p {color:#f00;}
.error em {font-weight:bold;}
Further examples can be found in the example/ directory and in the GenerateTest
class.
-
example/tarski.rb
-
test/generate_test.rb
The options argument is currently unused.
28 29 30 31 32 |
# File 'lib/stylish/generate.rb', line 28 def self.generate( = {}, &block) dsl = Generate::Description.new dsl.instance_eval(&block) dsl.node end |