Class: Juli::Visitor::Html::HtmlLine

Inherits:
LineAbsyn::Visitor show all
Includes:
Util, TagHelper
Defined in:
lib/juli/visitor/html.rb

Overview

visits a line of document text and generate:

  • hyperlink on wikiname.

  • hyperlink on url like http://…

  • macro result

Instance Method Summary collapse

Methods included from TagHelper

#content_tag, #tag

Methods included from Util

#camelize, conf, find_template, in_filename, juli_repo, mkdir, out_filename, str_limit, str_trim, to_wikiname, underscore, usage, visitor, visitor_list

Methods inherited from LineAbsyn::Visitor

#visit_node

Constructor Details

#initialize(html_visitor) ⇒ HtmlLine

Returns a new instance of HtmlLine.



62
63
64
# File 'lib/juli/visitor/html.rb', line 62

def initialize(html_visitor)
  @_html_visitor  = html_visitor
end

Instance Method Details

#visit_array(n) ⇒ Object



66
67
68
69
70
# File 'lib/juli/visitor/html.rb', line 66

def visit_array(n)
  n.array.inject('') do |result, n|
    result += n.accept(self)
  end
end

#visit_macro(n) ⇒ Object



90
91
92
93
94
95
96
97
98
# File 'lib/juli/visitor/html.rb', line 90

def visit_macro(n)
  if macro = @_html_visitor.macros[camelize(n.name).to_sym]
    macro.run(*n.rest.split(' '))
  else
    s = "juli ERR: UNKNOWN macro name: '#{n.name}'"
    STDERR.print s, "\n"
    s
  end
end

#visit_string(n) ⇒ Object



72
73
74
# File 'lib/juli/visitor/html.rb', line 72

def visit_string(n)
  n.str
end

#visit_url(n) ⇒ Object



86
87
88
# File 'lib/juli/visitor/html.rb', line 86

def visit_url(n)
  (:a, n.str, :class=>'url', :href=>n.str)
end

#visit_wikiname(n) ⇒ Object



76
77
78
79
80
81
82
83
84
# File 'lib/juli/visitor/html.rb', line 76

def visit_wikiname(n)
  if conf['link_wikiname_on'] == '1st-only' && @_html_visitor.wikiname_visited[n.str]
    n.str
  else
    @_html_visitor.wikiname_visited[n.str] = true
    decoded = Juli::Wiki.decode(n.str)
    (:a, decoded, :class=>'wiki', :href=>decoded + conf['ext'])
  end
end