Module: EL::AceHelpers

Defined in:
lib/el-ace/el-ace.rb

Constant Summary collapse

ASSETS_PATH =
File.expand_path('../../../assets', __FILE__).freeze
ASSETS_EXT =
'.el-ace'.freeze
ASSETS_REGEXP =
/#{Regexp.escape ASSETS_EXT}\Z/.freeze
TAB_SIZES =
%w[2 4].freeze
FONT_SIZES =
%w[10 12 14 16].freeze
THEMES =
Dir[ASSETS_PATH + '/ace/theme-*.js'].map do |e|
  File.basename(e).gsub(/\Atheme\-|\.js\Z/, '')
end.reject {|t| t == 'kr'}.freeze
MODES =
Dir[ASSETS_PATH + '/ace/mode-*.js'].map do |e|
  File.basename(e).gsub(/\Amode\-|\.js\Z/, '')
end.freeze
MODE_MAP =
mode_map.inject({}) do |f,(k,v)|
  f.merge(k => v, k.upcase => v)
end.freeze

Instance Method Summary collapse

Instance Method Details

#normalize_editor_id(smth) ⇒ Object



110
111
112
113
114
115
116
# File 'lib/el-ace/el-ace.rb', line 110

def normalize_editor_id smth
  # removing non-alphanumerics as well as underscores,
  # otherwise Ace does not recognize it as a valid id.
  # also, it is important to add the digest, cause without it
  # all of "ab", "a_b", "a-b" will result in same id
  ('ELAceEditor' << Digest::MD5.hexdigest(smth.to_s) << smth.to_s).gsub(/\W|_/, '').freeze
end

#normalize_snippets(*snippets) ⇒ Object



118
119
120
121
# File 'lib/el-ace/el-ace.rb', line 118

def normalize_snippets *snippets
  snippets = snippets[0].call if snippets[0].is_a?(Proc)
  snippets.compact.flatten.map {|s| s.to_s.gsub("'", '"')}.freeze
end

#stringify_opts(*keys) ⇒ Object



123
124
125
# File 'lib/el-ace/el-ace.rb', line 123

def stringify_opts *keys
  keys.inject([]) {|a,o| (v = @opts[o]) ? a << ('%s: "%s"' % [o,v]) : a}*', '
end