class SublimeDSL::TextMate::Preference::DSLReader
Public Class Methods
new(file = nil)
click to toggle source
# 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
Public Instance Methods
_preferences()
click to toggle source
# File lib/sublime_dsl/textmate/preference.rb, line 135 def _preferences @preferences end
highlight_pair(open, close)
click to toggle source
# 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)
click to toggle source
# 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 = {})
click to toggle source
# 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
method_missing(sym, *args, &block)
click to toggle source
# 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
preferences(options = {}, &block)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# File lib/sublime_dsl/textmate/preference.rb, line 171 def smart_typing_pairs(string) ensure_context __method__ store_pairs 'smartTypingPairs', string end
Private Instance Methods
_re(s)
click to toggle source
# File lib/sublime_dsl/textmate/preference.rb, line 237 def _re(s) Tools::RegexpWannabe.new(s) end
ensure_context(name)
click to toggle source
# File lib/sublime_dsl/textmate/preference.rb, line 233 def ensure_context(name) @current_pref or raise Error, "#{name} is invalid outside a 'preferences' block" end
store_pair(property, open, close)
click to toggle source
# File lib/sublime_dsl/textmate/preference.rb, line 211 def store_pair(property, open, close) array = @current_pref.settings[property] ||= [] array << [_re(open.source), _re(close.source)] end
store_pairs(property, string)
click to toggle source
# File lib/sublime_dsl/textmate/preference.rb, line 203 def store_pairs(property, string) array = @current_pref.settings[property] ||= [] string.split(/\s+/).each do |pair| pair.length == 2 or raise Error, "invalid pair '#{pair}': only 2 characters allowed" array << pair.split(//) end end
store_setting(name, args)
click to toggle source
# File lib/sublime_dsl/textmate/preference.rb, line 216 def store_setting(name, args) case name when 'uuid', 'bundle_uuid' @current_pref.send "#{name}=", args.first else prop = name.camel_case arg = args.first if prop =~ /symbolTransformation|completionCommand/ arg = arg.lines.map(&:strip).join("\n") else arg = _re(arg.source) if arg.is_a?(Regexp) end @current_pref.settings[prop] = arg end # raise Error, "'#{name}' is not a valid preference" end