Class: NattyUI::Theme
- Inherits:
-
Object
- Object
- NattyUI::Theme
- Defined in:
- lib/natty-ui/theme.rb
Overview
This chapter needs more documentation.
A theme defines the style of elements.
Defined Under Namespace
Classes: Builder
Class Attribute Summary collapse
-
.current ⇒ Theme
readonly
Currently used theme.
-
.current_name ⇒ Symbol
readonly
Name of currently used theme.
-
.names ⇒ Array<Symbol>
readonly
Names of all registered themes.
Instance Attribute Summary collapse
-
#choice_current_style ⇒ Object
readonly
Returns the value of attribute choice_current_style.
-
#choice_style ⇒ Object
readonly
Returns the value of attribute choice_style.
-
#option_states ⇒ Object
readonly
Returns the value of attribute option_states.
-
#sh_err_style ⇒ Object
readonly
Returns the value of attribute sh_err_style.
-
#sh_out_style ⇒ Object
readonly
Returns the value of attribute sh_out_style.
-
#task_style ⇒ Object
readonly
Returns the value of attribute task_style.
Class Method Summary collapse
-
.description(name) ⇒ String
Get the descrition of a theme.
-
.register(name, description = nil) {|builder| ... } ⇒ Theme
Register a theme.
-
.use(name) ⇒ Symbol
Use a theme.
Instance Method Summary collapse
- #border(value) ⇒ Object
- #defined_borders ⇒ Object
- #defined_marks ⇒ Object
- #heading(index) ⇒ Object
-
#initialize(theme) ⇒ Theme
constructor
A new instance of Theme.
- #mark(value) ⇒ Object
- #section_border(kind) ⇒ Object
Constructor Details
#initialize(theme) ⇒ Theme
Returns a new instance of Theme.
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 |
# File 'lib/natty-ui/theme.rb', line 221 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) @sh_out_style = as_style(theme.sh_out_style) @sh_err_style = as_style(theme.sh_err_style) @sections = create_sections( SectionBorder.create(border(theme.section_border)), theme.section_styles.dup.compare_by_identity ) @option_states = create_option_states end |
Class Attribute Details
.current ⇒ Theme (readonly)
Currently used theme
15 16 17 |
# File 'lib/natty-ui/theme.rb', line 15 def current @current end |
.current_name ⇒ Symbol (readonly)
Name of currently used theme
20 21 22 |
# File 'lib/natty-ui/theme.rb', line 20 def current_name @current_name end |
.names ⇒ Array<Symbol> (readonly)
Names of all registered themes
26 |
# File 'lib/natty-ui/theme.rb', line 26 def names = @ll.keys.sort! |
Instance Attribute Details
#choice_current_style ⇒ Object (readonly)
Returns the value of attribute choice_current_style.
187 188 189 |
# File 'lib/natty-ui/theme.rb', line 187 def choice_current_style @choice_current_style end |
#choice_style ⇒ Object (readonly)
Returns the value of attribute choice_style.
187 188 189 |
# File 'lib/natty-ui/theme.rb', line 187 def choice_style @choice_style end |
#option_states ⇒ Object (readonly)
Returns the value of attribute option_states.
187 188 189 |
# File 'lib/natty-ui/theme.rb', line 187 def option_states @option_states end |
#sh_err_style ⇒ Object (readonly)
Returns the value of attribute sh_err_style.
187 188 189 |
# File 'lib/natty-ui/theme.rb', line 187 def sh_err_style @sh_err_style end |
#sh_out_style ⇒ Object (readonly)
Returns the value of attribute sh_out_style.
187 188 189 |
# File 'lib/natty-ui/theme.rb', line 187 def sh_out_style @sh_out_style end |
#task_style ⇒ Object (readonly)
Returns the value of attribute task_style.
187 188 189 |
# File 'lib/natty-ui/theme.rb', line 187 def task_style @task_style end |
Class Method Details
.description(name) ⇒ String
Get the descrition of a theme.
46 |
# File 'lib/natty-ui/theme.rb', line 46 def description(name) = find(name).first |
.register(name, description = nil) {|builder| ... } ⇒ Theme
Register a theme
54 55 56 57 58 |
# File 'lib/natty-ui/theme.rb', line 54 def register(name, description = nil, &block) raise(ArgumentError, 'block missing') unless block @ll[name.to_sym] = [description&.to_s || name.to_s.capitalize, block] self end |
.use(name) ⇒ Symbol
Use a theme
32 33 34 35 36 37 38 39 40 |
# File 'lib/natty-ui/theme.rb', line 32 def use(name) sel = find(name).last if sel.is_a?(Proc) sel[builder = Builder.new] sel = @ll[name][-1] = builder.build.freeze end @current = sel @current_name = name end |
Instance Method Details
#border(value) ⇒ Object
203 204 205 206 207 208 209 210 211 212 213 214 215 |
# File 'lib/natty-ui/theme.rb', line 203 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_borders ⇒ Object
195 |
# File 'lib/natty-ui/theme.rb', line 195 def defined_borders = @border.keys.sort! |
#defined_marks ⇒ Object
194 |
# File 'lib/natty-ui/theme.rb', line 194 def defined_marks = @mark.keys.sort! |
#heading(index) ⇒ Object
196 |
# File 'lib/natty-ui/theme.rb', line 196 def heading(index) = @heading[index.to_i.clamp(1, 6) - 1] |
#mark(value) ⇒ Object
198 199 200 201 |
# File 'lib/natty-ui/theme.rb', line 198 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
217 218 219 |
# File 'lib/natty-ui/theme.rb', line 217 def section_border(kind) kind.is_a?(Symbol) ? @sections[kind] : @sections[:default] end |