Class: SublimeDSL::TextMate::Theme::Item
- Inherits:
-
Object
- Object
- SublimeDSL::TextMate::Theme::Item
- Defined in:
- lib/sublime_dsl/textmate/theme/item.rb
Instance Attribute Summary collapse
-
#background ⇒ Object
Returns the value of attribute background.
-
#bold ⇒ Object
Returns the value of attribute bold.
-
#foreground ⇒ Object
Returns the value of attribute foreground.
-
#italic ⇒ Object
Returns the value of attribute italic.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#scope ⇒ Object
readonly
Returns the value of attribute scope.
-
#underline ⇒ Object
Returns the value of attribute underline.
Instance Method Summary collapse
- #colors ⇒ Object
- #font_style ⇒ Object
- #font_style=(string) ⇒ Object
-
#initialize(name, scope) ⇒ Item
constructor
A new instance of Item.
- #to_dsl(colors_hash) ⇒ Object
Constructor Details
#initialize(name, scope) ⇒ Item
Returns a new instance of Item.
13 14 15 16 17 18 19 20 21 |
# File 'lib/sublime_dsl/textmate/theme/item.rb', line 13 def initialize(name, scope) @name = name.nil? || name.empty? ? nil : name @scope = scope.nil? || scope.empty? ? nil : scope.strip.gsub(/\s+/m, ' ') @background = nil @foreground = nil @bold = nil @italic = nil @underline = nil end |
Instance Attribute Details
#background ⇒ Object
Returns the value of attribute background.
10 11 12 |
# File 'lib/sublime_dsl/textmate/theme/item.rb', line 10 def background @background end |
#bold ⇒ Object
Returns the value of attribute bold.
11 12 13 |
# File 'lib/sublime_dsl/textmate/theme/item.rb', line 11 def bold @bold end |
#foreground ⇒ Object
Returns the value of attribute foreground.
10 11 12 |
# File 'lib/sublime_dsl/textmate/theme/item.rb', line 10 def foreground @foreground end |
#italic ⇒ Object
Returns the value of attribute italic.
11 12 13 |
# File 'lib/sublime_dsl/textmate/theme/item.rb', line 11 def italic @italic end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
9 10 11 |
# File 'lib/sublime_dsl/textmate/theme/item.rb', line 9 def name @name end |
#scope ⇒ Object (readonly)
Returns the value of attribute scope.
9 10 11 |
# File 'lib/sublime_dsl/textmate/theme/item.rb', line 9 def scope @scope end |
#underline ⇒ Object
Returns the value of attribute underline.
11 12 13 |
# File 'lib/sublime_dsl/textmate/theme/item.rb', line 11 def underline @underline end |
Instance Method Details
#colors ⇒ Object
48 49 50 |
# File 'lib/sublime_dsl/textmate/theme/item.rb', line 48 def colors [background, foreground].compact end |
#font_style ⇒ Object
31 32 33 34 35 |
# File 'lib/sublime_dsl/textmate/theme/item.rb', line 31 def font_style style = [] %w(bold italic underline).each { |a| style << a if self.send(a) } style.empty? ? nil : style.join(' ') end |
#font_style=(string) ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/sublime_dsl/textmate/theme/item.rb', line 37 def font_style=(string) string.split(/\s+/).each do |attr| case attr when 'bold' then @bold = true when 'italic' then @italic = true when 'underline' then @underline = true else raise Error, "unknown font_style: #{attr.inspect}" end end end |
#to_dsl(colors_hash) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/sublime_dsl/textmate/theme/item.rb', line 52 def to_dsl(colors_hash) scope_arg = scope.to_s.length > 70 ? '<<-SCOPE' : scope.to_s.to_source dsl = '' dsl << "# FIXME: no name:\n" unless name dsl << "# FIXME: no scope:\n" unless scope dsl << "item #{name.to_s.to_source}, #{scope_arg}" dsl << ", #{colors_hash[foreground]}" if foreground dsl << ", bold" if bold dsl << ", italic" if italic dsl << ", underline" if underline dsl << ", back: #{colors_hash[background]}" if background if scope_arg == '<<-SCOPE' dsl << "\n" << scope.wrap.indent(2) dsl << "\nSCOPE" end dsl end |