lotusrb 0.4.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +18 -0
  3. data/FEATURES.md +7 -0
  4. data/README.md +2 -1
  5. data/lib/lotus/cli.rb +2 -1
  6. data/lib/lotus/commands/generate.rb +4 -0
  7. data/lib/lotus/config/assets.rb +46 -8
  8. data/lib/lotus/configuration.rb +119 -11
  9. data/lib/lotus/environment.rb +1 -1
  10. data/lib/lotus/frameworks.rb +2 -0
  11. data/lib/lotus/generators/action.rb +22 -1
  12. data/lib/lotus/generators/action/action_spec.rspec.tt +2 -3
  13. data/lib/lotus/generators/action/view_spec.rspec.tt +2 -3
  14. data/lib/lotus/generators/application/app.rb +22 -79
  15. data/lib/lotus/generators/application/app/Gemfile.tt +1 -0
  16. data/lib/lotus/generators/application/app/config/application.rb.tt +8 -3
  17. data/lib/lotus/generators/application/app/lib/app_name.rb.tt +12 -0
  18. data/lib/lotus/generators/application/container.rb +18 -84
  19. data/lib/lotus/generators/application/container/Gemfile.tt +3 -2
  20. data/lib/lotus/generators/application/container/lib/app_name.rb.tt +12 -0
  21. data/lib/lotus/generators/database_config.rb +86 -0
  22. data/lib/lotus/generators/mailer.rb +112 -0
  23. data/lib/lotus/generators/mailer/mailer.rb.tt +7 -0
  24. data/lib/lotus/generators/mailer/mailer_spec.rb.tt +7 -0
  25. data/lib/lotus/generators/mailer/template.html.tt +0 -0
  26. data/lib/lotus/generators/mailer/template.txt.tt +0 -0
  27. data/lib/lotus/generators/model/entity_spec.rspec.tt +0 -2
  28. data/lib/lotus/generators/model/repository_spec.rspec.tt +0 -2
  29. data/lib/lotus/generators/slice/application.rb.tt +8 -3
  30. data/lib/lotus/generators/slice/templates/application.html.erb.tt +1 -1
  31. data/lib/lotus/loader.rb +10 -3
  32. data/lib/lotus/mailer/glue.rb +68 -0
  33. data/lib/lotus/middleware.rb +3 -3
  34. data/lib/lotus/version.rb +1 -1
  35. data/lotusrb.gemspec +6 -5
  36. metadata +38 -11
@@ -1,13 +1,12 @@
1
- require 'spec_helper'
2
1
  require_relative '<%= config[:relative_view_path] %>'
3
2
 
4
3
  describe <%= config[:app] %>::Views::<%= config[:controller] %>::<%= config[:action] %> do
5
4
  let(:exposures) { Hash[foo: 'bar'] }
6
5
  let(:template) { Lotus::View::Template.new('<%= config[:template_path] %>') }
7
- let(:view) { <%= config[:app] %>::Views::<%= config[:controller] %>::<%= config[:action] %>.new(template, exposures) }
6
+ let(:view) { described_class.new(template, exposures) }
8
7
  let(:rendered) { view.render }
9
8
 
10
- it "exposes #foo" do
9
+ it 'exposes #foo' do
11
10
  expect(view.foo).to eq exposures.fetch(:foo)
12
11
  end
13
12
  end
@@ -1,5 +1,6 @@
1
1
  require 'shellwords'
2
2
  require 'lotus/generators/abstract'
3
+ require 'lotus/generators/database_config'
3
4
 
4
5
  module Lotus
5
6
  module Generators
@@ -8,13 +9,13 @@ module Lotus
8
9
  def initialize(command)
9
10
  super
10
11
 
11
- @upcase_app_name = app_name.to_env_s
12
- @classified_app_name = Utils::String.new(app_name).classify
13
- @lotus_head = options.fetch(:lotus_head)
14
- @test = options[:test]
15
- @database = options[:database]
16
- @application_base_url = options[:application_base_url]
17
- @lotus_model_version = '~> 0.4'
12
+ @upcase_app_name = app_name.to_env_s
13
+ @classified_app_name = Utils::String.new(app_name).classify
14
+ @lotus_head = options.fetch(:lotus_head)
15
+ @test = options[:test]
16
+ @database_config = DatabaseConfig.new(options[:database], app_name)
17
+ @application_base_url = options[:application_base_url]
18
+ @lotus_model_version = '~> 0.5'
18
19
 
19
20
  cli.class.source_root(source)
20
21
  end
@@ -22,15 +23,15 @@ module Lotus
22
23
  def start
23
24
 
24
25
  opts = {
25
- app_name: app_name,
26
- upcase_app_name: @upcase_app_name,
27
- classified_app_name: @classified_app_name,
28
- application_base_url: @application_base_url,
29
- lotus_head: @lotus_head,
30
- test: @test,
31
- database: @database,
32
- database_config: database_config,
33
- lotus_model_version: @lotus_model_version,
26
+ app_name: app_name,
27
+ upcase_app_name: @upcase_app_name,
28
+ classified_app_name: @classified_app_name,
29
+ application_base_url: @application_base_url,
30
+ lotus_head: @lotus_head,
31
+ test: @test,
32
+ database: @database_config.engine,
33
+ database_config: @database_config.to_hash,
34
+ lotus_model_version: @lotus_model_version,
34
35
  }
35
36
 
36
37
  templates = {
@@ -54,11 +55,12 @@ module Lotus
54
55
  "app/views",
55
56
  "lib/#{ app_name }/entities",
56
57
  "lib/#{ app_name }/repositories",
58
+ "lib/#{ app_name }/mailers",
57
59
  "public/javascripts",
58
60
  "public/stylesheets"
59
61
  ]
60
62
 
61
- empty_directories << if sql_database?
63
+ empty_directories << if @database_config.sql?
62
64
  "db/migrations"
63
65
  else
64
66
  "db"
@@ -91,10 +93,11 @@ module Lotus
91
93
  empty_directories << [
92
94
  "spec/#{ app_name }/entities",
93
95
  "spec/#{ app_name }/repositories",
96
+ "spec/#{ app_name }/mailers",
94
97
  "spec/support"
95
98
  ]
96
99
 
97
- if sql_database?
100
+ if @database_config.sql?
98
101
  templates.merge!(
99
102
  'schema.sql.tt' => 'db/schema.sql'
100
103
  )
@@ -110,7 +113,7 @@ module Lotus
110
113
  end
111
114
 
112
115
  unless git_dir_present?
113
- cli.template(source.join(database_type == :file_system ? 'gitignore.tt' : '.gitignore'), target.join('.gitignore'), opts)
116
+ cli.template(source.join(@database_config.type == :file_system ? 'gitignore.tt' : '.gitignore'), target.join('.gitignore'), opts)
114
117
  cli.run("git init #{Shellwords.escape(target)}", capture: true)
115
118
  end
116
119
  end
@@ -120,66 +123,6 @@ module Lotus
120
123
  def git_dir_present?
121
124
  File.directory?(source.join('.git'))
122
125
  end
123
-
124
- def database_config
125
- {
126
- gem: database_gem,
127
- uri: database_uri,
128
- type: database_type
129
- }
130
- end
131
-
132
- def database_gem
133
- {
134
- 'mysql' => 'mysql',
135
- 'mysql2' => 'mysql2',
136
- 'postgresql' => 'pg',
137
- 'postgres' => 'pg',
138
- 'sqlite' => 'sqlite3',
139
- 'sqlite3' => 'sqlite3'
140
- }[@database]
141
- end
142
-
143
- def sql_database?
144
- database_type == :sql
145
- end
146
-
147
- def database_type
148
- case @database
149
- when 'mysql', 'mysql2', 'postgresql', 'postgres', 'sqlite', 'sqlite3'
150
- :sql
151
- when 'filesystem'
152
- :file_system
153
- when 'memory'
154
- :memory
155
- end
156
- end
157
-
158
- def database_uri
159
- {
160
- development: "#{database_base_uri}_development",
161
- test: "#{database_base_uri}_test"
162
- }
163
- end
164
-
165
- def database_base_uri
166
- case @database
167
- when 'mysql'
168
- "mysql://localhost/#{app_name}"
169
- when 'mysql2'
170
- "mysql2://localhost/#{app_name}"
171
- when 'postgresql', 'postgres'
172
- "postgres://localhost/#{app_name}"
173
- when 'sqlite', 'sqlite3'
174
- "sqlite://db/#{Shellwords.escape(app_name)}"
175
- when 'memory'
176
- "memory://localhost/#{app_name}"
177
- when 'filesystem'
178
- "file:///db/#{app_name}"
179
- else
180
- raise "\"#{@database}\" is not a valid database type"
181
- end
182
- end
183
126
  end
184
127
  end
185
128
  end
@@ -11,6 +11,7 @@ gem 'lotus-helpers', require: false, github: 'lotus/helpers'
11
11
  gem 'lotus-controller', require: false, github: 'lotus/controller'
12
12
  gem 'lotus-view', require: false, github: 'lotus/view'
13
13
  gem 'lotus-model', require: false, github: 'lotus/model'
14
+ gem 'lotus-mailer', require: false, github: 'lotus/mailer'
14
15
  gem 'lotusrb', github: 'lotus/lotus'
15
16
  <%- else -%>
16
17
  gem 'lotusrb', '<%= Lotus::VERSION %>'
@@ -84,7 +84,12 @@ module <%= config[:classified_app_name] %>
84
84
  # Default format for the requests that don't specify an HTTP_ACCEPT header
85
85
  # Argument: A symbol representation of a mime type, default to :html
86
86
  #
87
- # default_format :html
87
+ # default_request_format :html
88
+
89
+ # Default format for responses that doesn't take into account the request format
90
+ # Argument: A symbol representation of a mime type, default to :html
91
+ #
92
+ # default_response_format :html
88
93
 
89
94
  # HTTP Body parsers
90
95
  # Parse non GET responses body for a specific mime type
@@ -146,7 +151,7 @@ module <%= config[:classified_app_name] %>
146
151
  # Web applications can send this header to mitigate Cross Site Scripting
147
152
  # (XSS) attacks.
148
153
  #
149
- # The default value allows images, scripts, AJAX, and CSS from the same
154
+ # The default value allows images, scripts, AJAX, fonts and CSS from the same
150
155
  # origin, and does not allow any other resources to load (eg object,
151
156
  # frame, media, etc).
152
157
  #
@@ -169,7 +174,7 @@ module <%= config[:classified_app_name] %>
169
174
  # * http://content-security-policy.com/
170
175
  # * https://developer.mozilla.org/en-US/docs/Web/Security/CSP/Using_Content_Security_Policy
171
176
  #
172
- security.content_security_policy "default-src 'none'; script-src 'self'; connect-src 'self'; img-src 'self'; style-src 'self';"
177
+ security.content_security_policy "default-src 'none'; script-src 'self'; connect-src 'self'; img-src 'self'; style-src 'self'; font-src 'self';"
173
178
 
174
179
  ##
175
180
  # FRAMEWORKS
@@ -1,4 +1,5 @@
1
1
  require 'lotus/model'
2
+ require 'lotus/mailer'
2
3
  Dir["#{ __dir__ }/<%= config[:app_name] %>/**/*.rb"].each { |file| require_relative file }
3
4
 
4
5
  Lotus::Model.configure do
@@ -45,3 +46,14 @@ Lotus::Model.configure do
45
46
  # end
46
47
  end
47
48
  end.load!
49
+
50
+ Lotus::Mailer.configure do
51
+ root "#{ __dir__ }/<%= config[:app_name] %>/mailers"
52
+
53
+ # See http://lotusrb.org/guides/mailers/delivery
54
+ delivery do
55
+ development :test
56
+ test :test
57
+ # production :stmp, address: ENV['SMTP_PORT'], port: 1025
58
+ end
59
+ end.load!
@@ -1,5 +1,6 @@
1
1
  require 'shellwords'
2
2
  require 'lotus/generators/abstract'
3
+ require 'lotus/generators/database_config'
3
4
  require 'lotus/generators/slice'
4
5
 
5
6
  module Lotus
@@ -9,23 +10,23 @@ module Lotus
9
10
  def initialize(command)
10
11
  super
11
12
 
12
- @slice_generator = Slice.new(command)
13
- @lotus_head = options.fetch(:lotus_head)
14
- @test = options[:test]
15
- @database = options[:database]
16
- @lotus_model_version = '~> 0.4'
13
+ @slice_generator = Slice.new(command)
14
+ @database_config = DatabaseConfig.new(options[:database], app_name)
15
+ @lotus_head = options.fetch(:lotus_head)
16
+ @test = options[:test]
17
+ @lotus_model_version = '~> 0.5'
17
18
 
18
19
  cli.class.source_root(source)
19
20
  end
20
21
 
21
22
  def start
22
23
  opts = {
23
- app_name: app_name,
24
- lotus_head: @lotus_head,
25
- test: @test,
26
- database: @database,
27
- database_config: database_config,
28
- lotus_model_version: @lotus_model_version,
24
+ app_name: app_name,
25
+ lotus_head: @lotus_head,
26
+ test: @test,
27
+ database: @database_config.engine,
28
+ database_config: @database_config.to_hash,
29
+ lotus_model_version: @lotus_model_version,
29
30
  }
30
31
 
31
32
  templates = {
@@ -42,10 +43,11 @@ module Lotus
42
43
 
43
44
  empty_directories = [
44
45
  "lib/#{ app_name }/entities",
45
- "lib/#{ app_name }/repositories"
46
+ "lib/#{ app_name }/repositories",
47
+ "lib/#{ app_name }/mailers"
46
48
  ]
47
49
 
48
- empty_directories << if sql_database?
50
+ empty_directories << if @database_config.sql?
49
51
  "db/migrations"
50
52
  else
51
53
  "db"
@@ -68,7 +70,7 @@ module Lotus
68
70
  )
69
71
  end
70
72
 
71
- if sql_database?
73
+ if @database_config.sql?
72
74
  templates.merge!(
73
75
  'schema.sql.tt' => 'db/schema.sql'
74
76
  )
@@ -77,6 +79,7 @@ module Lotus
77
79
  empty_directories << [
78
80
  "spec/#{ app_name }/entities",
79
81
  "spec/#{ app_name }/repositories",
82
+ "spec/#{ app_name }/mailers",
80
83
  "spec/support"
81
84
  ]
82
85
 
@@ -90,7 +93,7 @@ module Lotus
90
93
  end
91
94
 
92
95
  unless git_dir_present?
93
- cli.template(source.join(database_type == :file_system ? 'gitignore.tt' : '.gitignore'), target.join('.gitignore'), opts)
96
+ cli.template(source.join(@database_config.type == :file_system ? 'gitignore.tt' : '.gitignore'), target.join('.gitignore'), opts)
94
97
  cli.run("git init #{Shellwords.escape(target)}", capture: true)
95
98
  end
96
99
 
@@ -102,75 +105,6 @@ module Lotus
102
105
  def git_dir_present?
103
106
  File.directory?(source.join('.git'))
104
107
  end
105
-
106
- def database_config
107
- {
108
- gem: database_gem,
109
- uri: database_uri,
110
- type: database_type
111
- }
112
- end
113
-
114
- def database_gem
115
- {
116
- 'mysql' => 'mysql',
117
- 'mysql2' => 'mysql2',
118
- 'postgresql' => 'pg',
119
- 'postgres' => 'pg',
120
- 'sqlite' => 'sqlite3',
121
- 'sqlite3' => 'sqlite3'
122
- }[@database]
123
- end
124
-
125
- def database_type
126
- case @database
127
- when 'mysql', 'mysql2', 'postgresql', 'postgres', 'sqlite', 'sqlite3'
128
- :sql
129
- when 'filesystem'
130
- :file_system
131
- when 'memory'
132
- :memory
133
- end
134
- end
135
-
136
- def sql_database?
137
- database_type == :sql
138
- end
139
-
140
- def database_uri
141
- {
142
- development: database_environment_uri(:development),
143
- test: database_environment_uri(:test)
144
- }
145
- end
146
-
147
- def database_base_uri
148
- case @database
149
- when 'mysql'
150
- "mysql://localhost/#{app_name}"
151
- when 'mysql2'
152
- "mysql2://localhost/#{app_name}"
153
- when 'postgresql', 'postgres'
154
- "postgres://localhost/#{app_name}"
155
- when 'sqlite', 'sqlite3'
156
- "sqlite://db/#{Shellwords.escape(app_name)}"
157
- when 'memory'
158
- "memory://localhost/#{app_name}"
159
- when 'filesystem'
160
- "file:///db/#{app_name}"
161
- else
162
- raise "\"#{@database}\" is not a valid database type"
163
- end
164
- end
165
-
166
- def database_environment_uri(environment)
167
- case @database
168
- when 'sqlite', 'sqlite3'
169
- "#{database_base_uri}_#{environment}.sqlite"
170
- else
171
- "#{database_base_uri}_#{environment}"
172
- end
173
- end
174
108
  end
175
109
  end
176
110
  end
@@ -11,10 +11,11 @@ gem 'lotus-helpers', require: false, github: 'lotus/helpers'
11
11
  gem 'lotus-controller', require: false, github: 'lotus/controller'
12
12
  gem 'lotus-view', require: false, github: 'lotus/view'
13
13
  gem 'lotus-model', require: false, github: 'lotus/model'
14
+ gem 'lotus-mailer', require: false, github: 'lotus/mailer'
14
15
  gem 'lotusrb', github: 'lotus/lotus'
15
16
  <%- else -%>
16
- gem 'lotusrb', '<%= Lotus::VERSION %>'
17
- gem 'lotus-model', '<%= config[:lotus_model_version] %>'
17
+ gem 'lotusrb', '<%= Lotus::VERSION %>'
18
+ gem 'lotus-model', '<%= config[:lotus_model_version] %>'
18
19
  <%- end -%>
19
20
 
20
21
  <%- if config[:database_config][:gem] %>
@@ -1,4 +1,5 @@
1
1
  require 'lotus/model'
2
+ require 'lotus/mailer'
2
3
  Dir["#{ __dir__ }/<%= config[:app_name] %>/**/*.rb"].each { |file| require_relative file }
3
4
 
4
5
  Lotus::Model.configure do
@@ -46,3 +47,14 @@ Lotus::Model.configure do
46
47
  # end
47
48
  end
48
49
  end.load!
50
+
51
+ Lotus::Mailer.configure do
52
+ root "#{ __dir__ }/<%= config[:app_name] %>/mailers"
53
+
54
+ # See http://lotusrb.org/guides/mailers/delivery
55
+ delivery do
56
+ development :test
57
+ test :test
58
+ # production :stmp, address: ENV['SMTP_PORT'], port: 1025
59
+ end
60
+ end.load!
@@ -0,0 +1,86 @@
1
+ module Lotus
2
+ module Generators
3
+ class DatabaseConfig
4
+ SUPPORTED_ENGINES = {
5
+ 'mysql' => { type: :sql, mri: 'mysql2', jruby: 'jdbc-mysql' },
6
+ 'mysql2' => { type: :sql, mri: 'mysql2', jruby: 'jdbc-mysql' },
7
+ 'postgresql' => { type: :sql, mri: 'pg', jruby: 'jdbc-postgres' },
8
+ 'postgres' => { type: :sql, mri: 'pg', jruby: 'jdbc-postgres' },
9
+ 'sqlite' => { type: :sql, mri: 'sqlite3', jruby: 'jdbc-sqlite3' },
10
+ 'sqlite3' => { type: :sql, mri: 'sqlite3', jruby: 'jdbc-sqlite3' },
11
+ 'filesystem' => { type: :file_system, mri: nil, jruby: nil },
12
+ 'memory' => { type: :memory, mri: nil, jruby: nil }
13
+ }.freeze
14
+
15
+ attr_reader :engine, :name
16
+
17
+ def initialize(engine, name)
18
+ @engine = engine
19
+ @name = name
20
+
21
+ SUPPORTED_ENGINES.key?(engine) or fail "\"#{ engine }\" is not a valid database type"
22
+ end
23
+
24
+ def to_hash
25
+ {
26
+ gem: gem,
27
+ uri: uri,
28
+ type: type
29
+ }
30
+ end
31
+
32
+ def type
33
+ SUPPORTED_ENGINES[engine][:type]
34
+ end
35
+
36
+ def sql?
37
+ type == :sql
38
+ end
39
+
40
+ private
41
+
42
+ def platform
43
+ Lotus::Utils.jruby? ? :jruby : :mri
44
+ end
45
+
46
+ def platform_prefix
47
+ :jdbc if Lotus::Utils.jruby?
48
+ end
49
+
50
+ def uri
51
+ {
52
+ development: environment_uri(:development),
53
+ test: environment_uri(:test)
54
+ }
55
+ end
56
+
57
+ def gem
58
+ SUPPORTED_ENGINES[engine][platform]
59
+ end
60
+
61
+ def base_uri
62
+ case engine
63
+ when 'mysql', 'mysql2'
64
+ "mysql2://localhost/#{ name }"
65
+ when 'postgresql', 'postgres'
66
+ "postgres://localhost/#{ name }"
67
+ when 'sqlite', 'sqlite3'
68
+ "sqlite://db/#{ Shellwords.escape(name) }"
69
+ when 'memory'
70
+ "memory://localhost/#{ name }"
71
+ when 'filesystem'
72
+ "file:///db/#{ Shellwords.escape(name) }"
73
+ end
74
+ end
75
+
76
+ def environment_uri(environment)
77
+ case engine
78
+ when 'sqlite', 'sqlite3'
79
+ "#{ platform_prefix }#{ base_uri }_#{ environment }.sqlite"
80
+ else
81
+ "#{ platform_prefix }#{ base_uri }_#{ environment }"
82
+ end
83
+ end
84
+ end
85
+ end
86
+ end