Sha256: 72dbe418403684901f5cdd5838bc8f545a0a78bfa91b6a81e37a64f9d0f6be22

Contents?: true

Size: 1.34 KB

Versions: 17

Compression:

Stored size: 1.34 KB

Contents

require 'hamlit/concerns/deprecation'
require 'temple/html/pretty'

# NOTE: This does not work and disabled by default.
# Actually on_static is just a workaround. This should be totally rewritten.
# Because pretty mode is not used on production and not so important,
# it is not done for now.
module Hamlit
  module HTML
    class Pretty < Temple::HTML::Pretty
      include Concerns::Deprecation

      def call(exp)
        result = super(exp)
        result << [:static, "\n"] if @added_newline
        result
      end

      def on_static(exp)
        if exp == "\n"
          @added_newline = true
          [:static, '']
        else
          [:static, exp]
        end
      end

      def on_html_tag(name, attrs, content = nil)
        if content.is_a?(Array) && content.first != :multi
          return parse_oneline_tag(name, attrs, content)
        end

        super
      end

      private

      def parse_oneline_tag(name, attrs, content)
        name = name.to_s
        closed = !content || (empty_exp?(content) && (@format == :xml || options[:autoclose].include?(name)))
        result = [:multi, [:static, "<#{name}"], compile(attrs)]
        result << [:static, (closed && @format != :html ? ' /' : '') + '>']
        result << compile(content) if content
        result << [:static, "</#{name}>"] if !closed
        result
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
hamlit-0.5.3 lib/hamlit/html/pretty.rb
hamlit-0.5.2 lib/hamlit/html/pretty.rb
hamlit-0.5.1 lib/hamlit/html/pretty.rb
hamlit-0.5.0 lib/hamlit/html/pretty.rb
hamlit-0.4.3 lib/hamlit/html/pretty.rb
hamlit-0.4.2 lib/hamlit/html/pretty.rb
hamlit-0.4.1 lib/hamlit/html/pretty.rb
hamlit-0.3.4 lib/hamlit/html/pretty.rb
hamlit-0.3.3 lib/hamlit/html/pretty.rb
hamlit-0.3.2 lib/hamlit/html/pretty.rb
hamlit-0.3.1 lib/hamlit/html/pretty.rb
hamlit-0.3.0 lib/hamlit/html/pretty.rb
hamlit-0.2.0 lib/hamlit/html/pretty.rb
hamlit-0.1.3 lib/hamlit/html/pretty.rb
hamlit-0.1.2 lib/hamlit/html/pretty.rb
hamlit-0.1.1 lib/hamlit/html/pretty.rb
hamlit-0.1.0 lib/hamlit/html/pretty.rb