Class: Juli::Visitor::Html::Helper::FbComments

Inherits:
AbstractHelper show all
Defined in:
lib/juli/visitor/html/helper/fb_comments.rb

Overview

Helper-class for ‘fb_like’ helper

Constant Summary collapse

DEFAULT_TEMPLATE =

default HTML template for facebook ‘like’ button. You can customize it in .juli/config facebook.like.template entry.

%href in the template will be replaced to the actual URL of current wiki page.

'<fb:comments href="%{href}" num_posts="2" width="470">' +
'</fb:comments>'

Class Method Summary collapse

Instance Method Summary collapse

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

Constructor Details

#initializeFbComments

Returns a new instance of FbComments.



27
28
29
# File 'lib/juli/visitor/html/helper/fb_comments.rb', line 27

def initialize
  @fb_conf  = conf['facebook']
end

Class Method Details

.conf_templateObject

called on ‘juli init’ to generate config sample template.



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/juli/visitor/html/helper/fb_comments.rb', line 14

def self.conf_template
  "# Facebook related setup is here.\n#\n#url_prefix: 'http://YOUR_HOST/juli'\n#facebook:\n#  like:\n#    template:  '\#{Juli::Visitor::Html::Helper::FbLike::DEFAULT_TEMPLATE}'\n#  comments:\n#    template:  '\#{DEFAULT_TEMPLATE}'\n"
end

Instance Method Details

#on_root(in_file, root, visitor = nil) ⇒ Object

called on each parsed document



51
52
53
# File 'lib/juli/visitor/html/helper/fb_comments.rb', line 51

def on_root(in_file, root, visitor = nil)
  @in_file  = in_file
end

#run(*args) ⇒ Object

Raises:



55
56
57
58
59
60
61
# File 'lib/juli/visitor/html/helper/fb_comments.rb', line 55

def run(*args)
  raise Juli::NoConfig if !conf['url_prefix']
  raise Juli::NoConfig if !@in_file

  template.gsub('%{href}',
      conf['url_prefix'] + '/' + to_wikiname(@in_file) + conf['ext'])
end

#set_conf_default(conf) ⇒ Object

set default value in conf if no .juli/conf defined.

Please overwrite this method when this implementation is not your case.



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/juli/visitor/html/helper/fb_comments.rb', line 35

def set_conf_default(conf)
  conf['url_prefix']  = 'http://YOUR_HOST/juli' if !conf['url_prefix']
  conf['facebook']    = {}                      if !conf['facebook']
  if !conf['facebook']['comments']
    conf['facebook']['comments'] = {
      'template'  => self.class::DEFAULT_TEMPLATE
    }
  end
  if !conf['facebook']['like']
    conf['facebook']['like'] = {
      'template'  => Juli::Visitor::Html::Helper::FbLike::DEFAULT_TEMPLATE
    }
  end
end