Sha256: 1dee2d1842241aea8cb13b83cb554d2034549e66cb4656163952dc179cf82788

Contents?: true

Size: 870 Bytes

Versions: 16

Compression:

Stored size: 870 Bytes

Contents

require 'hamlit/filters/base'

module Hamlit
  module Filters
    class Css < Base
      def compile(lines)
        return compile_xhtml(lines) if options[:format] == :xhtml

        compile_html(lines)
      end

      private

      def compile_html(lines)
        ast = [:haml, :text, compile_lines(lines, indent_width: 2), false]
        ast = [:multi, [:static, "\n"], ast]
        ast = [:html, :tag, 'style', [:html, :attrs], ast]
        ast
      end

      def compile_xhtml(lines)
        attr  = [:html, :attr, 'type', [:static, 'text/css']]
        attrs = [:html, :attrs, attr]

        multi = [:multi, [:static, "\n"]]
        multi << [:static, "  /*<![CDATA[*/\n"]
        multi << [:haml, :text, compile_lines(lines, indent_width: 4)]
        multi << [:static, "  /*]]>*/\n"]

        [:html, :tag, 'style', attrs, multi]
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
hamlit-1.6.7 lib/hamlit/filters/css.rb
hamlit-1.6.6 lib/hamlit/filters/css.rb
hamlit-1.6.5 lib/hamlit/filters/css.rb
hamlit-1.6.4 lib/hamlit/filters/css.rb
hamlit-1.6.3 lib/hamlit/filters/css.rb
hamlit-1.6.2 lib/hamlit/filters/css.rb
hamlit-1.6.1 lib/hamlit/filters/css.rb
hamlit-1.6.0 lib/hamlit/filters/css.rb
hamlit-1.5.9 lib/hamlit/filters/css.rb
hamlit-1.5.8 lib/hamlit/filters/css.rb
hamlit-1.5.7 lib/hamlit/filters/css.rb
hamlit-1.5.6 lib/hamlit/filters/css.rb
hamlit-1.5.5 lib/hamlit/filters/css.rb
hamlit-1.5.4 lib/hamlit/filters/css.rb
hamlit-1.5.3 lib/hamlit/filters/css.rb
hamlit-1.5.2 lib/hamlit/filters/css.rb