Class: Glimmer::CSS::CSSToGlimmerConverter
- Inherits:
-
Object
- Object
- Glimmer::CSS::CSSToGlimmerConverter
- Includes:
- CssParser
- Defined in:
- lib/glimmer/css/css_to_glimmer_converter.rb
Constant Summary collapse
- RULE_KEYWORDS =
%w[rule rul ru r s _]
Instance Attribute Summary collapse
-
#rule_keyword ⇒ Object
readonly
This option specifies if we want to use the default rule keyword or an alias like rul or r.
Instance Method Summary collapse
- #convert(css) ⇒ Object
-
#initialize(rule_keyword: 'rule') ⇒ CSSToGlimmerConverter
constructor
A new instance of CSSToGlimmerConverter.
- #minify(css) ⇒ Object
- #remove_charset(css) ⇒ Object
- #remove_comments(css) ⇒ Object
Constructor Details
#initialize(rule_keyword: 'rule') ⇒ CSSToGlimmerConverter
Returns a new instance of CSSToGlimmerConverter.
35 36 37 38 |
# File 'lib/glimmer/css/css_to_glimmer_converter.rb', line 35 def initialize(rule_keyword: 'rule') @rule_keyword = rule_keyword.to_s validate_rule_keyword end |
Instance Attribute Details
#rule_keyword ⇒ Object (readonly)
This option specifies if we want to use the default rule keyword or an alias like rul or r
33 34 35 |
# File 'lib/glimmer/css/css_to_glimmer_converter.rb', line 33 def rule_keyword @rule_keyword end |
Instance Method Details
#convert(css) ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'lib/glimmer/css/css_to_glimmer_converter.rb', line 40 def convert(css) glimmer = '' glimmer += "require 'glimmer-dsl-css'\n\n" glimmer += "include Glimmer\n\n" glimmer += "style_sheet = css {\n" glimmer += convert_css(css).lines.map { |line| " #{line}" }.join glimmer += "}\n\n" glimmer += "puts style_sheet.to_s\n" end |
#minify(css) ⇒ Object
50 51 52 |
# File 'lib/glimmer/css/css_to_glimmer_converter.rb', line 50 def minify(css) CSSMinifier.instance.convert(css) end |
#remove_charset(css) ⇒ Object
54 55 56 |
# File 'lib/glimmer/css/css_to_glimmer_converter.rb', line 54 def remove_charset(css) css.sub(/@charset[^;]*;/, '') end |
#remove_comments(css) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/glimmer/css/css_to_glimmer_converter.rb', line 58 def remove_comments(css) output = '' comment = false current_two_characters = []; css.chars.each do |character| output << character if !comment current_two_characters.shift if current_two_characters.size == 2 current_two_characters << character if !comment && current_two_characters.join == '/*' comment = true output = output[0...-2] elsif comment && current_two_characters.join == '*/' comment = false end end output end |