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
@@ -0,0 +1,112 @@
1
+ require 'lotus/generators/abstract'
2
+ require 'lotus/utils/string'
3
+
4
+ module Lotus
5
+ module Generators
6
+ # @since 0.5.0
7
+ # @api private
8
+ class Mailer < Abstract
9
+
10
+ # @since 0.5.0
11
+ # @api private
12
+ TXT_FORMAT = '.txt'.freeze
13
+
14
+ # @since 0.5.0
15
+ # @api private
16
+ HTML_FORMAT = '.html'.freeze
17
+
18
+ # @since 0.5.0
19
+ # @api private
20
+ DEFAULT_ENGINE = 'erb'.freeze
21
+
22
+ # @since 0.5.0
23
+ # @api private
24
+ DEFAULT_FROM = "'<from>'".freeze
25
+
26
+ # @since 0.5.0
27
+ # @api private
28
+ DEFAULT_TO = "'<to>'".freeze
29
+
30
+ # @since 0.5.0
31
+ # @api private
32
+ DEFAULT_SUBJECT = "'Hello'".freeze
33
+
34
+ # @since 0.5.0
35
+ # @api private
36
+ def initialize(command)
37
+ super
38
+
39
+ @mailer_name = Utils::String.new(name).classify
40
+ cli.class.source_root(source)
41
+ end
42
+
43
+ # @since 0.5.0
44
+ # @api private
45
+ def start
46
+ assert_mailer!
47
+
48
+ opts = {
49
+ mailer: @mailer_name,
50
+ from: DEFAULT_FROM,
51
+ to: DEFAULT_TO,
52
+ subject: DEFAULT_SUBJECT,
53
+ }
54
+
55
+ templates = {
56
+ 'mailer_spec.rb.tt' => _mailer_spec_path,
57
+ 'mailer.rb.tt' => _mailer_path,
58
+ 'template.txt.tt' => _txt_template_path,
59
+ 'template.html.tt' => _html_template_path,
60
+ }
61
+
62
+ templates.each do |src, dst|
63
+ cli.template(source.join(src), target.join(dst), opts)
64
+ end
65
+ end
66
+
67
+ # @since 0.5.0
68
+ # @api private
69
+ def assert_mailer!
70
+ if @mailer_name.nil? || @mailer_name.empty?
71
+ raise Lotus::Commands::Generate::Error.new("Missing mailer name")
72
+ end
73
+ end
74
+
75
+ # @since 0.5.0
76
+ # @api private
77
+ def _mailer_path
78
+ core_root.join('mailers', "#{ name }.rb").to_s
79
+ end
80
+
81
+ # @since 0.5.0
82
+ # @api private
83
+ def _mailer_spec_path
84
+ spec_root.join(::File.basename(Dir.getwd), 'mailers', "#{ name }_spec.rb")
85
+ end
86
+
87
+ # @since 0.5.0
88
+ # @api private
89
+ def _txt_template_path
90
+ __template_path(TXT_FORMAT)
91
+ end
92
+
93
+ # @since 0.5.0
94
+ # @api private
95
+ def _html_template_path
96
+ __template_path(HTML_FORMAT)
97
+ end
98
+
99
+ # @since 0.5.0
100
+ # @api private
101
+ def __template_path(format)
102
+ core_root.join('mailers', 'templates', "#{ name }#{ format }.#{ DEFAULT_ENGINE }")
103
+ end
104
+
105
+ # @since 0.5.0
106
+ # @api private
107
+ def name
108
+ Utils::String.new(app_name || super).underscore
109
+ end
110
+ end
111
+ end
112
+ end
@@ -0,0 +1,7 @@
1
+ class Mailers::<%= config[:mailer] %>
2
+ include Lotus::Mailer
3
+
4
+ from <%= config[:from] %>
5
+ to <%= config[:to] %>
6
+ subject <%= config[:subject] %>
7
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe Mailers::<%= config[:mailer] %> do
4
+ it 'delivers email' do
5
+ mail = Mailers::<%= config[:mailer] %>.deliver
6
+ end
7
+ end
File without changes
File without changes
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  RSpec.describe <%= config[:model_name] %> do
4
2
  # place your tests here
5
3
  end
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  RSpec.describe <%= config[:model_name] %>Repository do
4
2
  # place your tests here
5
3
  end
@@ -82,7 +82,12 @@ module <%= config[:classified_slice_name] %>
82
82
  # Default format for the requests that don't specify an HTTP_ACCEPT header
83
83
  # Argument: A symbol representation of a mime type, default to :html
84
84
  #
85
- # default_format :html
85
+ # default_request_format :html
86
+
87
+ # Default format for responses that doesn't take into account the request format
88
+ # Argument: A symbol representation of a mime type, default to :html
89
+ #
90
+ # default_response_format :html
86
91
 
87
92
  # HTTP Body parsers
88
93
  # Parse non GET responses body for a specific mime type
@@ -149,7 +154,7 @@ module <%= config[:classified_slice_name] %>
149
154
  # Web applications can send this header to mitigate Cross Site Scripting
150
155
  # (XSS) attacks.
151
156
  #
152
- # The default value allows images, scripts, AJAX, and CSS from the same
157
+ # The default value allows images, scripts, AJAX, fonts and CSS from the same
153
158
  # origin, and does not allow any other resources to load (eg object,
154
159
  # frame, media, etc).
155
160
  #
@@ -172,7 +177,7 @@ module <%= config[:classified_slice_name] %>
172
177
  # * http://content-security-policy.com/
173
178
  # * https://developer.mozilla.org/en-US/docs/Web/Security/CSP/Using_Content_Security_Policy
174
179
  #
175
- security.content_security_policy "default-src 'none'; script-src 'self'; connect-src 'self'; img-src 'self'; style-src 'self';"
180
+ security.content_security_policy "default-src 'none'; script-src 'self'; connect-src 'self'; img-src 'self'; style-src 'self'; font-src 'self';"
176
181
 
177
182
  ##
178
183
  # FRAMEWORKS
@@ -1,4 +1,4 @@
1
- <!doctype HTML>
1
+ <!DOCTYPE html>
2
2
  <html>
3
3
  <head>
4
4
  <title><%= config[:classified_slice_name] %></title>
data/lib/lotus/loader.rb CHANGED
@@ -53,7 +53,8 @@ module Lotus
53
53
  unless namespace.const_defined?('Controller')
54
54
  controller = Lotus::Controller.duplicate(namespace) do
55
55
  handle_exceptions config.handle_exceptions
56
- default_format config.default_format
56
+ default_request_format config.default_request_format
57
+ default_response_format config.default_response_format
57
58
  default_headers({
58
59
  Lotus::Config::Security::X_FRAME_OPTIONS_HEADER => config.security.x_frame_options,
59
60
  Lotus::Config::Security::CONTENT_SECURITY_POLICY_HEADER => config.security.content_security_policy
@@ -112,8 +113,10 @@ module Lotus
112
113
 
113
114
  def _configure_logger!
114
115
  unless application_module.const_defined?('Logger', false)
115
- logger = Lotus::Logger.new(application_module.to_s)
116
- application_module.const_set('Logger', logger)
116
+ if configuration.logger.nil?
117
+ configuration.logger Lotus::Logger.new(application_module.to_s)
118
+ end
119
+ application_module.const_set('Logger', configuration.logger)
117
120
  end
118
121
  end
119
122
 
@@ -147,6 +150,10 @@ module Lotus
147
150
  defined?(Lotus::Model)
148
151
  end
149
152
 
153
+ def _lotus_mailer_loaded?
154
+ defined?(Lotus::Mailer)
155
+ end
156
+
150
157
  def load_configuration_load_paths!
151
158
  configuration.load_paths.load!(configuration.root)
152
159
  end
@@ -0,0 +1,68 @@
1
+ require 'lotus/utils/basic_object'
2
+
3
+ module Lotus::Mailer
4
+ # @since 0.5.0
5
+ # @api private
6
+ class Delivery < ::Lotus::Utils::BasicObject
7
+ # @since 0.5.0
8
+ # @api private
9
+ def initialize(env, &blk)
10
+ @env = env
11
+ instance_eval(&blk)
12
+ end
13
+
14
+ # @since 0.5.0
15
+ # @api private
16
+ def to_config
17
+ @config
18
+ end
19
+
20
+ # @since 0.5.0
21
+ # @api private
22
+ def test(*args)
23
+ __setup_config(:test, *args)
24
+ end
25
+
26
+ private
27
+
28
+ # @since 0.5.0
29
+ # @api private
30
+ def method_missing(m, *args)
31
+ __setup_config(m, *args)
32
+ end
33
+
34
+ # @since 0.5.0
35
+ # @api private
36
+ def __setup_config(env, *args)
37
+ if env.to_s == @env
38
+ @config = args
39
+ end
40
+ end
41
+ end
42
+
43
+
44
+ # @since 0.5.0
45
+ # @api private
46
+ module Glue
47
+
48
+ # @since 0.5.0
49
+ # @api private
50
+ def delivery(&blk)
51
+ raise ArgumentError unless block_given?
52
+ delivery_method(*Lotus::Mailer::Delivery.new(Lotus.env, &blk).to_config)
53
+ end
54
+ end
55
+
56
+ Configuration.class_eval do
57
+ include Glue
58
+ end
59
+ end
60
+
61
+ # @since 0.5.0
62
+ # @api private
63
+ module Mailers
64
+ end
65
+
66
+ Lotus::Mailer.configure do
67
+ namespace Mailers
68
+ end
@@ -94,7 +94,7 @@ module Lotus
94
94
  # @api private
95
95
  # @since 0.2.0
96
96
  def _load_default_welcome_page_for(application)
97
- unless application.routes.defined?
97
+ unless Lotus.env?(:test) || application.routes.defined?
98
98
  require 'lotus/welcome'
99
99
  use Lotus::Welcome
100
100
  end
@@ -116,8 +116,8 @@ module Lotus
116
116
  # #since 0.2.0
117
117
  def _load_asset_middlewares
118
118
  if @configuration.serve_assets
119
- @configuration.assets.entries.each do |path, children|
120
- use Rack::Static, urls: children, root: path
119
+ @configuration.assets.for_each_source do |source|
120
+ use Rack::Static, urls: source.urls, root: source.root
121
121
  end
122
122
  end
123
123
  end
data/lib/lotus/version.rb CHANGED
@@ -2,5 +2,5 @@ module Lotus
2
2
  # Defines the version
3
3
  #
4
4
  # @since 0.1.0
5
- VERSION = '0.4.1'.freeze
5
+ VERSION = '0.5.0'.freeze
6
6
  end
data/lotusrb.gemspec CHANGED
@@ -19,11 +19,12 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ['lib']
20
20
  spec.required_ruby_version = '>= 2.0.0'
21
21
 
22
- spec.add_dependency 'lotus-utils', '~> 0.5', '>= 0.5.1'
23
- spec.add_dependency 'lotus-router', '~> 0.4', '>= 0.4.2'
24
- spec.add_dependency 'lotus-controller', '~> 0.4', '>= 0.4.4'
25
- spec.add_dependency 'lotus-view', '~> 0.4', '>= 0.4.3'
26
- spec.add_dependency 'lotus-helpers', '~> 0.2'
22
+ spec.add_dependency 'lotus-utils', '~> 0.5', '>= 0.5.2'
23
+ spec.add_dependency 'lotus-router', '~> 0.4', '>= 0.4.3'
24
+ spec.add_dependency 'lotus-controller', '~> 0.4', '>= 0.4.5'
25
+ spec.add_dependency 'lotus-view', '~> 0.4', '>= 0.4.4'
26
+ spec.add_dependency 'lotus-helpers', '~> 0.2', '>= 0.2.5'
27
+ spec.add_dependency 'lotus-mailer', '~> 0.1'
27
28
  spec.add_dependency 'shotgun', '~> 0.9'
28
29
  spec.add_dependency 'dotenv', '~> 2.0'
29
30
  spec.add_dependency 'thor', '~> 0.19'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lotusrb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luca Guidi
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2015-07-10 00:00:00.000000000 Z
13
+ date: 2015-09-30 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: lotus-utils
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '0.5'
22
22
  - - ">="
23
23
  - !ruby/object:Gem::Version
24
- version: 0.5.1
24
+ version: 0.5.2
25
25
  type: :runtime
26
26
  prerelease: false
27
27
  version_requirements: !ruby/object:Gem::Requirement
@@ -31,7 +31,7 @@ dependencies:
31
31
  version: '0.5'
32
32
  - - ">="
33
33
  - !ruby/object:Gem::Version
34
- version: 0.5.1
34
+ version: 0.5.2
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: lotus-router
37
37
  requirement: !ruby/object:Gem::Requirement
@@ -41,7 +41,7 @@ dependencies:
41
41
  version: '0.4'
42
42
  - - ">="
43
43
  - !ruby/object:Gem::Version
44
- version: 0.4.2
44
+ version: 0.4.3
45
45
  type: :runtime
46
46
  prerelease: false
47
47
  version_requirements: !ruby/object:Gem::Requirement
@@ -51,7 +51,7 @@ dependencies:
51
51
  version: '0.4'
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: 0.4.2
54
+ version: 0.4.3
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: lotus-controller
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -61,7 +61,7 @@ dependencies:
61
61
  version: '0.4'
62
62
  - - ">="
63
63
  - !ruby/object:Gem::Version
64
- version: 0.4.4
64
+ version: 0.4.5
65
65
  type: :runtime
66
66
  prerelease: false
67
67
  version_requirements: !ruby/object:Gem::Requirement
@@ -71,7 +71,7 @@ dependencies:
71
71
  version: '0.4'
72
72
  - - ">="
73
73
  - !ruby/object:Gem::Version
74
- version: 0.4.4
74
+ version: 0.4.5
75
75
  - !ruby/object:Gem::Dependency
76
76
  name: lotus-view
77
77
  requirement: !ruby/object:Gem::Requirement
@@ -81,7 +81,7 @@ dependencies:
81
81
  version: '0.4'
82
82
  - - ">="
83
83
  - !ruby/object:Gem::Version
84
- version: 0.4.3
84
+ version: 0.4.4
85
85
  type: :runtime
86
86
  prerelease: false
87
87
  version_requirements: !ruby/object:Gem::Requirement
@@ -91,7 +91,7 @@ dependencies:
91
91
  version: '0.4'
92
92
  - - ">="
93
93
  - !ruby/object:Gem::Version
94
- version: 0.4.3
94
+ version: 0.4.4
95
95
  - !ruby/object:Gem::Dependency
96
96
  name: lotus-helpers
97
97
  requirement: !ruby/object:Gem::Requirement
@@ -99,6 +99,9 @@ dependencies:
99
99
  - - "~>"
100
100
  - !ruby/object:Gem::Version
101
101
  version: '0.2'
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: 0.2.5
102
105
  type: :runtime
103
106
  prerelease: false
104
107
  version_requirements: !ruby/object:Gem::Requirement
@@ -106,6 +109,23 @@ dependencies:
106
109
  - - "~>"
107
110
  - !ruby/object:Gem::Version
108
111
  version: '0.2'
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: 0.2.5
115
+ - !ruby/object:Gem::Dependency
116
+ name: lotus-mailer
117
+ requirement: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - "~>"
120
+ - !ruby/object:Gem::Version
121
+ version: '0.1'
122
+ type: :runtime
123
+ prerelease: false
124
+ version_requirements: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - "~>"
127
+ - !ruby/object:Gem::Version
128
+ version: '0.1'
109
129
  - !ruby/object:Gem::Dependency
110
130
  name: shotgun
111
131
  requirement: !ruby/object:Gem::Requirement
@@ -320,6 +340,12 @@ files:
320
340
  - lib/lotus/generators/application/container/schema.sql.tt
321
341
  - lib/lotus/generators/application/container/spec_helper.rb.minitest.tt
322
342
  - lib/lotus/generators/application/container/spec_helper.rb.rspec.tt
343
+ - lib/lotus/generators/database_config.rb
344
+ - lib/lotus/generators/mailer.rb
345
+ - lib/lotus/generators/mailer/mailer.rb.tt
346
+ - lib/lotus/generators/mailer/mailer_spec.rb.tt
347
+ - lib/lotus/generators/mailer/template.html.tt
348
+ - lib/lotus/generators/mailer/template.txt.tt
323
349
  - lib/lotus/generators/migration.rb
324
350
  - lib/lotus/generators/migration/migration.rb.tt
325
351
  - lib/lotus/generators/model.rb
@@ -337,6 +363,7 @@ files:
337
363
  - lib/lotus/generators/slice/views/application_layout.rb.tt
338
364
  - lib/lotus/loader.rb
339
365
  - lib/lotus/lotusrc.rb
366
+ - lib/lotus/mailer/glue.rb
340
367
  - lib/lotus/middleware.rb
341
368
  - lib/lotus/rendering_policy.rb
342
369
  - lib/lotus/root.rb
@@ -372,7 +399,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
372
399
  version: '0'
373
400
  requirements: []
374
401
  rubyforge_project:
375
- rubygems_version: 2.4.8
402
+ rubygems_version: 2.4.5.1
376
403
  signing_key:
377
404
  specification_version: 4
378
405
  summary: A complete web framework for Ruby