Module: Lab42::TagCloud::Compiler

Extended by:
Compiler
Included in:
Compiler
Defined in:
lib/lab42/tag_cloud/compiler.rb

Instance Method Summary collapse

Instance Method Details

#color_value(color_spec) ⇒ Object



8
9
10
11
# File 'lib/lab42/tag_cloud/compiler.rb', line 8

def color_value(color_spec)
  parsed = Colors.parse_color(color_spec)
  Colors.gamma_correct(parsed)
end

#make_css_attributes(color, size, weight = nil) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/lab42/tag_cloud/compiler.rb', line 13

def make_css_attributes(color, size, weight = nil)
  color = "##{color_value(color)}"
  font_size = _normalize_size(size)
  font_weight = _maybe_weight(weight)
  attributes = { color:, font_size: }.merge(font_weight)
  _format_css_attributes(**attributes)
end

#tag_from_object(object, tag: :span, **atts) ⇒ Object



21
22
23
24
25
# File 'lib/lab42/tag_cloud/compiler.rb', line 21

def tag_from_object(object, tag: :span, **atts)
  dsl = object[:dsl] || object.dsl
  tag_text = object[:tag] || object.tag
  "<#{tag} #{_make_html_attributes(dsl, **atts)}>#{tag_text}</#{tag}>"
end