teamon-rubber 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENSE +20 -0
- data/README.textile +44 -0
- data/Rakefile +56 -0
- data/bin/rubber +7 -0
- data/lib/rubber.rb +147 -0
- data/lib/server.ru +38 -0
- metadata +77 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Tymon Tobolski
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.textile
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
h2. rubber v. 0.0.1
|
2
|
+
|
3
|
+
Edytor szablonów Joggera
|
4
|
+
|
5
|
+
h3. Instalacja
|
6
|
+
|
7
|
+
<pre><code>
|
8
|
+
gem sources -a http://gems.github.com
|
9
|
+
sudo gem install teamon-rubber
|
10
|
+
</pre></code>
|
11
|
+
|
12
|
+
h3. Inicjalizacja
|
13
|
+
|
14
|
+
<pre><code>
|
15
|
+
mkdir my_jogger
|
16
|
+
cd my_jogger
|
17
|
+
rubber
|
18
|
+
</pre></code>
|
19
|
+
|
20
|
+
h3. Pobranie plików z Joggera
|
21
|
+
|
22
|
+
<pre><code>
|
23
|
+
rubber download
|
24
|
+
</pre></code>
|
25
|
+
|
26
|
+
h3. Wysłanie zmodyfikowanych plików na Joggera
|
27
|
+
|
28
|
+
<pre><code>
|
29
|
+
rubber upload files/my_file.html
|
30
|
+
</pre></code>
|
31
|
+
|
32
|
+
h3. Wysłanie wszystkich plików na Joggera
|
33
|
+
|
34
|
+
<pre><code>
|
35
|
+
rubber upload files/*
|
36
|
+
</pre></code>
|
37
|
+
|
38
|
+
h3. Uruchomienie serwera
|
39
|
+
|
40
|
+
<pre><code>
|
41
|
+
rubber server
|
42
|
+
</pre></code>
|
43
|
+
|
44
|
+
Twój jogger jest dostępny pod adresem http://localhost:1337
|
data/Rakefile
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake/gempackagetask'
|
3
|
+
|
4
|
+
PLUGIN = "rubber"
|
5
|
+
GEM_NAME = "rubber"
|
6
|
+
GEM_VERSION = "0.0.3"
|
7
|
+
AUTHOR = "Tymon Tobolski"
|
8
|
+
EMAIL = "i@teamon.eu"
|
9
|
+
HOMEPAGE = "http://teamon.eu/projekty/"
|
10
|
+
SUMMARY = "Edytor szablonów Joggera"
|
11
|
+
|
12
|
+
spec = Gem::Specification.new do |s|
|
13
|
+
s.name = GEM_NAME
|
14
|
+
s.version = GEM_VERSION
|
15
|
+
s.has_rdoc = false
|
16
|
+
s.summary = SUMMARY
|
17
|
+
s.description = s.summary
|
18
|
+
s.author = AUTHOR
|
19
|
+
s.email = EMAIL
|
20
|
+
s.homepage = HOMEPAGE
|
21
|
+
s.require_path = 'lib'
|
22
|
+
s.bindir = 'bin'
|
23
|
+
s.executables = %w( rubber )
|
24
|
+
s.files = %w( LICENSE README.textile Rakefile ) + Dir.glob("{bin,lib}/**/*")
|
25
|
+
s.add_dependency('mechanize', '>= 0.9.0')
|
26
|
+
s.add_dependency('thin')
|
27
|
+
end
|
28
|
+
|
29
|
+
Rake::GemPackageTask.new(spec) do |pkg|
|
30
|
+
pkg.gem_spec = spec
|
31
|
+
end
|
32
|
+
|
33
|
+
desc "Create a gemspec file"
|
34
|
+
task :gemspec do
|
35
|
+
File.open("#{GEM_NAME}.gemspec", "w") do |file|
|
36
|
+
file.puts spec.to_ruby
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
# development
|
41
|
+
|
42
|
+
desc 'Strip trailing whitespace from source files'
|
43
|
+
task :strip do
|
44
|
+
Dir["#{File.dirname(__FILE__)}/**/*.rb"].each do |path|
|
45
|
+
content = File.open(path, 'r') do |f|
|
46
|
+
f.map { |line| line.gsub(/\G\s/, ' ').rstrip + "\n" }.join.rstrip
|
47
|
+
end + "\n"
|
48
|
+
|
49
|
+
if File.read(path) != content
|
50
|
+
puts "Stripping whitepsace from #{path}"
|
51
|
+
File.open(path, 'w') {|f| f.write content}
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
|
data/bin/rubber
ADDED
data/lib/rubber.rb
ADDED
@@ -0,0 +1,147 @@
|
|
1
|
+
require 'mechanize'
|
2
|
+
|
3
|
+
class Rubber
|
4
|
+
def initialize(args)
|
5
|
+
@args = args
|
6
|
+
@agent = WWW::Mechanize.new
|
7
|
+
end
|
8
|
+
|
9
|
+
def run
|
10
|
+
load_config_file
|
11
|
+
end
|
12
|
+
|
13
|
+
protected
|
14
|
+
|
15
|
+
def load_config_file
|
16
|
+
if File.exists?("config.yml")
|
17
|
+
@config = YAML.load(File.read("config.yml"))
|
18
|
+
else
|
19
|
+
File.open("config.yml", "w") {|f|
|
20
|
+
f.write YAML.dump({:jabber_id => "your@jabber.id", :password => "secret"})
|
21
|
+
}
|
22
|
+
puts "Brak pliku config.yml. Przykładowy plik został utworzony."
|
23
|
+
exit
|
24
|
+
end
|
25
|
+
|
26
|
+
case @args[0]
|
27
|
+
when 'download'
|
28
|
+
download
|
29
|
+
when 'upload'
|
30
|
+
@args.shift
|
31
|
+
upload(@args)
|
32
|
+
when 'server'
|
33
|
+
server
|
34
|
+
else
|
35
|
+
usage
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def server
|
40
|
+
system("thin start -R #{File.join(File.dirname(__FILE__), "server.ru")} -p 1337")
|
41
|
+
end
|
42
|
+
|
43
|
+
def download
|
44
|
+
login
|
45
|
+
get_filemap
|
46
|
+
get_pagesmap
|
47
|
+
|
48
|
+
# files
|
49
|
+
Dir.mkdir("files") unless File.exists?("files")
|
50
|
+
@filemap.each do |filename, url|
|
51
|
+
puts "Pobieranie #{filename}"
|
52
|
+
|
53
|
+
if confirm(filename)
|
54
|
+
File.open(filename, 'wb') {|f| f.write @agent.get(url).body }
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# strony
|
59
|
+
Dir.mkdir("strony") unless File.exists?("strony")
|
60
|
+
@pagesmap.each do |filename, url|
|
61
|
+
puts "Pobieranie #{filename}"
|
62
|
+
|
63
|
+
if confirm(filename)
|
64
|
+
File.open(filename, 'w') {|f| f.write @agent.get("https://login.jogger.pl#{url}").forms.first.templatesContent }
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def upload(files = [])
|
70
|
+
login
|
71
|
+
get_filemap
|
72
|
+
get_pagesmap
|
73
|
+
|
74
|
+
files.each do |file|
|
75
|
+
if url = @pagesmap[file]
|
76
|
+
form = @agent.get(url).forms.first
|
77
|
+
form.templatesContent = File.read(file)
|
78
|
+
form.submit
|
79
|
+
puts "Plik #{file} został zaktualizowany"
|
80
|
+
elsif url = @filemap[file] || file =~ %r[^files/]
|
81
|
+
form = @agent.get('https://login.jogger.pl/templates/files/').forms.first
|
82
|
+
form.file_uploads.first.file_name = file
|
83
|
+
form.submit
|
84
|
+
puts "Plik #{file} został zaktualizowany"
|
85
|
+
else
|
86
|
+
puts "Plik #{file} nie istnieje"
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def confirm(filename)
|
92
|
+
if File.exists?(filename) && @args[1] != '--force'
|
93
|
+
puts "Plik #{filename} istnieje. Nadpisac? [T/N]"
|
94
|
+
|
95
|
+
loop do
|
96
|
+
print "> "
|
97
|
+
res = STDIN.gets.chomp.upcase
|
98
|
+
|
99
|
+
if res == "T"
|
100
|
+
return true
|
101
|
+
elsif res == "N"
|
102
|
+
return false
|
103
|
+
else
|
104
|
+
puts "Nie czaje..."
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
109
|
+
|
110
|
+
return true
|
111
|
+
end
|
112
|
+
|
113
|
+
def get_pagesmap
|
114
|
+
@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
|
+
@pagesmap["Szablon wpisów.html"] ='/templates/edit/?file=entries'
|
116
|
+
@pagesmap["Szablon komentarzy.html"] ='/templates/edit/?file=comments'
|
117
|
+
@pagesmap["Szablon logowania.html"] ='/templates/edit/?file=login'
|
118
|
+
end
|
119
|
+
|
120
|
+
def get_filemap
|
121
|
+
@filemap = Hash[*@agent.get('https://login.jogger.pl/templates/files/').parser.css("td > a").map {|e| ["files/#{e.text}", e[:href]] }.flatten]
|
122
|
+
end
|
123
|
+
|
124
|
+
def login
|
125
|
+
form = @agent.get('https://login.jogger.pl/login/').forms.first
|
126
|
+
form.login_jabberid = @config[:jabber_id]
|
127
|
+
form.login_jabberpass = @config[:password]
|
128
|
+
page = form.submit
|
129
|
+
|
130
|
+
if page.uri.to_s == 'https://login.jogger.pl/login/'
|
131
|
+
puts "Identyfikator jabbera lub hasło jest nieporawne"
|
132
|
+
exit
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
def usage
|
137
|
+
puts <<-USAGE
|
138
|
+
rubber [action]
|
139
|
+
|
140
|
+
Actions:
|
141
|
+
download (--force)
|
142
|
+
upload [file]
|
143
|
+
USAGE
|
144
|
+
exit
|
145
|
+
end
|
146
|
+
|
147
|
+
end
|
data/lib/server.ru
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'rack/response'
|
2
|
+
|
3
|
+
def parse(body)
|
4
|
+
body.gsub!(%r|<INCLUDE>(.+)</INCLUDE>|) {|e|
|
5
|
+
parse(File.read("files/#{$1}"))
|
6
|
+
}
|
7
|
+
|
8
|
+
body
|
9
|
+
end
|
10
|
+
|
11
|
+
app = Proc.new do |env|
|
12
|
+
path = env["REQUEST_URI"]
|
13
|
+
|
14
|
+
if path =~ %r[/files/]
|
15
|
+
Rack::File.new(Dir.pwd).call(env)
|
16
|
+
else
|
17
|
+
content = case path
|
18
|
+
when "/"
|
19
|
+
parse File.read("Szablon wpisów.html")
|
20
|
+
when "/entry"
|
21
|
+
parse File.read("Szablon komentarzy.html")
|
22
|
+
when "/login"
|
23
|
+
parse File.read("Szablon logowanie.html")
|
24
|
+
else
|
25
|
+
path = "strony/#{path.gsub('-', ' ').gsub('/', '').capitalize}.html"
|
26
|
+
if File.exists?(path)
|
27
|
+
parse File.read(path)
|
28
|
+
else
|
29
|
+
"NotFound"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
[200, {"Content-type" => "text/html"}, content || ""]
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
run app
|
metadata
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: teamon-rubber
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tymon Tobolski
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-05-08 00:00:00 -07:00
|
13
|
+
default_executable: rubber
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: mechanize
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.9.0
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: thin
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: "0"
|
34
|
+
version:
|
35
|
+
description: "Edytor szablon\xC3\xB3w Joggera"
|
36
|
+
email: i@teamon.eu
|
37
|
+
executables:
|
38
|
+
- rubber
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files: []
|
42
|
+
|
43
|
+
files:
|
44
|
+
- LICENSE
|
45
|
+
- README.textile
|
46
|
+
- Rakefile
|
47
|
+
- bin/rubber
|
48
|
+
- lib/rubber.rb
|
49
|
+
- lib/server.ru
|
50
|
+
has_rdoc: false
|
51
|
+
homepage: http://teamon.eu/projekty/
|
52
|
+
post_install_message:
|
53
|
+
rdoc_options: []
|
54
|
+
|
55
|
+
require_paths:
|
56
|
+
- lib
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: "0"
|
62
|
+
version:
|
63
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: "0"
|
68
|
+
version:
|
69
|
+
requirements: []
|
70
|
+
|
71
|
+
rubyforge_project:
|
72
|
+
rubygems_version: 1.2.0
|
73
|
+
signing_key:
|
74
|
+
specification_version: 3
|
75
|
+
summary: "Edytor szablon\xC3\xB3w Joggera"
|
76
|
+
test_files: []
|
77
|
+
|