Class: SublimeDSL::TextMate::Theme::DSLReader

Inherits:
Object
  • Object
show all
Defined in:
lib/sublime_dsl/textmate/theme/dsl_reader.rb

Instance Method Summary collapse

Constructor Details

#initialize(file = nil) ⇒ DSLReader

Returns a new instance of DSLReader.



9
10
11
12
13
# File 'lib/sublime_dsl/textmate/theme/dsl_reader.rb', line 9

def initialize(file = nil)
  @themes = []
  @current_theme = nil
  instance_eval File.read(file, encoding: 'utf-8'), file if file
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args, &block) ⇒ Object

Raises:



19
20
21
# File 'lib/sublime_dsl/textmate/theme/dsl_reader.rb', line 19

def method_missing(sym, *args, &block)
  raise Error, "'#{sym}' is not a valid Theme DSL statement"
end

Instance Method Details

#_themesObject



15
16
17
# File 'lib/sublime_dsl/textmate/theme/dsl_reader.rb', line 15

def _themes
  @themes
end

#author(value) ⇒ Object



37
38
39
40
# File 'lib/sublime_dsl/textmate/theme/dsl_reader.rb', line 37

def author(value)
  ensure_context __method__
  @current_theme.author = value
end

#base_colors(options = {}) ⇒ Object



51
52
53
54
# File 'lib/sublime_dsl/textmate/theme/dsl_reader.rb', line 51

def base_colors(options = {})
  ensure_context __method__
  @current_theme.base_colors.merge! options
end

#boldObject



23
# File 'lib/sublime_dsl/textmate/theme/dsl_reader.rb', line 23

def bold; 'bold' end

#ensure_context(name) ⇒ Object



79
80
81
# File 'lib/sublime_dsl/textmate/theme/dsl_reader.rb', line 79

def ensure_context(name)
  @current_theme or raise Error, "#{name} is invalid outside a 'theme' block"
end

#italicObject



24
# File 'lib/sublime_dsl/textmate/theme/dsl_reader.rb', line 24

def italic; 'italic' end

#item(name, scope, *attributes) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/sublime_dsl/textmate/theme/dsl_reader.rb', line 56

def item(name, scope, *attributes)
  ensure_context __method__
  item = Item.new(name, scope)
  attributes.each do |a|
    if a.is_a? Hash
      a.each_pair do |k, v|
        if k == :back
          item.background = v
        else
          raise Error, "invalid item option: #{k.inspect} => #{v.inspect}"
        end
      end
    elsif %w(bold italic underline).include?(a)
      item.send "#{a}=", true
    elsif a.start_with? '#'
      item.foreground = a
    else
      raise Error, "invalid item attribute: #{a.inspect}"
    end
  end
  @current_theme.add_item item
end

#license(text) ⇒ Object



47
48
49
# File 'lib/sublime_dsl/textmate/theme/dsl_reader.rb', line 47

def license(text)
  @current_theme.license = text
end

#theme(name, options = {}, &block) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'lib/sublime_dsl/textmate/theme/dsl_reader.rb', line 27

def theme(name, options={}, &block)
  @current_theme and raise Error, "'theme' blocks cannot be nested"
  @current_theme = Theme.new(name)
  @current_theme.basename = options.delete(:file)
  options.empty? or warn "invalid options: #{options.inspect}"
  instance_eval(&block)
  @themes << @current_theme
  @current_theme = nil
end

#underlineObject



25
# File 'lib/sublime_dsl/textmate/theme/dsl_reader.rb', line 25

def underline; 'underline' end

#uuid(value) ⇒ Object



42
43
44
45
# File 'lib/sublime_dsl/textmate/theme/dsl_reader.rb', line 42

def uuid(value)
  ensure_context __method__
  @current_theme.uuid = value
end