teamon-rubber 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +3 -1
- data/Rakefile +1 -1
- data/lib/content.yml.sample +65 -0
- data/lib/rubber.rb +10 -11
- data/lib/server.ru +287 -8
- metadata +3 -2
data/README.textile
CHANGED
data/Rakefile
CHANGED
@@ -0,0 +1,65 @@
|
|
1
|
+
---
|
2
|
+
:entries:
|
3
|
+
- :subject: Lorem ipsum dolor sit amet
|
4
|
+
:content: <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p><EXCERPT><p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
|
5
|
+
:date: 2009-05-08 22:19:41.282848 +02:00
|
6
|
+
:categories: [One, Two, Three]
|
7
|
+
:tags: [Ruby, Merb, Awesome]
|
8
|
+
:comments_allowed: true
|
9
|
+
:comments:
|
10
|
+
- :nick: teamon
|
11
|
+
:date: 2009-05-08 23:19:16.282848 +02:00
|
12
|
+
:content: Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
|
13
|
+
:favicon: http://blog.teamon.eu/files/favicon.png
|
14
|
+
:edit: true
|
15
|
+
:class: owner # owner, jogger, guest, trackback
|
16
|
+
|
17
|
+
- :subject: Consectetur adipisicing elit
|
18
|
+
:content: <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p><EXCERPT><p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
|
19
|
+
:date: 2009-05-08 22:19:41.282848 +02:00
|
20
|
+
:categories: [One, Two, Three]
|
21
|
+
:tags: [Ruby, Merb, Awesome]
|
22
|
+
:comments_allowed: true
|
23
|
+
:comments:
|
24
|
+
- :nick: teamon
|
25
|
+
:date: 2009-05-08 23:19:16.282848 +02:00
|
26
|
+
:content: Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
|
27
|
+
:favicon: http://blog.teamon.eu/files/favicon.png
|
28
|
+
:edit: true
|
29
|
+
:class: owner # owner, jogger, guest, trackback
|
30
|
+
- :nick: ivyl
|
31
|
+
:date: 2009-05-08 23:19:16.282848 +02:00
|
32
|
+
:content: Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
|
33
|
+
:favicon: http://blog.teamon.eu/files/favicon.png
|
34
|
+
:edit: false
|
35
|
+
:class: jogger # owner, jogger, guest, trackback
|
36
|
+
|
37
|
+
:archive:
|
38
|
+
- :name: Maj 2009
|
39
|
+
:entries: 10
|
40
|
+
- :name: Kwiecień 2009
|
41
|
+
:entries: 5
|
42
|
+
|
43
|
+
:categories:
|
44
|
+
- :name: Ruby
|
45
|
+
:entries: 10
|
46
|
+
:sub_level: 0
|
47
|
+
- :name: Merb
|
48
|
+
:entries: 5
|
49
|
+
:sub_level: 1
|
50
|
+
|
51
|
+
:links:
|
52
|
+
- :name: Friends
|
53
|
+
:links: [Dmilith, Ivyl]
|
54
|
+
- :name: Stuff
|
55
|
+
:links: ["Ruby on Rails", "Merb"]
|
56
|
+
|
57
|
+
:pages:
|
58
|
+
- :subject: Consectetur adipisicing elit
|
59
|
+
:content: <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p><EXCERPT><p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
|
60
|
+
- :subject: Lorem ipsum dolor sit amet
|
61
|
+
:content: <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p><EXCERPT><p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
|
data/lib/rubber.rb
CHANGED
@@ -16,9 +16,8 @@ class Rubber
|
|
16
16
|
if File.exists?("config.yml")
|
17
17
|
@config = YAML.load(File.read("config.yml"))
|
18
18
|
else
|
19
|
-
File.open("config.yml", "w") {|f|
|
20
|
-
|
21
|
-
}
|
19
|
+
File.open("config.yml", "w") {|f| f.write YAML.dump({:jabber_id => "your@jabber.id", :password => "secret"}) }
|
20
|
+
File.open("content.yml", "w") {|f| f.write File.read(File.join(File.dirname(__FILE__), "content.yml.sample")) } unless File.exists?("content.yml")
|
22
21
|
puts "Brak pliku config.yml. Przykładowy plik został utworzony."
|
23
22
|
exit
|
24
23
|
end
|
@@ -35,7 +34,7 @@ class Rubber
|
|
35
34
|
usage
|
36
35
|
end
|
37
36
|
end
|
38
|
-
|
37
|
+
|
39
38
|
def server
|
40
39
|
system("thin start -R #{File.join(File.dirname(__FILE__), "server.ru")} -p 1337")
|
41
40
|
end
|
@@ -49,7 +48,7 @@ class Rubber
|
|
49
48
|
Dir.mkdir("files") unless File.exists?("files")
|
50
49
|
@filemap.each do |filename, url|
|
51
50
|
puts "Pobieranie #{filename}"
|
52
|
-
|
51
|
+
|
53
52
|
if confirm(filename)
|
54
53
|
File.open(filename, 'wb') {|f| f.write @agent.get(url).body }
|
55
54
|
end
|
@@ -59,7 +58,7 @@ class Rubber
|
|
59
58
|
Dir.mkdir("strony") unless File.exists?("strony")
|
60
59
|
@pagesmap.each do |filename, url|
|
61
60
|
puts "Pobieranie #{filename}"
|
62
|
-
|
61
|
+
|
63
62
|
if confirm(filename)
|
64
63
|
File.open(filename, 'w') {|f| f.write @agent.get("https://login.jogger.pl#{url}").forms.first.templatesContent }
|
65
64
|
end
|
@@ -87,7 +86,7 @@ class Rubber
|
|
87
86
|
end
|
88
87
|
end
|
89
88
|
end
|
90
|
-
|
89
|
+
|
91
90
|
def confirm(filename)
|
92
91
|
if File.exists?(filename) && @args[1] != '--force'
|
93
92
|
puts "Plik #{filename} istnieje. Nadpisac? [T/N]"
|
@@ -95,7 +94,7 @@ class Rubber
|
|
95
94
|
loop do
|
96
95
|
print "> "
|
97
96
|
res = STDIN.gets.chomp.upcase
|
98
|
-
|
97
|
+
|
99
98
|
if res == "T"
|
100
99
|
return true
|
101
100
|
elsif res == "N"
|
@@ -104,12 +103,12 @@ class Rubber
|
|
104
103
|
puts "Nie czaje..."
|
105
104
|
end
|
106
105
|
end
|
107
|
-
|
106
|
+
|
108
107
|
end
|
109
|
-
|
108
|
+
|
110
109
|
return true
|
111
110
|
end
|
112
|
-
|
111
|
+
|
113
112
|
def get_pagesmap
|
114
113
|
@pagesmap = Hash[*@agent.get('https://login.jogger.pl/templates/edit/').links.select{|e| e.href =~ %r[/templates/edit/\?page_id] }.map {|e| ["strony/#{e.text}.html", e.href]}.flatten]
|
115
114
|
@pagesmap["Szablon wpisów.html"] ='/templates/edit/?file=entries'
|
data/lib/server.ru
CHANGED
@@ -1,9 +1,288 @@
|
|
1
1
|
require 'rack/response'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
|
4
|
+
J = YAML.load(File.read("content.yml"))
|
5
|
+
|
6
|
+
MONTHS = %w(stycznia lutego marca kwietnia maja czerwca lipa sierpnia września pażdziernika listopada grudnia)
|
7
|
+
|
8
|
+
def tag(body, pattern, replacement)
|
9
|
+
body.gsub! %r|<#{pattern}/>|, replacement.to_s
|
10
|
+
body.gsub! %r|&#{pattern};|, replacement.to_s
|
11
|
+
end
|
12
|
+
|
13
|
+
def parse_with_comment(body, comment, counter = 0)
|
14
|
+
tag body, "COMMENT_CLASS", "comment#{(counter % 2)+1}"
|
15
|
+
tag body, "COMMENT_EDIT_HREF", "/edit_me_please"
|
16
|
+
tag body, "COMMENT_NICK", comment[:nick]
|
17
|
+
tag body, "COMMENT_DATE", "#{comment[:date].day} #{MONTHS[comment[:date].month]} #{comment[:date].hour}"
|
18
|
+
tag body, "COMMENT_DATE_DAY", comment[:date].day
|
19
|
+
tag body, "COMMENT_DATE_MONTH", MONTHS[comment[:date].month]
|
20
|
+
tag body, "COMMENT_DATE_YEAR", comment[:date].year
|
21
|
+
tag body, "COMMENT_HOUR", comment[:date].hour
|
22
|
+
tag body, "COMMENT_NUMBER", counter+1
|
23
|
+
tag body, "COMMENT_CONTENT", comment[:content]
|
24
|
+
tag body, "COMMENT_FAVICON", comment[:favicon]
|
25
|
+
tag body, "COMMENT_FAVICON2", comment[:favicon]
|
26
|
+
tag body, "COMMENT_ID", rand(100)
|
27
|
+
tag body, "COMMENT_NICK_CLASS", comment[:class]
|
28
|
+
|
29
|
+
body.gsub!(%r|<COMMENT_FAVICON_EXIST>(.+)</COMMENT_FAVICON_EXIST>|m) { comment[:favicon] ? parse_with_comment($1, comment, counter) : "" }
|
30
|
+
body.gsub!(%r|<COMMENT_FAVICON_NOT_EXIST>(.+)</COMMENT_FAVICON_NOT_EXIST>|m) { comment[:favicon] ? "" : parse_with_comment($1, comment, counter) }
|
31
|
+
body.gsub!(%r|<COMMENT_EDIT_EXIST>(.+)</COMMENT_EDIT_EXIST>|m) { comment[:edit] ? parse_with_comment($1, comment, counter) : "" }
|
32
|
+
end
|
33
|
+
|
34
|
+
def parse_with_entry(body, entry, counter = 0)
|
35
|
+
tag body, "ENTRY_SUBJECT", entry[:subject]
|
36
|
+
tag body, "ENTRY_TITLE", entry[:subject]
|
37
|
+
|
38
|
+
tag body, "ENTRY_DATE", "#{entry[:date].day} #{MONTHS[entry[:date].month]} #{entry[:date].hour}"
|
39
|
+
tag body, "ENTRY_DATE_DAY", entry[:date].day
|
40
|
+
tag body, "ENTRY_DATE_MONTH", MONTHS[entry[:date].month]
|
41
|
+
tag body, "ENTRY_DATE_YEAR", entry[:date].year
|
42
|
+
tag body, "ENTRY_HOUR", entry[:date].hour
|
43
|
+
|
44
|
+
tag body, "ENTRY_ID", rand(100)
|
45
|
+
tag body, "ENTRY_LEVEL", rand(3)
|
46
|
+
|
47
|
+
tag body, "ENTRY_CONTENT", entry[:content].sub(%r|<EXCERPT>|, "")
|
48
|
+
tag body, "ENTRY_CONTENT_LONG", entry[:content].split(%r|<EXCERPT>|).last
|
49
|
+
tag body, "ENTRY_CONTENT_SHORT", entry[:content].split(%r|<EXCERPT>|).first
|
50
|
+
body.gsub!(%r|<ENTRY_CONTENT_SHORT_EXIST>(.+)</ENTRY_CONTENT_SHORT_EXIST>|m) { entry[:content]["<EXCERPT>"] ? parse_with_entry($1, entry) : "" }
|
51
|
+
body.gsub!(%r|<ENTRY_CONTENT_SHORT_NOT_EXIST>(.+)</ENTRY_CONTENT_SHORT_NOT_EXIST>|m) { entry[:content]["<EXCERPT>"] ? "" : parse_with_entry($1, entry) }
|
52
|
+
|
53
|
+
tag body, "ENTRY_COMMENT_HREF", "/entry"
|
54
|
+
tag body, "ENTRY_COMMENT_HREF_DESCR", entry[:comments] ? "#{entry[:comments].size} komentarzy" : "Brak komentarzy"
|
55
|
+
tag body, "ENTRY_CLASS", "entry#{(counter % 2)+1}"
|
56
|
+
entry_counter = 0 if body["ENTRY_CLASS_RESET"]
|
57
|
+
|
58
|
+
body.gsub!(%r|<ENTRY_CATEGORY_BLOCK>(.+)</ENTRY_CATEGORY_BLOCK>|m) do
|
59
|
+
category_block = $1
|
60
|
+
category_counter = -1
|
61
|
+
entry[:categories].map do |category|
|
62
|
+
catbody = category_block.dup
|
63
|
+
category_counter += 1
|
64
|
+
|
65
|
+
tag catbody, "ENTRY_CATEGORY_CLASS", "entrycategory#{(category_counter % 2)+1}"
|
66
|
+
tag catbody, "ENTRY_CATEGORY_HREF", "/za_duzo_bys_chcial"
|
67
|
+
tag catbody, "ENTRY_CATEGORY_HREF_DESCR", category
|
68
|
+
tag catbody, "ENTRY_CATEGORY_TITLE", category
|
69
|
+
catbody.gsub!(%r|<ENTRY_CATEGORY_NOT_LAST>(.+)</ENTRY_CATEGORY_NOT_LAST>|m) { category_counter == entry[:categories].size-1 ? "" : $1 }
|
70
|
+
catbody
|
71
|
+
end.join
|
72
|
+
end
|
73
|
+
|
74
|
+
body.gsub!(%r|<ENTRY_TAG_BLOCK_EXIST>(.+)</ENTRY_TAG_BLOCK_EXIST>|m) { entry[:tags] ? parse_with_entry($1, entry) : "" }
|
75
|
+
body.gsub!(%r|<ENTRY_TAG_BLOCK>(.+)</ENTRY_TAG_BLOCK>|m) do
|
76
|
+
tag_block = $1
|
77
|
+
entry[:tags].map do |t|
|
78
|
+
tagbody = tag_block.dup
|
79
|
+
tag tagbody, "ENTRY_TAG_DESCR", t
|
80
|
+
tagbody
|
81
|
+
end.join
|
82
|
+
end
|
83
|
+
|
84
|
+
tag body, "ENTRY_TRACKBACK_HREF", entry[:trackback]
|
85
|
+
body.gsub!(%r|<ENTRY_TRACKBACK_EXIST>(.+)</ENTRY_TRACKBACK_EXIST>|m) { entry[:trackback] ? parse_with_entry($1, entry) : "" }
|
86
|
+
body.gsub!(%r|<ENTRY_TRACKBACK_NOT_EXIST>(.+)</ENTRY_TRACKBACK_NOT_EXIST>|m) { entry[:trackback] ? "" : parse_with_entry($1, entry) }
|
87
|
+
|
88
|
+
["PREV", "NEXT"].each do |type|
|
89
|
+
p = entry[type.downcase.to_sym]
|
90
|
+
|
91
|
+
body.gsub!(%r|<ENTRY_#{type}_EXIST>(.+)</ENTRY_#{type}_EXIST>|m) { p ? parse_with_entry($1, entry) : "" }
|
92
|
+
body.gsub!(%r|<ENTRY_#{type}_NOT_EXIST>(.+)</ENTRY_#{type}_NOT_EXIST>|m) { p ? "" : parse_with_entry($1, entry) }
|
93
|
+
|
94
|
+
if p
|
95
|
+
tag body, "ENTRY_#{type}_SUBJECT", p[:subject]
|
96
|
+
tag body, "ENTRY_#{type}_TITLE", p[:subject]
|
97
|
+
tag body, "ENTRY_#{type}_CONTENT", p[:content].sub(%r|<EXCERPT>|, "")
|
98
|
+
tag body, "ENTRY_#{type}_CONTENT_SHORT", p[:content].split(%r|<EXCERPT>|).first
|
99
|
+
tag body, "ENTRY_#{type}_DATE", "#{p[:date].day} #{MONTHS[p[:date].month]} #{p[:date].hour}"
|
100
|
+
tag body, "ENTRY_#{type}_HREF", "/entry"
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
body.gsub!(%r|<ENTRY_IS_MINIBLOG>(.+)</ENTRY_IS_MINIBLOG>|m) { entry[:miniblog] ? parse_with_entry($1, entry) : "" }
|
105
|
+
|
106
|
+
body
|
107
|
+
end
|
108
|
+
|
109
|
+
def parse(type, body)
|
110
|
+
body.gsub!(%r|<INCLUDE>(.+)</INCLUDE>|) { parse nil, File.read("files/#{$1}") }
|
111
|
+
|
112
|
+
body.gsub!(%r|<ARCHIVE_BLOCK>(.+)</ARCHIVE_BLOCK>|m) do
|
113
|
+
archive_block = $1
|
114
|
+
archive_counter = -1
|
115
|
+
J[:archive].map do |archive|
|
116
|
+
archive_counter += 1
|
117
|
+
archbody = archive_block.dup
|
118
|
+
|
119
|
+
tag archbody, "ARCHIVE_ENTRIES", archive[:entries]
|
120
|
+
tag archbody, "ARCHIVE_HREF", "/za_duzo_bys_chcial"
|
121
|
+
tag archbody, "ARCHIVE_HREF_DESCR", archive[:name]
|
122
|
+
tag archbody, "ARCHIVE_CLASS", "archive#{(archive_counter % 2)+1}"
|
123
|
+
tag archbody, "ARCHIVE_CURRENT_DESCR", "Maj 2009"
|
124
|
+
archbody.gsub!(%r|<ARCHIVE_NOT_LAST>(.+)</ARCHIVE_NOT_LAST>|m) { archive_counter == J[:archive].size-1 ? "" : $1 }
|
125
|
+
archbody
|
126
|
+
end.join
|
127
|
+
end
|
128
|
+
|
129
|
+
body.gsub!(%r|<CATEGORY_BLOCK>(.+)</CATEGORY_BLOCK>|m) do
|
130
|
+
category_block = $1
|
131
|
+
category_counter = -1
|
132
|
+
J[:categories].map do |category|
|
133
|
+
catbody = category_block.dup
|
134
|
+
category_counter += 1
|
135
|
+
|
136
|
+
tag catbody, "CATEGORY_CLASS", "category#{(category_counter % 2)+1}"
|
137
|
+
tag catbody, "CATEGORY_ENTRIES", category[:entries]
|
138
|
+
tag catbody, "CATEGORY_HREF", "/za_duzo_bys_chcial"
|
139
|
+
tag catbody, "CATEGORY_HREF_DESCR", category[:name]
|
140
|
+
tag catbody, "CATEGORY_TITLE", category[:name]
|
141
|
+
tag catbody, "CATEGORY_ID", category_counter
|
142
|
+
tag catbody, "CATEGORY_LEVEL", rand(6)
|
143
|
+
tag catbody, "CATEGORY_SUB_CLASS", "subcategory#{category[:sub]}"
|
144
|
+
catbody.gsub!(%r|<CATEGORY_NOT_LAST>(.+)</CATEGORY_NOT_LAST>|m) { category_counter == J[:categories].size-1 ? "" : $1 }
|
145
|
+
catbody
|
146
|
+
end.join
|
147
|
+
end
|
148
|
+
|
149
|
+
body.gsub!(%r|<LINK_BLOCK_EXIST>(.+)</LINK_BLOCK_EXIST>|m) { J[:links] ? parse(nil, $1) : "" }
|
150
|
+
|
151
|
+
body.gsub!(%r|<LINK_GROUP_BLOCK>(.+)</LINK_GROUP_BLOCK>|m) do
|
152
|
+
link_group_block = $1
|
153
|
+
link_counter = -1
|
154
|
+
J[:links].map do |link_group|
|
155
|
+
grobody = link_group_block.dup
|
156
|
+
tag grobody, "LINK_GROUP_DESCR", link_group[:name]
|
157
|
+
|
158
|
+
grobody.gsub!(%r|<LINK_BLOCK>(.+)</LINK_BLOCK>|m) do
|
159
|
+
link_block = $1
|
160
|
+
link_group[:links].map do |link|
|
161
|
+
link_counter += 1
|
162
|
+
linkbody = link_block.dup
|
163
|
+
|
164
|
+
tag linkbody, "LINK_HREF", "/za_duzo_bys_chcial"
|
165
|
+
tag linkbody, "LINK_HREF_DESCR", link
|
166
|
+
tag linkbody, "LINK_TITLE", link
|
167
|
+
tag linkbody, "LINK_CLASS", "link#{(link_counter % 2)+1}"
|
168
|
+
link_counter = -1 if linkbody["LINK_CLASS_RESET"]
|
169
|
+
|
170
|
+
linkbody
|
171
|
+
end.join
|
172
|
+
end
|
173
|
+
|
174
|
+
grobody
|
175
|
+
end.join
|
176
|
+
end
|
177
|
+
|
178
|
+
case type
|
179
|
+
when :entries
|
180
|
+
body.gsub!(%r|<ENTRY_BLOCK>(.+)</ENTRY_BLOCK>|m) do
|
181
|
+
entry_block = $1
|
182
|
+
entry_counter = -1
|
183
|
+
J[:entries].map {|entry| parse_with_entry(entry_block.dup, entry, entry_counter += 1) }.join
|
184
|
+
end
|
185
|
+
|
186
|
+
body.gsub!(%r|<PAGE_BLOCK_EXIST>(.+)</PAGE_BLOCK_EXIST>|) { parse(:entries, $1) }
|
187
|
+
body.gsub!(%r|<PAGE_PREV_EXIST>(.+)</PAGE_PREV_EXIST>|) { parse(:entries, $1) }
|
188
|
+
body.gsub!(%r|<PAGE_NEXT_EXIST>(.+)</PAGE_NEXT_EXIST>|) { parse(:entries, $1) }
|
189
|
+
tag body, "PAGE_PREV_HREF", "/prev"
|
190
|
+
tag body, "PAGE_NEXT_HREF", "/next"
|
191
|
+
|
192
|
+
|
193
|
+
when :comments
|
194
|
+
entry = J[:entries].first
|
195
|
+
parse_with_entry(body, entry)
|
196
|
+
|
197
|
+
body.gsub!(%r|<COMMENT_BLOCK>(.+)</COMMENT_BLOCK>|m) do
|
198
|
+
comment_block = $1
|
199
|
+
comment_counter = -1
|
200
|
+
entry[:comments].map do |comment|
|
201
|
+
parse_with_comment(comment_block.dup, comment, comment_counter += 1)
|
202
|
+
end.join
|
203
|
+
end
|
204
|
+
|
205
|
+
body.gsub!(%r|<COMMENT_BLOCK_EXIST>(.+)</COMMENT_BLOCK_EXIST>|m) { entry[:comments] ? parse(:comments, $1) : "" }
|
206
|
+
body.gsub!(%r|<COMMENT_BLOCK_NOT_EXIST>(.+)</COMMENT_BLOCK_NOT_EXIST>|m) { entry[:comments] ? "" : parse(:comments, $1) }
|
207
|
+
body.gsub!(%r|<COMMENT_ALLOWED_BLOCK>(.+)</COMMENT_ALLOWED_BLOCK>|m) { entry[:comments_allowed] ? parse(:comments, $1) : "" }
|
208
|
+
body.gsub!(%r|<COMMENT_NONE_BLOCK>(.+)</COMMENT_NONE_BLOCK>|m) { entry[:comments_allowed] ? "" : parse(:comments, $1) }
|
209
|
+
|
210
|
+
|
211
|
+
|
212
|
+
tag body, "COMMENT_FORM", <<-FORM
|
213
|
+
<form action="[adres_wpisu]?op=addcomm" method="post" id="formcomment">
|
214
|
+
<fieldset>
|
215
|
+
<legend id="formname">Dodaj komentarz</legend>
|
216
|
+
<div class="commrow1">
|
217
|
+
<label id="commnicklab" for="commnickid">Podpis</label>
|
218
|
+
<input type="text" name="commnickid" id="commnickid" value="[Twój_jid]" />
|
219
|
+
</div>
|
220
|
+
<div class="commrow2">
|
221
|
+
<label id="commbodylab" for="commbody">Treść</label>
|
222
|
+
<textarea name="commbody" id="commbody" cols="60" rows="6"></textarea>
|
223
|
+
</div>
|
224
|
+
<div>
|
225
|
+
<input type="submit" name="submit" id="submitcomm" value="Wyślij komentarz " />
|
226
|
+
</div>
|
227
|
+
</fieldset>
|
228
|
+
</form>
|
229
|
+
FORM
|
230
|
+
|
231
|
+
tag body, "COMMENT_FORM2", <<-FORM
|
232
|
+
<form action="/comment.php" method="post">
|
233
|
+
<div>
|
234
|
+
<input type="hidden" name="jid" value="[jid_komentowanego]" />
|
235
|
+
<input type="hidden" name="eid" value="[id_wpisu]" />
|
236
|
+
<input type="hidden" name="startid" value="0" />
|
237
|
+
<input type="hidden" name="op" value="addcomm" />
|
238
|
+
</div>
|
239
|
+
<table>
|
240
|
+
<tr>
|
241
|
+
<td>Podpis:</td>
|
242
|
+
<td><input type="text" name="commnickid" id="commnickid" value="[Twój_jid]" /></td>
|
243
|
+
</tr>
|
244
|
+
<tr>
|
245
|
+
<td>Treść:</td>
|
246
|
+
<td><textarea name="commbody" id="commbody" cols="60" rows="6"></textarea></td>
|
247
|
+
</tr>
|
248
|
+
<tr>
|
249
|
+
<td> </td>
|
250
|
+
<td>
|
251
|
+
<input type="checkbox" name="notifyentry" value="notify" />Śledź ten wątek i powiadom mnie o nowych komentarzach
|
252
|
+
</td>
|
253
|
+
</tr>
|
254
|
+
<tr>
|
255
|
+
<td> </td>
|
256
|
+
<td><input type='submit' name="submit" id="submitcomm" value='Wyślij' /></td>
|
257
|
+
</tr>
|
258
|
+
</table>
|
259
|
+
</form>
|
260
|
+
FORM
|
261
|
+
|
262
|
+
|
263
|
+
body.gsub!(%r|<COMMENT_FORM_BLOCK>(.+)</COMMENT_FORM_BLOCK>|m) { $1 }
|
264
|
+
|
265
|
+
tag body, "COMMENT_FORM_ACTION", "/lawl"
|
266
|
+
tag body, "COMMENT_FORM_BODY", "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
|
267
|
+
tag body, "COMMENT_FORM_CODE", "..."
|
268
|
+
tag body, "COMMENT_FORM_NICKID", "teamon"
|
269
|
+
tag body, "COMMENT_FORM_NICKURL", "http://blog.teamon.eu"
|
270
|
+
|
271
|
+
body.gsub!(%r|<COMMENT_FORM_NOTIFY_START_BLOCK>(.+?)</COMMENT_FORM_NOTIFY_START_BLOCK>|m) { $1 }
|
272
|
+
body.gsub!(%r|<COMMENT_FORM_NOTIFY_STOP_BLOCK>(.+?)</COMMENT_FORM_NOTIFY_STOP_BLOCK>|m) { $1 }
|
273
|
+
body.gsub!(%r|<COMMENT_FORM_NOUSER_BLOCK>(.+?)</COMMENT_FORM_NOUSER_BLOCK>|m) { $1 }
|
274
|
+
body.gsub!(%r|<COMMENT_LOGGED_BLOCK>(.+?)</COMMENT_LOGGED_BLOCK>|) { "" }
|
275
|
+
body.gsub!(%r|<COMMENT_NONE_BLOCK>(.+?)</COMMENT_NONE_BLOCK>|m) { entry[:allowed_comments] ? "" : $1 }
|
276
|
+
|
277
|
+
when :login
|
278
|
+
|
279
|
+
when :page
|
280
|
+
tag body, "PAGE_SUBJECT", J[:pages].first[:subject]
|
281
|
+
tag body, "PAGE_TITLE", J[:pages].first[:subject]
|
282
|
+
tag body, "PAGE_CONTENT", J[:pages].first[:content]
|
283
|
+
else
|
284
|
+
|
285
|
+
end
|
7
286
|
|
8
287
|
body
|
9
288
|
end
|
@@ -16,15 +295,15 @@ app = Proc.new do |env|
|
|
16
295
|
else
|
17
296
|
content = case path
|
18
297
|
when "/"
|
19
|
-
parse File.read("Szablon wpisów.html")
|
298
|
+
parse :entries, File.read("Szablon wpisów.html")
|
20
299
|
when "/entry"
|
21
|
-
parse File.read("Szablon komentarzy.html")
|
300
|
+
parse :comments, File.read("Szablon komentarzy.html")
|
22
301
|
when "/login"
|
23
|
-
parse File.read("Szablon logowanie.html")
|
302
|
+
parse :login, File.read("Szablon logowanie.html")
|
24
303
|
else
|
25
304
|
path = "strony/#{path.gsub('-', ' ').gsub('/', '').capitalize}.html"
|
26
305
|
if File.exists?(path)
|
27
|
-
parse File.read(path)
|
306
|
+
parse :page, File.read(path)
|
28
307
|
else
|
29
308
|
"NotFound"
|
30
309
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: teamon-rubber
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tymon Tobolski
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-05-
|
12
|
+
date: 2009-05-09 00:00:00 -07:00
|
13
13
|
default_executable: rubber
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -45,6 +45,7 @@ files:
|
|
45
45
|
- README.textile
|
46
46
|
- Rakefile
|
47
47
|
- bin/rubber
|
48
|
+
- lib/content.yml.sample
|
48
49
|
- lib/rubber.rb
|
49
50
|
- lib/server.ru
|
50
51
|
has_rdoc: false
|