Class: SublimeDSL::TextMate::Preference::DSLReader

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

Instance Method Summary collapse

Constructor Details

#initialize(file = nil) ⇒ DSLReader

Returns a new instance of DSLReader.



129
130
131
132
133
# File 'lib/sublime_dsl/textmate/preference.rb', line 129

def initialize(file = nil)
  @preferences = []
  @current_pref = 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



139
140
141
142
143
144
145
# File 'lib/sublime_dsl/textmate/preference.rb', line 139

def method_missing(sym, *args, &block)
  if @current_pref
    store_setting sym.to_s, args
  else
    raise Error, "'#{sym}': only 'preferences' blocks are allowed"
  end
end

Instance Method Details

#_preferencesObject



135
136
137
# File 'lib/sublime_dsl/textmate/preference.rb', line 135

def _preferences
  @preferences
end

#highlight_pair(open, close) ⇒ Object



186
187
188
189
# File 'lib/sublime_dsl/textmate/preference.rb', line 186

def highlight_pair(open, close)
  ensure_context __method__
  store_pair 'highlightPairs', open, close
end

#highlight_pairs(string) ⇒ Object



176
177
178
179
# File 'lib/sublime_dsl/textmate/preference.rb', line 176

def highlight_pairs(string)
  ensure_context __method__
  store_pairs 'highlightPairs', string
end

#indented_soft_wrap(options = {}) ⇒ Object



191
192
193
194
195
196
197
198
199
# File 'lib/sublime_dsl/textmate/preference.rb', line 191

def indented_soft_wrap(options = {})
  ensure_context __method__
  match = options.delete(:match)
  format = options.delete(:format)
  match && format or raise Error, "#{__method__} requires 'match' and 'format'"
  options.empty? or warn "#{__method__} options ignored: #{options.inspect}"
  @current_pref.settings['indentedSoftWrap'] =
    { match: _re(match.source), format: format }
end

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



147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/sublime_dsl/textmate/preference.rb', line 147

def preferences(options = {}, &block)
  @current_pref and raise Error, "preferences blocks cannot be nested"
  file = options.delete(:file)
  options.length == 0 and raise Error, 'missing name & scope'
  name = options.keys.first
  scope = options.delete(name)
  options.length == 0 or
    warn "extraneous 'preferences' arguments ignored: #{options.inspect}"
  @current_pref = Preference.new.tap do |p|
    p.name = name
    p.scope = scope
    p.basename = file
  end
  instance_eval(&block)
  @preferences << @current_pref
  @current_pref = nil
end

#shell_variable(name, value) ⇒ Object



165
166
167
168
169
# File 'lib/sublime_dsl/textmate/preference.rb', line 165

def shell_variable(name, value)
  ensure_context __method__
  array = @current_pref.settings['shellVariables'] ||= []
  array << { name: name, value: value }
end

#smart_typing_pair(open, close) ⇒ Object



181
182
183
184
# File 'lib/sublime_dsl/textmate/preference.rb', line 181

def smart_typing_pair(open, close)
  ensure_context __method__
  store_pair 'smartTypingPairs', open, close
end

#smart_typing_pairs(string) ⇒ Object



171
172
173
174
# File 'lib/sublime_dsl/textmate/preference.rb', line 171

def smart_typing_pairs(string)
  ensure_context __method__
  store_pairs 'smartTypingPairs', string
end