tumblr-themer 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +3 -1
- data/lib/tumblr-themer/server.rb +8 -2
- data/lib/tumblr-themer/tag_helper.rb +7 -0
- data/lib/tumblr-themer/theme.rb +81 -13
- data/lib/tumblr-themer/version.rb +1 -1
- data/theme_template/index.html.tt +1 -8
- data/theme_template/partials/tags.html.tt +8 -0
- metadata +5 -4
data/README.md
CHANGED
data/lib/tumblr-themer/server.rb
CHANGED
@@ -2,13 +2,19 @@ require 'sinatra/base'
|
|
2
2
|
|
3
3
|
class TumblrThemer::Server < Sinatra::Base
|
4
4
|
get '/' do
|
5
|
-
theme = TumblrThemer::Theme.new('.')
|
5
|
+
theme = TumblrThemer::Theme.new('.',params)
|
6
6
|
|
7
7
|
theme.render
|
8
8
|
end
|
9
9
|
|
10
10
|
get '/post/:id' do
|
11
|
-
theme = TumblrThemer::Theme.new('.')
|
11
|
+
theme = TumblrThemer::Theme.new('.',params)
|
12
|
+
theme.render
|
13
|
+
end
|
14
|
+
|
15
|
+
get '/page/:page' do
|
16
|
+
theme = TumblrThemer::Theme.new('.',params)
|
17
|
+
theme.render
|
12
18
|
end
|
13
19
|
|
14
20
|
# start the server if ruby file executed directly
|
@@ -31,6 +31,13 @@ module TumblrThemer::TagHelper
|
|
31
31
|
word
|
32
32
|
end
|
33
33
|
|
34
|
+
# File activesupport/lib/active_support/inflector/methods.rb, line 55
|
35
|
+
def camelize(term)
|
36
|
+
string = term.to_s
|
37
|
+
string = string.sub(/^[a-z\d]*/) { $&.capitalize }
|
38
|
+
string.gsub(/(?:_|(\/))([a-z\d]*)/) { "#{$1}#{$2.capitalize}" }.gsub('/', '::')
|
39
|
+
end
|
40
|
+
|
34
41
|
end
|
35
42
|
|
36
43
|
module ClassMethods
|
data/lib/tumblr-themer/theme.rb
CHANGED
@@ -1,30 +1,38 @@
|
|
1
1
|
class TumblrThemer::Theme
|
2
2
|
include TumblrThemer::TagHelper
|
3
|
-
attr_reader :body
|
3
|
+
attr_reader :body, :params
|
4
4
|
|
5
|
-
def initialize dirname
|
6
|
-
base = File.expand_path(dirname)
|
5
|
+
def initialize dirname, params={}
|
6
|
+
@base = File.expand_path(dirname)
|
7
|
+
@params = params
|
7
8
|
|
8
|
-
@body = File.read(File.join(base,'index.html'))
|
9
|
+
@body = File.read(File.join(@base,'index.html'))
|
9
10
|
@posts = {}
|
10
|
-
Dir[File.join(base,'posts/*.html')].each do |f|
|
11
|
-
basename = File.basename(f).sub(/\.html$/,'')
|
11
|
+
Dir[File.join(@base,'posts/*.html')].each do |f|
|
12
|
+
basename = File.basename(f).sub(/\.html$/,'')
|
12
13
|
html = File.read(f)
|
13
14
|
@posts[basename] = html
|
14
15
|
end
|
15
16
|
|
16
17
|
posts_html = @posts.collect do |basename, html|
|
17
|
-
str = "{block:#{basename
|
18
|
+
str = "{block:#{camelize(basename)}}"
|
18
19
|
str << html
|
19
|
-
str << "{/block:#{basename
|
20
|
+
str << "{/block:#{camelize(basename)}}"
|
20
21
|
end
|
21
22
|
|
22
23
|
@body.gsub!("{PostsCode}",posts_html.join("\n"))
|
24
|
+
|
25
|
+
render_partials
|
23
26
|
end
|
24
27
|
|
25
28
|
def get_data
|
26
29
|
return @post_data if defined?(@post_data)
|
27
|
-
|
30
|
+
if params[:id]
|
31
|
+
data = TumblrThemer::API.all_posts(:id => params[:id])
|
32
|
+
else
|
33
|
+
data = TumblrThemer::API.posts
|
34
|
+
end
|
35
|
+
|
28
36
|
@blog_data = data['blog']
|
29
37
|
@post_data = data['posts']
|
30
38
|
end
|
@@ -37,6 +45,14 @@ class TumblrThemer::Theme
|
|
37
45
|
@blog_data || (get_data && @blog_data)
|
38
46
|
end
|
39
47
|
|
48
|
+
def page
|
49
|
+
if params[:page]
|
50
|
+
params[:page].to_i
|
51
|
+
else
|
52
|
+
1
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
40
56
|
def render
|
41
57
|
html = TumblrThemer::HtmlSnippet.new(@body)
|
42
58
|
|
@@ -67,12 +83,64 @@ class TumblrThemer::Theme
|
|
67
83
|
tag('CopyrightYears') {'2007-2013'}
|
68
84
|
tag('CustomCSS') {''}
|
69
85
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
86
|
+
block('IndexPage') { !boolify(params[:id]) }
|
87
|
+
block('PermalinkPage') { boolify(params[:id]) }
|
88
|
+
block('PostTitle') { boolify(params[:id]) }
|
89
|
+
tag('PostTitle') { "Post Title" }
|
74
90
|
# block('PostSummary') { false }
|
75
91
|
# tag('PostSummary') {''}
|
76
92
|
|
77
93
|
block('Date') { false }
|
94
|
+
|
95
|
+
block('Pagination') { !boolify(params[:id]) }
|
96
|
+
block('PreviousPage') { page > 1 }
|
97
|
+
block('NextPage') { page < 3 }
|
98
|
+
tag('PreviousPage') do
|
99
|
+
if page == 2
|
100
|
+
'/'
|
101
|
+
else
|
102
|
+
"/page/#{page-1}"
|
103
|
+
end
|
104
|
+
end
|
105
|
+
tag('NextPage') { "/page/#{page+1}"}
|
106
|
+
tag('CurrentPage') { page }
|
107
|
+
tag('TotalPages') { 3 }
|
108
|
+
|
109
|
+
block('SubmissionsEnabled') { true }
|
110
|
+
tag('SubmitLabel') { 'Submit' }
|
111
|
+
block('AskEnabled') { true }
|
112
|
+
tag('AskLabel') { 'Ask' }
|
113
|
+
|
114
|
+
|
115
|
+
private
|
116
|
+
|
117
|
+
def render_partials
|
118
|
+
partials = {}
|
119
|
+
Dir[File.join(@base,'partials/*.html')].each do |f|
|
120
|
+
basename = "{partial:"<<camelize(File.basename(f).sub(/\.html$/,''))<<"}"
|
121
|
+
html = File.read(f)
|
122
|
+
partials[basename] = html
|
123
|
+
end
|
124
|
+
|
125
|
+
regex = Regexp.new("{partial:(.+?)}")
|
126
|
+
i=0
|
127
|
+
|
128
|
+
while match = regex.match(@body)
|
129
|
+
if i > 5000
|
130
|
+
raise RecusiveTag, "you probably have a recursive partial, make sure to fix that"
|
131
|
+
else
|
132
|
+
i += 1
|
133
|
+
end
|
134
|
+
|
135
|
+
if html = partials[match[0]]
|
136
|
+
@body.gsub!(match[0],html)
|
137
|
+
else
|
138
|
+
raise UndefinedPartial, "Unknown partial: #{match[1]}, please place in partials/#{underscore(match[1])}.html"
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
class UndefinedPartial < StandardError; end
|
144
|
+
class RecusiveTag < StandardError; end
|
145
|
+
|
78
146
|
end
|
@@ -10,14 +10,7 @@
|
|
10
10
|
<article class="post {PostType}" id="post{PostID}">
|
11
11
|
{PostsCode}
|
12
12
|
|
13
|
-
{
|
14
|
-
<section class="tags">
|
15
|
-
{block:Tags}
|
16
|
-
<a href="{TagURL}" class="tag">#{Tag}</a>
|
17
|
-
{/block:Tags}
|
18
|
-
|
19
|
-
</section>
|
20
|
-
{/block:HasTags}
|
13
|
+
{partial:Tags}
|
21
14
|
</article>
|
22
15
|
{/block:Posts}
|
23
16
|
</div>
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tumblr-themer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-05-
|
12
|
+
date: 2013-05-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: url
|
@@ -146,6 +146,7 @@ files:
|
|
146
146
|
- lib/tumblr-themer/version.rb
|
147
147
|
- theme_template/config.ru.tt
|
148
148
|
- theme_template/index.html.tt
|
149
|
+
- theme_template/partials/tags.html.tt
|
149
150
|
- theme_template/posts/chat.html.cc
|
150
151
|
- theme_template/posts/link.html.tt
|
151
152
|
- theme_template/posts/photo.html.tt
|
@@ -169,7 +170,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
169
170
|
version: '0'
|
170
171
|
segments:
|
171
172
|
- 0
|
172
|
-
hash: -
|
173
|
+
hash: -2563184423870591930
|
173
174
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
174
175
|
none: false
|
175
176
|
requirements:
|
@@ -178,7 +179,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
178
179
|
version: '0'
|
179
180
|
segments:
|
180
181
|
- 0
|
181
|
-
hash: -
|
182
|
+
hash: -2563184423870591930
|
182
183
|
requirements: []
|
183
184
|
rubyforge_project:
|
184
185
|
rubygems_version: 1.8.25
|