Class: NattyUI::Theme::Compiled

Inherits:
Object
  • Object
show all
Defined in:
lib/natty-ui/theme.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(theme) ⇒ Compiled

Returns a new instance of Compiled.



199
200
201
202
203
204
205
206
207
208
209
210
211
# File 'lib/natty-ui/theme.rb', line 199

def initialize(theme)
  @heading = create_heading(theme.heading, theme.heading_sytle).freeze
  @border = create_border(theme.border).freeze
  @mark = create_mark(theme.mark).freeze
  @task_style = as_style(theme.task_style)
  @choice_current_style = as_style(theme.choice_current_style)
  @choice_style = as_style(theme.choice_style)
  @sections =
    create_sections(
      SectionBorder.create(border(theme.section_border)),
      theme.section_styles.dup.compare_by_identity
    )
end

Instance Attribute Details

#choice_current_styleObject (readonly)

Returns the value of attribute choice_current_style.



169
170
171
# File 'lib/natty-ui/theme.rb', line 169

def choice_current_style
  @choice_current_style
end

#choice_styleObject (readonly)

Returns the value of attribute choice_style.



169
170
171
# File 'lib/natty-ui/theme.rb', line 169

def choice_style
  @choice_style
end

#task_styleObject (readonly)

Returns the value of attribute task_style.



169
170
171
# File 'lib/natty-ui/theme.rb', line 169

def task_style
  @task_style
end

Instance Method Details

#border(value) ⇒ Object



181
182
183
184
185
186
187
188
189
190
191
192
193
# File 'lib/natty-ui/theme.rb', line 181

def border(value)
  return @border[value] if value.is_a?(Symbol)
  case Text.width(value = value.to_s, bbcode: false)
  when 1
    "#{value * 11}  "
  when 11
    "#{value}  "
  when 13
    value
  else
    @border[:default]
  end
end

#defined_bordersObject



172
# File 'lib/natty-ui/theme.rb', line 172

def defined_borders = @border.keys.sort!

#defined_marksObject



171
# File 'lib/natty-ui/theme.rb', line 171

def defined_marks = @mark.keys.sort!

#heading(index) ⇒ Object



174
# File 'lib/natty-ui/theme.rb', line 174

def heading(index) = @heading[index.to_i.clamp(1, 6) - 1]

#mark(value) ⇒ Object



176
177
178
179
# File 'lib/natty-ui/theme.rb', line 176

def mark(value)
  return @mark[value] if value.is_a?(Symbol)
  (element = Str.new(value, true)).empty? ? @mark[:default] : element
end

#section_border(kind) ⇒ Object



195
196
197
# File 'lib/natty-ui/theme.rb', line 195

def section_border(kind)
  kind.is_a?(Symbol) ? @sections[kind] : @sections[:default]
end