code-snippets 0.1.11 → 0.1.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/code-snippets.rb +25 -24
  2. metadata +2 -2
data/lib/code-snippets.rb CHANGED
@@ -15,20 +15,20 @@ class CodeSnippets
15
15
  load()
16
16
  end
17
17
 
18
- def page(n='1')
19
- html_page n
18
+ def page(n='1', logged_in='false')
19
+ html_page n, logged_in
20
20
  end
21
21
 
22
- def tag(tag, n='1')
23
- html_tag tag, n
22
+ def tag(tag, n='1', logged_in='false')
23
+ html_tag tag, n, logged_in
24
24
  end
25
25
 
26
- def user(user, n='1')
27
- html_user(user, n)
26
+ def user(user, n='1', logged_in='false')
27
+ html_user(user, n, logged_in)
28
28
  end
29
29
 
30
- def user_tag(user, tag, n='1')
31
- html_user_tag(user, tag, n)
30
+ def user_tag(user, tag, n='1', logged_in='false')
31
+ html_user_tag(user, tag, n, logged_in)
32
32
  end
33
33
 
34
34
  def rss()
@@ -47,7 +47,7 @@ class CodeSnippets
47
47
  rss_cached(user+tag) { @blog.user(user).tag(tag).page(1) }
48
48
  end
49
49
 
50
- def show(id)
50
+ def show(id, logged_in='false')
51
51
 
52
52
  doc = Document.new('<result><summary/><records/></result>')
53
53
  entry = @blog.entry(id).dup
@@ -57,7 +57,7 @@ class CodeSnippets
57
57
  doc.root.elements['summary'].add Element.new('title').add_text(entry.text('title').to_s + tags)
58
58
  prepare_doc doc
59
59
 
60
- render_html(doc, @xsl_doc_single).to_s
60
+ render_html(doc, @xsl_doc_single, logged_in).to_s
61
61
  end
62
62
 
63
63
  def reload_renderer()
@@ -79,38 +79,38 @@ class CodeSnippets
79
79
 
80
80
  private
81
81
 
82
- def html_page(n)
82
+ def html_page(n, logged_in='false')
83
83
  @args = [n]
84
84
  summary = {title: 'Snippets'}
85
- html_cached(context=@args, summary) { @blog.page(n.to_i) }
85
+ html_cached(context=@args, summary, logged_in) { @blog.page(n.to_i) }
86
86
  end
87
87
 
88
- def html_tag(tag, pg_n)
88
+ def html_tag(tag, pg_n, logged_in='false')
89
89
  @args = [tag, pg_n]
90
90
  summary = {title: tag + ' code', tag: tag}
91
- html_cached(context=@args, summary) { @blog.tag(tag).page(pg_n.to_i) }
91
+ html_cached(context=@args, summary, logged_in) { @blog.tag(tag).page(pg_n.to_i) }
92
92
  end
93
93
 
94
- def html_user(user, pg_n)
94
+ def html_user(user, pg_n, logged_in='false')
95
95
  @args = ['user', user, pg_n]
96
96
  summary = {title: 'Snippets', user: user}
97
- html_cached(context=@args, summary) { @blog.user(user).page(pg_n.to_i) }
97
+ html_cached(context=@args, summary, logged_in) { @blog.user(user).page(pg_n.to_i) }
98
98
  end
99
99
 
100
- def html_user_tag(user, tag, pg_n)
100
+ def html_user_tag(user, tag, pg_n, logged_in='false')
101
101
  @args = ['user', user, 'tag', tag, pg_n]
102
102
  summary = {title: 'Snippets', user: user, tag: tag}
103
- html_cached(context=@args, summary) { @blog.user(user).tag(tag).page(pg_n.to_i) }
103
+ html_cached(context=@args, summary, logged_in) { @blog.user(user).tag(tag).page(pg_n.to_i) }
104
104
  end
105
105
 
106
- def html_cached(context, summary, &b)
106
+ def html_cached(context, summary, logged_in='false', &b)
107
107
  c = context.join
108
108
  @page_cache.read(c) do
109
- view_html(@doc_cache.read(c){b.call}, c, summary).to_s
109
+ view_html(@doc_cache.read(c){b.call}, c, summary, logged_in).to_s
110
110
  end
111
111
  end
112
112
 
113
- def view_html(raw_doc, context, summary)
113
+ def view_html(raw_doc, context, summary, logged_in='false')
114
114
 
115
115
  blk = lambda do
116
116
  page_doc = Document.new(raw_doc.to_s)
@@ -148,7 +148,7 @@ class CodeSnippets
148
148
 
149
149
  xml_doc = context != '1' ? @hc_xml.read(context, &blk) : blk.call
150
150
 
151
- render_html(xml_doc, @xsl_doc)
151
+ render_html(xml_doc, @xsl_doc, logged_in)
152
152
 
153
153
  end
154
154
 
@@ -245,8 +245,9 @@ class CodeSnippets
245
245
 
246
246
  end
247
247
 
248
- def render_html(xml_doc, xsl_doc)
249
- Nokogiri::XSLT(xsl_doc.to_s).transform(Nokogiri::XML(xml_doc.to_s))
248
+ def render_html(xml_doc, xsl_doc, logged_in)
249
+ xsl_params = ['logged_in', logged_in]
250
+ Nokogiri::XSLT(xsl_doc.to_s).transform(Nokogiri::XML(xml_doc.to_s), Nokogiri::XSLT.quote_params(xsl_params))
250
251
  end
251
252
 
252
253
  alias render_rss render_html
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: code-snippets
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.11
4
+ version: 0.1.12
5
5
  platform: ruby
6
6
  authors: []
7
7
 
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-08-30 00:00:00 +01:00
12
+ date: 2010-09-04 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies: []
15
15