Sha256: 5bace5ae1994f16bb34897242acb1921e0b2359047775f6c94cfdd4477812fc8

Contents?: true

Size: 1.89 KB

Versions: 13

Compression:

Stored size: 1.89 KB

Contents

module Juli::Visitor::Html::Helper
  # Helper-class for 'fb_like' helper
  class FbComments < AbstractHelper
    # 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.
    DEFAULT_TEMPLATE =
      '<fb:comments href="%{href}" num_posts="2" width="470">' +
      '</fb:comments>'

    # called on 'juli init' to generate config sample template.
    def self.conf_template
      <<EOM
# Facebook related setup is here.
#
#url_prefix: 'http://YOUR_HOST/juli'
#facebook:
#  like:
#    template:  '#{Juli::Visitor::Html::Helper::FbLike::DEFAULT_TEMPLATE}'
#  comments:
#    template:  '#{DEFAULT_TEMPLATE}'
EOM
    end

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

    # set default value in conf if no .juli/conf defined.
    #
    # Please overwrite this method when this implementation is not your
    # case.
    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

    # called on each parsed document
    def on_root(in_file, root, visitor = nil)
      @in_file  = in_file
    end

    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

  private
    def template
      @fb_conf['comments']['template']
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
juli-2.3.2 lib/juli/visitor/html/helper/fb_comments.rb
juli-2.3.1 lib/juli/visitor/html/helper/fb_comments.rb
juli-2.3.0 lib/juli/visitor/html/helper/fb_comments.rb
juli-2.2.4 lib/juli/visitor/html/helper/fb_comments.rb
juli-2.2.3 lib/juli/visitor/html/helper/fb_comments.rb
juli-2.2.1 lib/juli/visitor/html/helper/fb_comments.rb
juli-2.2.0 lib/juli/visitor/html/helper/fb_comments.rb
juli-2.1.0 lib/juli/visitor/html/helper/fb_comments.rb
juli-2.0.4 lib/juli/visitor/html/helper/fb_comments.rb
juli-2.0.3 lib/juli/visitor/html/helper/fb_comments.rb
juli-2.0.2 lib/juli/visitor/html/helper/fb_comments.rb
juli-2.0.1 lib/juli/visitor/html/helper/fb_comments.rb
juli-2.0.0 lib/juli/visitor/html/helper/fb_comments.rb