Sha256: 34a59047456fd411fb49de902a1b01378c55ca2a2a26919780937ff8f690518c

Contents?: true

Size: 906 Bytes

Versions: 3

Compression:

Stored size: 906 Bytes

Contents

require "sass"

module Smurfville
  class TypographyParser
    attr_accessor :typographies, :typography_sass_file

    def initialize(typography_sass_file = Smurfville.typography_sass_file)
      @typographies = {}
      @typography_sass_file = typography_sass_file
    end

    def parse(options = {})
      sass_tree = Sass::Engine.for_file(self.typography_sass_file, options).to_tree
      sass_tree.children.each do | node |
        if node.kind_of?(Sass::Tree::CommentNode) && is_typography_comment?(node)
          parsed_comment = YAML.load node.value.join.gsub!("// ", "")
          self.typographies[parsed_comment["styleguide_typography"]["mixin"]] = parsed_comment["styleguide_typography"]["params"]
        end
      end
    end

    private

      def is_typography_comment?(comment_node)
        comment_node.value.any? { |comment| comment.index("styleguide_typography") }
      end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
smurfville-0.0.6 lib/smurfville/typography_parser.rb
smurfville-0.0.5 lib/smurfville/typography_parser.rb
smurfville-0.0.4 lib/smurfville/typography_parser.rb