plezi 0.12.13 → 0.12.14
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/bin/plezi +1 -1
- data/lib/plezi.rb +3 -2
- data/lib/plezi/builders/ac_model.rb +59 -0
- data/lib/plezi/builders/app_builder.rb +114 -112
- data/lib/plezi/builders/builder.rb +30 -28
- data/lib/plezi/builders/form_builder.rb +16 -13
- data/lib/plezi/handlers/controller_magic.rb +18 -23
- data/lib/plezi/handlers/stubs.rb +7 -2
- data/lib/plezi/helpers/http_sender.rb +19 -18
- data/lib/plezi/version.rb +1 -1
- data/plezi.gemspec +1 -1
- data/resources/404.erb +6 -1
- data/resources/500.erb +6 -1
- data/test/plezi_tests.rb +13 -12
- metadata +5 -5
- data/websocket chatroom.md +0 -629
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d6b0b52b7ab1f233bf4d1e35c75df9579a0f1456
|
4
|
+
data.tar.gz: 1f927d686228dd20ebec6397b3977dbb68bdcf3f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 54a35d6840cbfd4477e52b68552c958458f886b85204360c2e7951d76b62836737622e83c8ad915469cc0f892fa459bb99a31b5650d3d21bfd7528f997b4c273
|
7
|
+
data.tar.gz: c9e5d79dade6f7fd1416cd5d34fb189fd31dd6fd9b0fdf6f6ef2df823de5b5203c84b51bd95f733e23436667d5c3bc16b623068792e708849b32a1a090c1aa15
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,14 @@
|
|
2
2
|
|
3
3
|
***
|
4
4
|
|
5
|
+
Change log v.0.12.14
|
6
|
+
|
7
|
+
**Update**: `Controller#redirect_to` will now attempt to guess the URL using `url_for`, unless the URL given is a String. It also leverages the new `redirect_to` Iodine::Response method, allowing you to set the FUTURE response's status_code.
|
8
|
+
|
9
|
+
**Update**: Error page rendering is now performed within a controller class called `ErrorCtrl`. This means that the error templates have acess to all the helper methods and properties of a controller, including `render`, `redirect_to`, etc'.
|
10
|
+
|
11
|
+
***
|
12
|
+
|
5
13
|
Change log v.0.12.13
|
6
14
|
|
7
15
|
**Fix**: fixed an error in te rendering engine, where the default :format was an empty String instead of 'html'.
|
data/bin/plezi
CHANGED
@@ -64,7 +64,7 @@ if ARGV[0] == 'new' || ARGV[0] == 'n' || ARGV[0] == "force" || ARGV[0] == 'mini'
|
|
64
64
|
end
|
65
65
|
|
66
66
|
# building
|
67
|
-
template = Plezi::AppBuilder.new
|
67
|
+
template = Plezi::Base::AppBuilder.new
|
68
68
|
(ARGV[0] == 'mini' || ARGV[0] == 'm' ) ? template.build_mini(ARGV[1]) : template.build(ARGV[1])
|
69
69
|
elsif ARGV[0] == 'server' || ARGV[0] == 'start' || ARGV[0] == 's'
|
70
70
|
ARGV.shift
|
data/lib/plezi.rb
CHANGED
@@ -29,8 +29,6 @@ require 'plezi/common/settings.rb'
|
|
29
29
|
require 'plezi/common/renderer.rb'
|
30
30
|
|
31
31
|
### helpers
|
32
|
-
|
33
|
-
require 'plezi/helpers/http_sender.rb'
|
34
32
|
require 'plezi/helpers/magic_helpers.rb'
|
35
33
|
require 'plezi/helpers/mime_types.rb'
|
36
34
|
|
@@ -45,6 +43,9 @@ require 'plezi/handlers/placebo.rb'
|
|
45
43
|
require 'plezi/handlers/stubs.rb'
|
46
44
|
require 'plezi/handlers/session.rb'
|
47
45
|
|
46
|
+
# error and last resort handling
|
47
|
+
require 'plezi/helpers/http_sender.rb'
|
48
|
+
|
48
49
|
## erb templating
|
49
50
|
begin
|
50
51
|
require 'erb'
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'plezi/builders/builder'
|
2
|
+
|
3
|
+
module Plezi
|
4
|
+
|
5
|
+
module Base
|
6
|
+
|
7
|
+
|
8
|
+
module ACModelBuilder
|
9
|
+
@gem_root = ::Plezi::Builder::GEM_ROOT
|
10
|
+
|
11
|
+
# ActiveRecord::Base.connection.tables
|
12
|
+
# # Checks for existence of kittens table (Kitten model)
|
13
|
+
# ActiveRecord::Base.connection.table_exists? 'kittens'
|
14
|
+
|
15
|
+
# # Tells you all migrations run
|
16
|
+
# ActiveRecord::Migrator.get_all_versions
|
17
|
+
# # Tells you the current schema version
|
18
|
+
# ActiveRecord::Migrator.current_version
|
19
|
+
|
20
|
+
# # Check a column exists
|
21
|
+
# column_exists?(:suppliers, :name)
|
22
|
+
|
23
|
+
# # Check a column exists of a particular type
|
24
|
+
# column_exists?(:suppliers, :name, :string)
|
25
|
+
|
26
|
+
# # Check a column exists with a specific definition
|
27
|
+
# column_exists?(:suppliers, :name, :string, limit: 100)
|
28
|
+
# column_exists?(:suppliers, :name, :string, default: 'default')
|
29
|
+
# column_exists?(:suppliers, :name, :string, null: false)
|
30
|
+
# column_exists?(:suppliers, :tax, :decimal, precision: 8, scale: 2)
|
31
|
+
|
32
|
+
def self.parse_args
|
33
|
+
return unless ARGS[0][0] == 'g'
|
34
|
+
struct = {}
|
35
|
+
ARGS[1..-1].each do |s|
|
36
|
+
s = s.split /[\:\.]/
|
37
|
+
raise "Cannot parse parameters - need to be defined as name.type or name:type." if s.count !=2
|
38
|
+
struct[s[0]] = DB_TYPES[s[1].downcase] || (raise "Unrecognized type #{s[1]}.")
|
39
|
+
end
|
40
|
+
struct
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# require 'sequel'
|
45
|
+
|
46
|
+
# ## Connect to the database
|
47
|
+
# DB = Sequel.sqlite('./ex1.db')
|
48
|
+
|
49
|
+
# unless DB.table_exists? :posts
|
50
|
+
# DB.create_table :posts do
|
51
|
+
# primary_key :id
|
52
|
+
# varchar :title
|
53
|
+
# text :body
|
54
|
+
# end
|
55
|
+
# end
|
56
|
+
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|
@@ -1,132 +1,134 @@
|
|
1
1
|
require 'plezi/builders/builder'
|
2
2
|
module Plezi
|
3
3
|
|
4
|
+
module Base
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
6
|
+
class AppBuilder
|
7
|
+
def initialize
|
8
|
+
@end_comments = []
|
9
|
+
@app_tree ||= {}
|
10
|
+
@root = ::Plezi::Base::Builder::GEM_ROOT
|
11
|
+
end
|
12
|
+
def app_tree
|
13
|
+
@app_tree ||= {}
|
14
|
+
end
|
15
|
+
def build_mini app_name = ARGV[1]
|
16
|
+
require 'plezi/version'
|
17
|
+
app_tree["#{app_name}"] ||= IO.read( File.join(@root, "resources" ,"mini_exec.rb")).gsub('appname', app_name)
|
18
|
+
app_tree["#{app_name}.rb"] ||= IO.read( File.join(@root, "resources" ,"mini_app.rb")).gsub('appname', app_name).gsub('appsecret', "#{app_name}_#{SecureRandom.hex}")
|
19
|
+
app_tree["Procfile"] ||= String.new
|
20
|
+
app_tree["Procfile"] << "\nweb: bundle exec ruby ./#{app_name} -p $PORT\n"
|
21
|
+
app_tree["Gemfile"] ||= String.new
|
22
|
+
app_tree["Gemfile"] << "source 'https://rubygems.org'\n\n####################\n# core gems\n\n# include the basic plezi framework and server\ngem 'plezi', '~> #{Plezi::VERSION}'\n"
|
23
|
+
app_tree["Gemfile"] << "\n\n\nruby '#{RUBY_VERSION}'\n"
|
24
|
+
app_tree["templates"] ||= {}
|
25
|
+
app_tree["templates"]["404.html.erb"] ||= IO.read(File.join(@root, "resources" ,"404.erb"))
|
26
|
+
app_tree["templates"]["500.html.erb"] ||= IO.read(File.join(@root, "resources" ,"500.erb"))
|
27
|
+
app_tree["templates"]["welcome.html.erb"] ||= IO.read(File.join(@root, "resources" ,"mini_welcome_page.html")).gsub('appname', app_name)
|
28
|
+
app_tree["assets"] ||= {}
|
29
|
+
app_tree["assets"]["websocket.js"] ||= IO.read(File.join(@root, "resources" ,"websockets.js")).gsub('appname', app_name)
|
30
|
+
finalize app_name
|
31
|
+
end
|
31
32
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
33
|
+
def build app_name = ARGV[1]
|
34
|
+
require 'plezi/version'
|
35
|
+
# plezi run script
|
36
|
+
app_tree["#{app_name}"] ||= IO.read File.join(@root,"resources" ,"code.rb")
|
36
37
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
38
|
+
# set up application files
|
39
|
+
app_tree["app"] ||= {}
|
40
|
+
app_tree["app"]["controllers"] ||= {}
|
41
|
+
app_tree["app"]["controllers"]["sample_controller.rb"] ||= IO.read(File.join(@root,"resources" ,"controller.rb"))
|
42
|
+
app_tree["app"]["models"] ||= {}
|
43
|
+
app_tree["app"]["views"] ||= {}
|
43
44
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
45
|
+
# set up templates for status error codes
|
46
|
+
app_tree["app"]["views"]["404.html"] ||= IO.read(File.join(@root,"resources" ,"404.html"))
|
47
|
+
app_tree["app"]["views"]["500.html"] ||= IO.read(File.join(@root,"resources" ,"500.html"))
|
48
|
+
app_tree["app"]["views"]["404.html.erb"] ||= IO.read(File.join(@root,"resources" ,"404.erb"))
|
49
|
+
app_tree["app"]["views"]["500.html.erb"] ||= IO.read(File.join(@root,"resources" ,"500.erb"))
|
50
|
+
app_tree["app"]["views"]["404.html.slim"] ||= IO.read(File.join(@root,"resources" ,"404.slim"))
|
51
|
+
app_tree["app"]["views"]["500.html.slim"] ||= IO.read(File.join(@root,"resources" ,"500.slim"))
|
52
|
+
app_tree["app"]["views"]["404.html.haml"] ||= IO.read(File.join(@root,"resources" ,"404.haml"))
|
53
|
+
app_tree["app"]["views"]["500.html.haml"] ||= IO.read(File.join(@root,"resources" ,"500.haml"))
|
53
54
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
55
|
+
# set up the assets folder
|
56
|
+
app_tree["assets"] ||= {}
|
57
|
+
app_tree["assets"]["stylesheets"] ||= {}
|
58
|
+
app_tree["assets"]["javascripts"] ||= {}
|
59
|
+
app_tree["assets"]["javascripts"]["websocket.js"] ||= IO.read(File.join(@root,"resources" ,"websockets.js")).gsub('appname', app_name)
|
60
|
+
app_tree["assets"]["welcome.html"] ||= IO.read(File.join(@root,"resources" ,"welcome_page.html")).gsub('appname', app_name)
|
60
61
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
62
|
+
# app core files.
|
63
|
+
app_tree["initialize.rb"] ||= IO.read File.join(@root,"resources" ,"initialize.rb").gsub('appname', app_name)
|
64
|
+
app_tree["routes.rb"] ||= IO.read File.join(@root,"resources" ,"routes.rb")
|
65
|
+
app_tree["rakefile"] ||= IO.read File.join(@root,"resources" ,"rakefile")
|
66
|
+
app_tree["Procfile"] ||= ""
|
67
|
+
app_tree["Procfile"] << "\nweb: bundle exec ruby ./#{app_name} -p $PORT\n"
|
68
|
+
app_tree["Gemfile"] ||= ''
|
69
|
+
app_tree["Gemfile"] << "source 'https://rubygems.org'\n\n####################\n# core gems\n\n# include the basic plezi framework and server\ngem 'plezi', '~> #{Plezi::VERSION}'\n"
|
70
|
+
app_tree["Gemfile"] << IO.read( File.join(@root,"resources" ,"Gemfile"))
|
71
|
+
app_tree["Gemfile"] << "\n\n\nruby '#{RUBY_VERSION}'\n"
|
71
72
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
73
|
+
# set up config files
|
74
|
+
app_tree["initialize"] ||= {}
|
75
|
+
app_tree["initialize"]["oauth.rb"] ||= IO.read(File.join(@root,"resources" ,"oauth_config.rb"))
|
76
|
+
app_tree["initialize"]["active_record.rb"] ||= IO.read(File.join(@root,"resources" ,"db_ac_config.rb"))
|
77
|
+
app_tree["initialize"]["sequel.rb"] ||= IO.read(File.join(@root,"resources" ,"db_sequel_config.rb"))
|
78
|
+
app_tree["initialize"]["datamapper.rb"] ||= IO.read(File.join(@root,"resources" ,"db_dm_config.rb"))
|
79
|
+
app_tree["initialize"]["haml.rb"] ||= IO.read(File.join(@root,"resources" ,"haml_config.rb"))
|
80
|
+
app_tree["initialize"]["slim.rb"] ||= IO.read(File.join(@root,"resources" ,"slim_config.rb"))
|
81
|
+
app_tree["initialize"]["i18n.rb"] ||= IO.read(File.join(@root,"resources" ,"i18n_config.rb"))
|
82
|
+
app_tree["initialize"]["redis.rb"] ||= (IO.read(File.join(@root,"resources" ,"redis_config.rb"))).gsub('appsecret', "#{app_name}_#{SecureRandom.hex}")
|
82
83
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
84
|
+
#set up database stub folders
|
85
|
+
app_tree["db"] ||= {}
|
86
|
+
app_tree["db"]["migrate"] ||= {}
|
87
|
+
app_tree["db"]["fixtures"] ||= {}
|
88
|
+
app_tree["db"]["config.yml"] ||= IO.read(File.join(@root,"resources" ,"database.yml"))
|
88
89
|
|
89
|
-
|
90
|
-
|
91
|
-
|
90
|
+
#set up the extras folder, to be filled with future goodies.
|
91
|
+
# app_tree["extras"] ||= {}
|
92
|
+
# app_tree["extras"]["config.ru"] ||= IO.read File.join(@root,"resources" ,"config.ru")
|
92
93
|
|
93
|
-
|
94
|
-
|
95
|
-
|
94
|
+
#set up I18n stub
|
95
|
+
app_tree["locales"] ||= {}
|
96
|
+
app_tree["locales"]["en.yml"] ||= IO.read File.join(@root,"resources" ,"en.yml")
|
96
97
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
98
|
+
# create library, log and tmp folders
|
99
|
+
app_tree["logs"] ||= {}
|
100
|
+
app_tree["lib"] ||= {}
|
101
|
+
app_tree["tmp"] ||= {}
|
101
102
|
|
102
103
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
104
|
+
# set up a public folder for static file service
|
105
|
+
app_tree["public"] ||= {}
|
106
|
+
app_tree["public"]["assets"] ||= {}
|
107
|
+
app_tree["public"]["assets"]["stylesheets"] ||= {}
|
108
|
+
app_tree["public"]["assets"]["javascripts"] ||= {}
|
109
|
+
app_tree["public"]["images"] ||= {}
|
110
|
+
finalize app_name
|
111
|
+
end
|
112
|
+
def finalize app_name = ARGV[1]
|
113
|
+
begin
|
114
|
+
Dir.mkdir app_name
|
115
|
+
puts "created the #{app_name} application directory.".green
|
116
|
+
rescue => e
|
117
|
+
puts "the #{app_name} application directory exists - trying to rebuild (no overwrite).".pink
|
118
|
+
end
|
119
|
+
Dir.chdir app_name
|
120
|
+
puts "starting to write template data...".red
|
121
|
+
puts ""
|
122
|
+
Builder.write_files app_tree
|
123
|
+
File.chmod 0775, "#{app_name}" rescue true
|
124
|
+
puts "done."
|
125
|
+
puts "\n#{@end_comments.join("\n")}" unless @end_comments.empty?
|
126
|
+
puts ""
|
127
|
+
puts "please change directory into the app directory: cd #{app_name}"
|
128
|
+
puts ""
|
129
|
+
puts "run the #{app_name} app using: ./#{app_name} or using: plezi s"
|
130
|
+
puts ""
|
117
131
|
end
|
118
|
-
Dir.chdir app_name
|
119
|
-
puts "starting to write template data...".red
|
120
|
-
puts ""
|
121
|
-
Builder.write_files app_tree
|
122
|
-
File.chmod 0775, "#{app_name}" rescue true
|
123
|
-
puts "done."
|
124
|
-
puts "\n#{@end_comments.join("\n")}" unless @end_comments.empty?
|
125
|
-
puts ""
|
126
|
-
puts "please change directory into the app directory: cd #{app_name}"
|
127
|
-
puts ""
|
128
|
-
puts "run the #{app_name} app using: ./#{app_name} or using: plezi s"
|
129
|
-
puts ""
|
130
132
|
end
|
131
133
|
end
|
132
134
|
end
|
@@ -1,36 +1,38 @@
|
|
1
1
|
module Plezi
|
2
|
-
module
|
2
|
+
module Base
|
3
|
+
module Builder
|
3
4
|
|
4
|
-
|
5
|
+
GEM_ROOT = ::File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..'))
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
7
|
+
def self.write_files files, parent = "."
|
8
|
+
if files.is_a? Hash
|
9
|
+
files.each do |k, v|
|
10
|
+
if v.is_a? Hash
|
11
|
+
begin
|
12
|
+
Dir.mkdir k
|
13
|
+
puts " created #{parent}/#{k}".green
|
14
|
+
rescue => e
|
15
|
+
puts " exists #{parent}/#{k}".red
|
16
|
+
end
|
17
|
+
Dir.chdir k
|
18
|
+
write_files v, (parent + "/" + k)
|
19
|
+
Dir.chdir ".."
|
20
|
+
elsif v.is_a? String
|
21
|
+
if ::File.exists? k
|
22
|
+
if false #%w{Gemfile rakefile.rb}.include? k
|
23
|
+
# old = IO.read k
|
24
|
+
# old = (old.lines.map {|l| "\##{l}"}).join
|
25
|
+
# IO.write k, "#####################\n#\n# OLD DATA COMMENTED OUT - PLEASE REVIEW\n#\n##{old}\n#{v}"
|
26
|
+
# puts " #{parent}/#{k} WAS OVERWRITTEN, old data was preserved by comenting it out.".pink
|
27
|
+
# puts " #{parent}/#{k} PLEASE REVIEW.".pink
|
28
|
+
# @end_comments << "#{parent}/#{k} WAS OVERWRITTEN, old data was preserved by comenting it out. PLEASE REVIEW."
|
29
|
+
else
|
30
|
+
puts " EXISTS(!) #{parent}/#{k}".red
|
31
|
+
end
|
28
32
|
else
|
29
|
-
|
33
|
+
IO.write k, v
|
34
|
+
puts " wrote #{parent}/#{k}".yellow
|
30
35
|
end
|
31
|
-
else
|
32
|
-
IO.write k, v
|
33
|
-
puts " wrote #{parent}/#{k}".yellow
|
34
36
|
end
|
35
37
|
end
|
36
38
|
end
|
@@ -2,23 +2,26 @@ require 'plezi/builders/builder'
|
|
2
2
|
|
3
3
|
module Plezi
|
4
4
|
|
5
|
-
module
|
5
|
+
module Base
|
6
6
|
|
7
|
-
|
8
|
-
MODEL_BUILDERS = %w{ Squel }
|
7
|
+
module FormBuilder
|
9
8
|
|
10
|
-
|
9
|
+
FORM_BUILDERS = %w{ Slim ERB }
|
10
|
+
MODEL_BUILDERS = %w{ Squel }
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
12
|
+
DB_TYPES = %w{primary_key string text integer float decimal datetime time date binary boolean}
|
13
|
+
|
14
|
+
@gem_root = ::Plezi::Builder::GEM_ROOT
|
15
|
+
def self.parse_args
|
16
|
+
return unless ARGS[0][0] == 'g'
|
17
|
+
struct = {}
|
18
|
+
ARGS[1..-1].each do |s|
|
19
|
+
s = s.split /[\:\.]/
|
20
|
+
raise "Cannot parse parameters - need to be defined as name.type or name:type." if s.count !=2
|
21
|
+
struct[s[0]] = DB_TYPES[s[1].downcase] || (raise "Unrecognized type #{s[1]}.")
|
22
|
+
end
|
23
|
+
struct
|
20
24
|
end
|
21
|
-
struct
|
22
25
|
end
|
23
26
|
end
|
24
27
|
end
|