Sha256: e454fe5d8bb0e182450e3961002a0ce88862aa54d332414fd122d9b0fcd34989

Contents?: true

Size: 972 Bytes

Versions: 1

Compression:

Stored size: 972 Bytes

Contents

require "beautiful-css/rule"
require "sass"

module BeautifulCss
  class Engine

    def initialize input
      @input = input
    end

    def scss_to_css scss
      Sass::Engine.new(scss,{:syntax => :scss}).render
    end

    def to_s
      render
    end

    def render
      return nil if @input.nil?

      text = scss_to_css @input
      text = text.gsub( /[\n\r\t]/m, " " )
      text = text.gsub( / +/m, " " )
      text = text.gsub( /\/\*[^*]*\*\//m, " " )
      rules = text.split('}')

      rules = rules.map{|r| Rule.new(r) }

      hash = {}

      ##BUILD
      rules.each do |r|
        r.props.each do |p|
          hash[p] = [] if !( hash.has_key? p)
          r.selectors.each { |s| hash[p].push s }
        end
      end

      ##PRINT
      output = ""
      hash.keys.sort.each do |key|
        output += "\n"
        output += hash[key].join(",\n") + "\n"
        output += key + "\n"
      end

      output.gsub( /: +/, ':' )
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
beautiful-css-0.0.1 lib/beautiful-css/engine.rb