Class: Glimmer::LibUI::CustomControl::CodeArea
Constant Summary
collapse
- REGEX_COLOR_HEX6 =
/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/
Instance Attribute Summary
#args, #body_root, #content, #keyword, #libui, #options, #parent, #parent_proxy
Class Method Summary
collapse
Instance Method Summary
collapse
add_custom_control_namespaces_for, after_body, before_body, body, #can_handle_listener?, custom_control_namespaces, custom_controls_being_interpreted, def_option_attr_accessors, flyweight_custom_control_classes, for, #handle_listener, #has_instance_method?, #initialize, keyword, namespaces_for_class, #observer_registrations, option, options, #post_add_content, #post_initialize_child, reset_custom_control_namespaces, shortcut_keyword
Class Method Details
.languages ⇒ Object
29
30
31
32
|
# File 'lib/glimmer/libui/custom_control/code_area.rb', line 29
def languages
require 'rouge'
Rouge::Lexer.all.map {|lexer| lexer.tag}.sort
end
|
.lexers ⇒ Object
34
35
36
37
|
# File 'lib/glimmer/libui/custom_control/code_area.rb', line 34
def lexers
require 'rouge'
Rouge::Lexer.all.sort_by(&:title)
end
|
Instance Method Details
#lexer ⇒ Object
68
69
70
71
72
73
74
|
# File 'lib/glimmer/libui/custom_control/code_area.rb', line 68
def lexer
require 'rouge'
require 'glimmer-dsl-libui/ext/rouge/theme/glimmer'
@lexer ||= Rouge::Lexer.find_fancy(language)
@lexer ||= Rouge::Lexer.find_fancy('ruby') end
|
#syntax_highlighting(text) ⇒ Object
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
# File 'lib/glimmer/libui/custom_control/code_area.rb', line 76
def syntax_highlighting(text)
return [] if text.to_s.strip.empty?
@syntax_highlighting ||= {}
unless @syntax_highlighting.keys.include?(text)
lex = lexer.lex(text).to_a
text_size = 0
@syntax_highlighting[text] = lex.map do |pair|
{token_type: pair.first, token_text: pair.last}
end.each do |hash|
hash[:token_index] = text_size
text_size += hash[:token_text].size
end
end
@syntax_highlighting[text]
end
|