Module: Mint::CSS

Defined in:
lib/mint/css.rb

Class Method Summary collapse

Class Method Details

.containerObject



5
6
7
# File 'lib/mint/css.rb', line 5

def self.container
  "container"
end

.mappingsObject

Maps a “DSL” onto actual CSS. Translates this …


Font: Helvetica Margin: 1in Orientation: Landscape

… into something like:

#container {

font-family: Helvetica;
padding-left: 1in;
@page { size: landscape };

}



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/mint/css.rb', line 23

def self.mappings
  { 
    font: "font-family",
    font_size: "font-size",
    font_color: "color",
    color: "color",
    top_margin: "padding-top",
    top: "padding-top",
    bottom_margin: "padding-bottom",
    bottom: "padding-bottom",
    left_margin: "padding-left",
    left: "padding-left",
    right_margin: "padding-right",
    right: "padding-right",
    height: "height",
    width: "width",
    columns: "column-count",
    column_gap: "column-gap",
    orientation: "@page { size: %s }",
    indentation: "p+p { text-indent: %s }",
    indent: "p+p { text-indent: %s }",
    bullet: "li { list-style-type: %s }",
    bullet_image: "li { list-style-image: url(%s) }",
    after_paragraph: "margin-bottom",
    before_paragraph: "margin-top"
  }
end

.parse(style) ⇒ Object



63
64
65
66
67
68
# File 'lib/mint/css.rb', line 63

def self.parse(style)
  css = style.map {|k,v| stylify(k, v) }.join("\n  ")
  container_scope = "##{container}\n  #{css.strip}\n"
  engine = Sass::Engine.new(container_scope)
  engine.silence_sass_warnings { engine.render }
end

.stylify(key, value) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/mint/css.rb', line 51

def self.stylify(key, value)
  selector = mappings[Helpers.symbolize key]

  if selector.nil?
    ""
  elsif selector.include? "%"
    selector % value
  else
    "#{selector || key}: #{value}"
  end
end