Module: Themizer
- Defined in:
- lib/themizer.rb
Constant Summary collapse
- ARGUMENT_ERROR =
"Themizer: argument error in 'init(args)': "\ "args should be Hash, "\ "args should contain ':themes' key, "\ "args[:themes] should be Array of strings"
- SASS_VAR_TILDA_IMPORTANT =
/(?<sass_var>\$[^\s:~;]*)~(?<important>[^;]*);/
Class Method Summary collapse
- .init(args) ⇒ Object
- .themize(action = :expand, theme = "\"\"", &block) ⇒ Object
- .unthemize(theme = "\"\"", &block) ⇒ Object
Class Method Details
.init(args) ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'lib/themizer.rb', line 8 def init(args) raise ARGUMENT_ERROR unless args.class == Hash raise ARGUMENT_ERROR unless args[:themes] raise ARGUMENT_ERROR unless args[:themes].class == Array raise ARGUMENT_ERROR unless args[:themes].map { |e| e.to_s } == args[:themes] @themes = args[:themes] @debug = args[:debug] || false end |
.themize(action = :expand, theme = "\"\"", &block) ⇒ Object
17 18 19 20 21 22 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 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/themizer.rb', line 17 def themize(action = :expand, theme = "\"\"", &block) return unless block_given? src_erb = _extract_block(block) return unless src_erb _debug(src_erb, "processing block") src_sass = ERB.new(src_erb).result case action when :expand maps, selectors = _mapize(src_sass) = maps unless selectors.strip.empty? # if you add "\"\"" to @themes, sass won't compile # because it cannot iterate through list with empty strings in it # therefore, you have to process unthemed sass separately << (selectors, "\"\"") # apply & sass operator # # ".form { # ... # }" # => # "@each $theme in theme1, theme2 { # #{$theme} { & # ... # } # }" << "\n@each $theme in #{@themes.join(', ')} {" << ".\#{$theme} { & " << (selectors) << "}}" @themes.each do |theme| .gsub!(".#{theme} body", "body.#{theme}") end end when :contract = _contract_tilda(src_sass, theme) end _debug(, "resulting sass") yield.gsub!(src_sass, ) end |
.unthemize(theme = "\"\"", &block) ⇒ Object
63 64 65 |
# File 'lib/themizer.rb', line 63 def unthemize(theme = "\"\"", &block) themize(:contract, theme, &block) end |