Class: Reflexive::CodeRayHtmlEncoder

Inherits:
CodeRay::Encoders::HTML
  • Object
show all
Includes:
RoutingHelpers
Defined in:
lib/reflexive/coderay_html_encoder.rb

Instance Method Summary collapse

Methods included from RoutingHelpers

#apidock_path, #class_method_definition_path, #constant_lookup_path, constant_path, #dashboard_path, #file_path, #instance_method_definition_path, #load_path_lookup_path, #method_call_path, #method_definition_path, #method_documentation_path, #method_path, #new_method_definition_path, new_method_path, #up_path

Instance Method Details

#compile(tokens, options) ⇒ Object



40
41
42
43
44
# File 'lib/reflexive/coderay_html_encoder.rb', line 40

def compile(tokens, options)
  for token in tokens
    token(*token)
  end
end

#token(text, type = :plain, tags = {}) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/reflexive/coderay_html_encoder.rb', line 11

def token(text, type = :plain, tags = {})
  if constant_access = tags[:constant_access]
    name, scope = constant_access.values_at(:name, :scope)
    @out << "<a href='#{ constant_lookup_path(name, scope) }'>"
    super(text, type)
    @out << "</a>"
  elsif type == :meta_scope
    # pass
  elsif type == :content && tags[:load_path]
    @out << "<a href='#{ load_path_lookup_path(text) }'>"
    super(text, type)
    @out << "</a>"
  elsif method_call = tags[:method_call]
    @out << "<a href='#{ method_call_path(method_call) }'>"
    super(text, type)
    @out << "</a>"
  elsif local_variable_assignment = tags[:local_variable_assignment]
    @out << "<span id='lv:#{ local_variable_assignment }'>"
    super(text, type)
    @out << "</span>"
  elsif local_variable_access = tags[:local_variable_access]
    @out << "<a href='#lv:#{ local_variable_access }' class='lva'>"
    super(text, type)
    @out << "</a>"
  else
    super(text, type)
  end
end