Sha256: adbd9574f44359a7fbdc22be2b0eb473e5328057d62bd1f2b79b092bbad685c2

Contents?: true

Size: 863 Bytes

Versions: 36

Compression:

Stored size: 863 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)]
        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

36 entries across 36 versions & 1 rubygems

Version Path
hamlit-1.5.1 lib/hamlit/filters/css.rb
hamlit-1.5.0 lib/hamlit/filters/css.rb
hamlit-1.4.7 lib/hamlit/filters/css.rb
hamlit-1.4.6 lib/hamlit/filters/css.rb
hamlit-1.4.5 lib/hamlit/filters/css.rb
hamlit-1.4.3 lib/hamlit/filters/css.rb
hamlit-1.4.2 lib/hamlit/filters/css.rb
hamlit-1.4.1 lib/hamlit/filters/css.rb
hamlit-1.3.2 lib/hamlit/filters/css.rb
hamlit-1.3.1 lib/hamlit/filters/css.rb
hamlit-1.3.0 lib/hamlit/filters/css.rb
hamlit-1.2.1 lib/hamlit/filters/css.rb
hamlit-1.2.0 lib/hamlit/filters/css.rb
hamlit-1.1.1 lib/hamlit/filters/css.rb
hamlit-1.1.0 lib/hamlit/filters/css.rb
hamlit-1.0.0 lib/hamlit/filters/css.rb
hamlit-0.6.2 lib/hamlit/filters/css.rb
hamlit-0.6.1 lib/hamlit/filters/css.rb
hamlit-0.6.0 lib/hamlit/filters/css.rb
hamlit-0.5.3 lib/hamlit/filters/css.rb