Class: Kwartz::CssStyleParser
- Inherits:
-
PresentationLogicParser
- Object
- PresentationLogicParser
- Kwartz::CssStyleParser
- Defined in:
- lib/kwartz/parser.rb
Overview
css style presentation logic parser
example of presentation logic in css style:
/* comment */
#idname, .classname, tagname {
value: @var;
attrs: "class" @classname, "bgcolro" color;
append: @value==item['list'] ? ' checked' : '';
logic: {
@list.each { |item|
_stag
_cont
_etag
}
}
}
Constant Summary
Constants inherited from PresentationLogicParser
PresentationLogicParser::ESCAPE_FLAG_TABLE, PresentationLogicParser::PLOGIC_KEYWORDS
Instance Attribute Summary collapse
-
#mode ⇒ Object
Returns the value of attribute mode.
Attributes inherited from PresentationLogicParser
#column, #error, #linenum, #pos, #token, #value
Instance Method Summary collapse
-
#initialize(*args) ⇒ CssStyleParser
constructor
A new instance of CssStyleParser.
- #parse(input, filename = '') ⇒ Object
Methods inherited from PresentationLogicParser
#escape?, get_class, #getch, #parse_error, register_class, #scan, #scan_block, #scan_ident, #scan_line, #scan_string, #scan_string_dquoted, #scan_string_quoted
Methods included from Assertion
Methods included from CharacterType
#is_alpha, #is_digit, #is_identchar, #is_whitespace
Constructor Details
#initialize(*args) ⇒ CssStyleParser
Returns a new instance of CssStyleParser.
605 606 607 608 |
# File 'lib/kwartz/parser.rb', line 605 def initialize(*args) super @mode = :selector # :selector or :declaration end |
Instance Attribute Details
#mode ⇒ Object
Returns the value of attribute mode.
610 611 612 |
# File 'lib/kwartz/parser.rb', line 610 def mode @mode end |
Instance Method Details
#parse(input, filename = '') ⇒ Object
613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 |
# File 'lib/kwartz/parser.rb', line 613 def parse(input, filename='') reset(input, filename) scan() rulesets = [] while @token == :command # '@import' command = @value case command when '@import' imported_rulesets = parse_import_command() rulesets += imported_rulesets when '@from' # TODO when '@import_pdata' # TODO else raise parse_error("#{command}: unsupported command.") end end while @token == :selector selectors = parse_selectors() unless @token == :'{' raise parse_error("'#{@value}': '{' is expected.") #' end @mode = :declaration _linenum, _column = @linenum, @column ruleset = Ruleset.new(selectors) parse_declaration(ruleset) unless @token raise parse_error("'#{selectors.first}': is not closed by '}'.", _linenum, _column) end @mode = :selector rulesets << ruleset scan() end unless @token == nil raise parse_error("'#{@value}': selector is expected.") end return rulesets end |