sibyl 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +24 -10
- data/app/assets/images/old_moon/old_moon.png +0 -0
- data/app/assets/images/old_moon/old_moon_@2X.jpg +0 -0
- data/app/assets/images/old_moon/readme.txt +8 -0
- data/app/assets/images/ui-bg_diagonals-thick_15_0b3e6f_40x40.png +0 -0
- data/app/assets/images/ui-bg_dots-medium_30_0b58a2_4x4.png +0 -0
- data/app/assets/images/ui-bg_dots-small_20_333333_2x2.png +0 -0
- data/app/assets/images/ui-bg_dots-small_30_a32d00_2x2.png +0 -0
- data/app/assets/images/ui-bg_dots-small_40_00498f_2x2.png +0 -0
- data/app/assets/images/ui-bg_gloss-wave_20_111111_500x100.png +0 -0
- data/app/assets/images/ui-icons_00498f_256x240.png +0 -0
- data/app/assets/images/ui-icons_98d2fb_256x240.png +0 -0
- data/app/assets/images/ui-icons_9ccdfc_256x240.png +0 -0
- data/app/assets/images/ui-icons_ffffff_256x240.png +0 -0
- data/app/assets/javascripts/jquery-ui.js +18706 -0
- data/app/assets/javascripts/jquery-ui.min.js +13 -0
- data/app/assets/javascripts/jquery.min.js +5 -0
- data/app/assets/javascripts/sibyl/application.js +2 -0
- data/app/assets/javascripts/sibyl/editor.js +218 -2
- data/app/assets/stylesheets/atelier-seaside-dark.css +1 -0
- data/app/assets/stylesheets/default.css +1 -0
- data/app/assets/stylesheets/jquery-ui.css +1312 -0
- data/app/assets/stylesheets/jquery-ui.min.css +7 -0
- data/app/assets/stylesheets/jquery-ui.structure.css +886 -0
- data/app/assets/stylesheets/jquery-ui.structure.min.css +5 -0
- data/app/assets/stylesheets/jquery-ui.theme.css +443 -0
- data/app/assets/stylesheets/jquery-ui.theme.min.css +5 -0
- data/app/assets/stylesheets/sibyl/application.css +9 -0
- data/app/assets/stylesheets/sibyl/editor.css +148 -4
- data/app/controllers/sibyl/editor_controller.rb +81 -3
- data/app/views/layouts/sibyl/application.html.erb +3 -2
- data/app/views/sibyl/editor/create_scaffold.html.erb +0 -0
- data/app/views/sibyl/editor/edit.html.erb +83 -1
- data/app/views/sibyl/editor/index.html.erb +28 -2
- data/app/views/sibyl/editor/index_task.html.erb +25 -0
- data/app/views/sibyl/editor/new_scaffold.html.erb +35 -0
- data/config/routes.rb +10 -2
- data/lib/generators/sibyl/form/USAGE +8 -0
- data/lib/generators/sibyl/form/form_generator.rb +34 -0
- data/lib/generators/sibyl/install/USAGE +8 -0
- data/lib/generators/sibyl/install/install_generator.rb +17 -0
- data/lib/generators/sibyl/install/templates/sibyl.rb +1 -0
- data/lib/generators/sibyl/model/USAGE +8 -0
- data/lib/generators/sibyl/model/model_generator.rb +29 -0
- data/lib/sibyl/base.rb +101 -0
- data/lib/sibyl/engine.rb +7 -0
- data/lib/sibyl/form.rb +43 -0
- data/lib/sibyl/task.rb +123 -0
- data/lib/sibyl/version.rb +1 -1
- data/lib/sibyl.rb +2 -0
- data/lib/tasks/sibyl_tasks.rake +19 -4
- metadata +123 -2
data/lib/sibyl/task.rb
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
require 'prawn'
|
2
|
+
require 'zip'
|
3
|
+
|
4
|
+
module Sibyl
|
5
|
+
module Task
|
6
|
+
include Magick
|
7
|
+
|
8
|
+
def clear
|
9
|
+
@sibyl_elements = {}
|
10
|
+
@sibyl_pdfs = []
|
11
|
+
end
|
12
|
+
def prepare(obj = nil)
|
13
|
+
clear unless @sibyl_elements
|
14
|
+
obj = self if obj == nil
|
15
|
+
obj.attributes.each do |col,val|
|
16
|
+
STDERR.puts "attr: #{col}: #{val}"
|
17
|
+
@sibyl_elements[col] = val
|
18
|
+
end
|
19
|
+
end
|
20
|
+
def fill
|
21
|
+
prepare
|
22
|
+
STDERR.puts "Obj: #{self}"
|
23
|
+
STDERR.puts "Obj.class: #{self.class}"
|
24
|
+
@task = ActiveSupport::Inflector.underscore(self.class.to_s).pluralize
|
25
|
+
STDERR.puts "@task: #{@task}"
|
26
|
+
Dir[Rails.root.join("app", "sibyl", @task, "*.json").to_s].each do |json|
|
27
|
+
self.create_pdf(json, Rails.root.join("tmp"))
|
28
|
+
end
|
29
|
+
end
|
30
|
+
def create_pdf(json, dest_dir)
|
31
|
+
STDERR.puts "json: #{json}"
|
32
|
+
data = JSON.parse(File.read(json))
|
33
|
+
STDERR.puts "data: #{data.inspect}"
|
34
|
+
dir = Pathname.new(json.gsub(/\.json/i, ""))
|
35
|
+
STDERR.puts "dir: #{dir}"
|
36
|
+
STDERR.puts "dir.basename: #{dir.basename}"
|
37
|
+
pdf_path = Pathname.new(dest_dir.to_s).join( dir.basename.to_s.gsub(/\/$|\\$/, '') + ".pdf" )
|
38
|
+
STDERR.puts "pdf_path: #{pdf_path}"
|
39
|
+
pdf = nil
|
40
|
+
tmp_images = []
|
41
|
+
data.keys.each do |page_name|
|
42
|
+
img_path = dir.join(page_name).to_s
|
43
|
+
img_outpath = dest_dir.join(page_name).to_s
|
44
|
+
STDERR.puts "img_path: #{img_path}"
|
45
|
+
STDERR.puts "img_outpath: #{img_outpath}"
|
46
|
+
STDERR.puts "data[#{page_name}]: #{data[page_name]}"
|
47
|
+
if data[page_name].has_key? 'elements'
|
48
|
+
img = ImageList.new(img_path)
|
49
|
+
text = Magick::Draw.new
|
50
|
+
elements = data[page_name]['elements']
|
51
|
+
STDERR.puts "elements: #{elements}"
|
52
|
+
elements.keys.each do |col|
|
53
|
+
STDERR.puts "elments[#{col}]: #{elements[col]}"
|
54
|
+
if elements[col].has_key? 'fontsize'
|
55
|
+
STDERR.puts "setting fontsize: #{elements[col]['fontsize']}"
|
56
|
+
text.pointsize = elements[col]['fontsize'].to_f + 2
|
57
|
+
end
|
58
|
+
if elements[col].has_key?('x') and elements[col].has_key?('y')
|
59
|
+
STDERR.puts "received element: #{elements[col]['x']},#{elements[col]['y']}"
|
60
|
+
if self.respond_to? col
|
61
|
+
STDERR.puts "Setting: #{col} at #{elements[col]['x']},#{elements[col]['y']}"
|
62
|
+
text.annotate(img, 0,0,elements[col]['x'].to_i,elements[col]['y'].to_i + 15, self.send(col)) {
|
63
|
+
self.fill = 'black'
|
64
|
+
}
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
img.write(img_outpath)
|
69
|
+
tmp_images.push img_outpath
|
70
|
+
else
|
71
|
+
STDERR.puts "No elements to using default: #{img_path}"
|
72
|
+
img_outpath = img_path
|
73
|
+
end
|
74
|
+
|
75
|
+
img = Magick::Image.ping(img_outpath).first
|
76
|
+
width = img.columns
|
77
|
+
height = img.rows
|
78
|
+
|
79
|
+
# Image should be 300dpi
|
80
|
+
# LETTER = 612.00 x 792.0
|
81
|
+
# Which is 2550 px, 3300 px
|
82
|
+
# This works out to 612 / 2550 = 0.24
|
83
|
+
ratio = 0.24
|
84
|
+
pdf_width = width * ratio
|
85
|
+
pdf_height = height * ratio
|
86
|
+
|
87
|
+
if pdf
|
88
|
+
STDERR.puts "start_new_page"
|
89
|
+
pdf.start_new_page(:page_size => [pdf_width, pdf_height], :margin => 0)
|
90
|
+
else
|
91
|
+
STDERR.puts "generate_pdf"
|
92
|
+
pdf = Prawn::Document.new(:page_size => [pdf_width, pdf_height], :margin => 0)
|
93
|
+
end
|
94
|
+
STDERR.puts "#{page_name}: Putting: #{img_outpath} of #{width},#{height} at [0,#{pdf_height}]"
|
95
|
+
pdf.image img_outpath, :at => [0,pdf_height], :width => pdf_width
|
96
|
+
end
|
97
|
+
pdf.render_file pdf_path
|
98
|
+
STDERR.puts "Saved to: #{pdf_path}"
|
99
|
+
# Clean up tmp images
|
100
|
+
tmp_images.each do |img_path|
|
101
|
+
File.unlink img_path
|
102
|
+
end
|
103
|
+
@sibyl_pdfs.push pdf_path
|
104
|
+
return pdf_path
|
105
|
+
end
|
106
|
+
|
107
|
+
def zip_path
|
108
|
+
fill
|
109
|
+
|
110
|
+
dirpath = Rails.root.join('tmp', "#{@task}#{self.id}-#{SecureRandom.hex(8)}")
|
111
|
+
FileUtils.mkdir dirpath
|
112
|
+
zip_path = dirpath.join("#{@task}.zip").to_s
|
113
|
+
STDERR.puts "Creating: #{zip_path}"
|
114
|
+
Zip::File.open(zip_path, Zip::File::CREATE) do |zipfile|
|
115
|
+
@sibyl_pdfs.each do |pdf|
|
116
|
+
STDERR.puts "Adding: #{pdf}"
|
117
|
+
zipfile.add(Pathname.new(pdf.to_s).basename, pdf)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
return zip_path
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
data/lib/sibyl/version.rb
CHANGED
data/lib/sibyl.rb
CHANGED
data/lib/tasks/sibyl_tasks.rake
CHANGED
@@ -1,4 +1,19 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
namespace :sibyl do
|
2
|
+
task :open do
|
3
|
+
desc "open tasks"
|
4
|
+
Sibyl::Engine.open
|
5
|
+
end
|
6
|
+
task :install do
|
7
|
+
initializer = Rails.root.join("config", "initializers", "sibyl.rb")
|
8
|
+
unless File.exists? initializer
|
9
|
+
File.open(initializer, "w") do |f|
|
10
|
+
f.write "Sibyl::Base.load"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
routes_file = Rails.root.join("config", "routes.rb")
|
14
|
+
routes = File.read(routes_file).gsub(/Rails.application.routes.draw do/, "Rails.application.routes.draw do\n mount Sibyl::Engine => \"/sibyl\"\n")
|
15
|
+
File.open(routes_file, "w") do |f|
|
16
|
+
f.write routes
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sibyl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Janet jeffus
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-12-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -30,6 +30,90 @@ dependencies:
|
|
30
30
|
- - ">="
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: 5.0.0.1
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: rmagick
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: 2.16.0
|
40
|
+
type: :runtime
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 2.16.0
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: awesome_print
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: rubyzip
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
type: :runtime
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: launchy
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
type: :runtime
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: prawn
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
type: :runtime
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
- !ruby/object:Gem::Dependency
|
104
|
+
name: thor-rails
|
105
|
+
requirement: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
type: :runtime
|
111
|
+
prerelease: false
|
112
|
+
version_requirements: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
33
117
|
- !ruby/object:Gem::Dependency
|
34
118
|
name: sqlite3
|
35
119
|
requirement: !ruby/object:Gem::Requirement
|
@@ -55,8 +139,32 @@ files:
|
|
55
139
|
- README.md
|
56
140
|
- Rakefile
|
57
141
|
- app/assets/config/sibyl_manifest.js
|
142
|
+
- app/assets/images/old_moon/old_moon.png
|
143
|
+
- app/assets/images/old_moon/old_moon_@2X.jpg
|
144
|
+
- app/assets/images/old_moon/readme.txt
|
145
|
+
- app/assets/images/ui-bg_diagonals-thick_15_0b3e6f_40x40.png
|
146
|
+
- app/assets/images/ui-bg_dots-medium_30_0b58a2_4x4.png
|
147
|
+
- app/assets/images/ui-bg_dots-small_20_333333_2x2.png
|
148
|
+
- app/assets/images/ui-bg_dots-small_30_a32d00_2x2.png
|
149
|
+
- app/assets/images/ui-bg_dots-small_40_00498f_2x2.png
|
150
|
+
- app/assets/images/ui-bg_gloss-wave_20_111111_500x100.png
|
151
|
+
- app/assets/images/ui-icons_00498f_256x240.png
|
152
|
+
- app/assets/images/ui-icons_98d2fb_256x240.png
|
153
|
+
- app/assets/images/ui-icons_9ccdfc_256x240.png
|
154
|
+
- app/assets/images/ui-icons_ffffff_256x240.png
|
155
|
+
- app/assets/javascripts/jquery-ui.js
|
156
|
+
- app/assets/javascripts/jquery-ui.min.js
|
157
|
+
- app/assets/javascripts/jquery.min.js
|
58
158
|
- app/assets/javascripts/sibyl/application.js
|
59
159
|
- app/assets/javascripts/sibyl/editor.js
|
160
|
+
- app/assets/stylesheets/atelier-seaside-dark.css
|
161
|
+
- app/assets/stylesheets/default.css
|
162
|
+
- app/assets/stylesheets/jquery-ui.css
|
163
|
+
- app/assets/stylesheets/jquery-ui.min.css
|
164
|
+
- app/assets/stylesheets/jquery-ui.structure.css
|
165
|
+
- app/assets/stylesheets/jquery-ui.structure.min.css
|
166
|
+
- app/assets/stylesheets/jquery-ui.theme.css
|
167
|
+
- app/assets/stylesheets/jquery-ui.theme.min.css
|
60
168
|
- app/assets/stylesheets/sibyl/application.css
|
61
169
|
- app/assets/stylesheets/sibyl/editor.css
|
62
170
|
- app/controllers/sibyl/application_controller.rb
|
@@ -67,11 +175,24 @@ files:
|
|
67
175
|
- app/mailers/sibyl/application_mailer.rb
|
68
176
|
- app/models/sibyl/application_record.rb
|
69
177
|
- app/views/layouts/sibyl/application.html.erb
|
178
|
+
- app/views/sibyl/editor/create_scaffold.html.erb
|
70
179
|
- app/views/sibyl/editor/edit.html.erb
|
71
180
|
- app/views/sibyl/editor/index.html.erb
|
181
|
+
- app/views/sibyl/editor/index_task.html.erb
|
182
|
+
- app/views/sibyl/editor/new_scaffold.html.erb
|
72
183
|
- config/routes.rb
|
184
|
+
- lib/generators/sibyl/form/USAGE
|
185
|
+
- lib/generators/sibyl/form/form_generator.rb
|
186
|
+
- lib/generators/sibyl/install/USAGE
|
187
|
+
- lib/generators/sibyl/install/install_generator.rb
|
188
|
+
- lib/generators/sibyl/install/templates/sibyl.rb
|
189
|
+
- lib/generators/sibyl/model/USAGE
|
190
|
+
- lib/generators/sibyl/model/model_generator.rb
|
73
191
|
- lib/sibyl.rb
|
192
|
+
- lib/sibyl/base.rb
|
74
193
|
- lib/sibyl/engine.rb
|
194
|
+
- lib/sibyl/form.rb
|
195
|
+
- lib/sibyl/task.rb
|
75
196
|
- lib/sibyl/version.rb
|
76
197
|
- lib/tasks/sibyl_tasks.rake
|
77
198
|
homepage: https://github.com/astaria/sibyl
|