Module: Retter::Page::ViewHelper

Includes:
Site
Included in:
Base::ViewContext
Defined in:
lib/retter/page/view_helper.rb

Instance Method Summary collapse

Methods included from Site

#config, #entries, #load, #reset!

Methods included from Configurable

#configurable, #define_configurable_method, #define_instance_shortcut_method

Instance Method Details

#article_path(*args) ⇒ Object



26
27
28
29
30
31
32
33
34
35
# File 'lib/retter/page/view_helper.rb', line 26

def article_path(*args)
  case args.first
  when Date, Time
    article_path_by_date_and_id(*args)
  when Entry::Article
    article_path_by_article(args.first)
  else
    raise TypeError, "wrong argument type #{args.first.class} (expected Date, Time or Retter::Entry::Article)"
  end
end

#article_path_by_article(article) ⇒ Object



54
55
56
# File 'lib/retter/page/view_helper.rb', line 54

def article_path_by_article(article)
  article_path(article.entry.date, article.id)
end

#article_path_by_date_and_id(date, id) ⇒ Object



50
51
52
# File 'lib/retter/page/view_helper.rb', line 50

def article_path_by_date_and_id(date, id)
  date.strftime("/entries/%Y%m%d/#{id}.html")
end

#article_url(*args) ⇒ Object



22
23
24
# File 'lib/retter/page/view_helper.rb', line 22

def article_url(*args)
  URI.parse(config.url) + article_path(*args)
end

#entry_path(*args) ⇒ Object



7
8
9
10
11
12
13
14
15
16
# File 'lib/retter/page/view_helper.rb', line 7

def entry_path(*args)
  case args.first
  when Date, Time
    entry_path_by_date(*args)
  when Entry
    entry_path_by_entry(args.first)
  else
    raise TypeError, "wrong argument type #{args.first.class} (expected Date, Time or Retter::Entry)"
  end
end

#entry_path_by_date(date, id = nil) ⇒ Object



58
59
60
# File 'lib/retter/page/view_helper.rb', line 58

def entry_path_by_date(date, id = nil)
  date.strftime('/entries/%Y%m%d.html') + (id ? "##{id}" : '')
end

#entry_path_by_entry(entry) ⇒ Object



62
63
64
# File 'lib/retter/page/view_helper.rb', line 62

def entry_path_by_entry(entry)
  entry_path(entry.date)
end

#entry_url(*args) ⇒ Object



18
19
20
# File 'lib/retter/page/view_helper.rb', line 18

def entry_url(*args)
  URI.parse(config.url) + entry_path(*args)
end

#render_disqus_comment_form(disqus_shortname = config.disqus_shortname) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/retter/page/view_helper.rb', line 37

def render_disqus_comment_form(disqus_shortname = config.disqus_shortname)
  Haml::Engine.new(<<-HAML).render
#disqus_thread
  :javascript
var disqus_shortname = '#{disqus_shortname}';
(function() {
  var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
  dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js';
  (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
})();
  HAML
end