Class: HtmlPress::Html
- Inherits:
-
Object
- Object
- HtmlPress::Html
- Defined in:
- lib/html_press/html.rb
Constant Summary collapse
- DEFAULTS =
{ :logger => false, :unquoted_attributes => false, :drop_empty_values => false, :strip_crlf => false, :js_minifier_options => false }
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Html
constructor
A new instance of Html.
- #press(html) ⇒ Object (also: #compile)
Constructor Details
#initialize(options = {}) ⇒ Html
Returns a new instance of Html.
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/html_press/html.rb', line 12 def initialize ( = {}) @options = DEFAULTS.merge() if @options.keys.include? :dump_empty_values @options[:drop_empty_values] = @options.delete(:dump_empty_values) warn "dump_empty_values deprecated use drop_empty_values" end if @options[:logger] && !@options[:logger].respond_to?(:error) raise ArgumentError, 'Logger has no error method' end end |
Instance Method Details
#press(html) ⇒ Object Also known as: compile
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 |
# File 'lib/html_press/html.rb', line 23 def press (html) out = html.respond_to?(:read) ? html.read : html.dup @replacement_hash = 'MINIFYHTML' + Time.now.to_i.to_s @placeholders = [] out = process_ie_conditional_comments out out = process_scripts out out = process_styles out out = process_html_comments out out = process_pres out out = HtmlPress.entities_compressor out out = trim_lines out out = process_block_elements out out = process_textareas out # use newlines before 1st attribute in open tags (to limit line lengths) # out.gsub!(/(<[a-z\-:]+)\s+([^>]+>)/i, "\\1\n\\2") out = process_attributes out out = process_whitespaces out out = fill_placeholders out out end |