Class: CodeSnippets

Inherits:
Object
  • Object
show all
Includes:
REXML
Defined in:
lib/code-snippets.rb

Instance Method Summary collapse

Constructor Details

#initialize(opt = {}) ⇒ CodeSnippets

Returns a new instance of CodeSnippets.



13
14
15
16
# File 'lib/code-snippets.rb', line 13

def initialize(opt={})
  @h = opt[:config]
  load()
end

Instance Method Details

#page(n = '1') ⇒ Object



18
19
20
# File 'lib/code-snippets.rb', line 18

def page(n='1')   
  html_page n
end

#rssObject



34
35
36
# File 'lib/code-snippets.rb', line 34

def rss()
  rss_cached('1') { @blog.page(1) }
end

#rss_tag(tag) ⇒ Object



38
39
40
# File 'lib/code-snippets.rb', line 38

def rss_tag(tag)
  rss_cached(tag) { @blog.tag(tag).page(1) }
end

#rss_user(user) ⇒ Object



42
43
44
# File 'lib/code-snippets.rb', line 42

def rss_user(user)
  rss_cached(user) { @blog.user(user).page(1) }
end

#rss_user_tag(user, tag) ⇒ Object



46
47
48
# File 'lib/code-snippets.rb', line 46

def rss_user_tag(user, tag)
  rss_cached(user+tag) { @blog.user(user).tag(tag).page(1) }
end

#show(id) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/code-snippets.rb', line 50

def show(id)
  
  doc = Document.new('<result><summary/><records/></result>')            
  entry = @blog.entry(id).dup
  doc.root.elements['records'].add entry

  (tags = " [%s]" % entry.text('tags').split(/\s/).join('] [')) if entry.text('tags')
  doc.root.elements['summary'].add Element.new('title').add_text(entry.text('title').to_s + tags)    
  prepare_doc doc
  
  render_html doc, @xsl_doc_single    
end

#tag(tag, n = '1') ⇒ Object



22
23
24
# File 'lib/code-snippets.rb', line 22

def tag(tag, n='1')
  html_tag tag, n
end

#user(user, n = '1') ⇒ Object



26
27
28
# File 'lib/code-snippets.rb', line 26

def user(user, n='1')
  html_user(user, n)
end

#user_tag(user, tag, n = '1') ⇒ Object



30
31
32
# File 'lib/code-snippets.rb', line 30

def user_tag(user, tag, n='1')
  html_user_tag(user, tag, n)
end