Class: CssTidy::Tidy
- Inherits:
-
Object
- Object
- CssTidy::Tidy
- Defined in:
- lib/modules/css_tidy.rb
Instance Attribute Summary collapse
-
#input_size ⇒ Object
readonly
Returns the value of attribute input_size.
-
#output_size ⇒ Object
readonly
Returns the value of attribute output_size.
Instance Method Summary collapse
-
#initialize ⇒ Tidy
constructor
A new instance of Tidy.
- #optimize(options) ⇒ Object
- #split_lines(compressed_css, line_length) ⇒ Object
- #tidy(css, opts = {}) ⇒ Object
Constructor Details
Instance Attribute Details
#input_size ⇒ Object (readonly)
Returns the value of attribute input_size.
5 6 7 |
# File 'lib/modules/css_tidy.rb', line 5 def input_size @input_size end |
#output_size ⇒ Object (readonly)
Returns the value of attribute output_size.
5 6 7 |
# File 'lib/modules/css_tidy.rb', line 5 def output_size @output_size end |
Instance Method Details
#optimize(options) ⇒ Object
55 56 57 |
# File 'lib/modules/css_tidy.rb', line 55 def optimize() @stylesheet.optimize() end |
#split_lines(compressed_css, line_length) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/modules/css_tidy.rb', line 59 def split_lines(compressed_css, line_length) css = compressed_css.clone # Some source control tools don't like it when files containing lines longer # than, say 8000 characters, are checked in. The linebreak option is used in # that case to split long lines after a specific column. startIndex = 0 index = 0 length = css.length while (index < length) index += 1 if (css[index - 1,1] === '}' && index - startIndex > line_length) css = css.slice(0, index) + "\n" + css.slice(index, length) startIndex = index end end css end |
#tidy(css, opts = {}) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/modules/css_tidy.rb', line 11 def tidy(css, opts={}) @input_size = css.length = { :downcase_selectors => true, :downcase_properties => true, :keep_special_comments => true, # comments that start with a ! :keep_ie5_comment_hack => true, # ie5 comment hack => /*\*/ stuff /**/ :keep_ie7_selector_comments => true, # empty comments in selectors => /**/ used for IE7 hack :keep_selector_comments => false, # other comments in selectors :keep_comments => false, # any other comments :optimize_colors => true, :fix_invalid_colors => false, :optimize_decimals => true, :optimize_zeros => true, :optimize_font_weight => true, :optimize_margin_padding => true, :optimize_filters => true, :optimize_urls => true, :optimize_selectors => false, :format => 0, :line_length => 0, }.merge(opts) @stylesheet = @parser.parse(css) optimize() case [:format] when 1 format = :multi_line else format = :one_line end compressed_css = @stylesheet.to_s(format) if ([:line_length] > 0 && format == :one_line) compressed_css = split_lines(compressed_css, [:line_length]) end @output_size = compressed_css.length compressed_css end |