snails 0.2.4 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: cfb299fdc1c0ea02bbbd6eb4826c0925a41202cb
4
- data.tar.gz: 80b38caff03a1d149eb41a2a07ee6ec99776ec82
2
+ SHA256:
3
+ metadata.gz: 0cafb0e86036bc65418240e5e0942ce1b2a89052f812db2269917c900e6a9652
4
+ data.tar.gz: 39bf3a5d05baba4bfc4828e222eb0ef0728a45dd6cc6bb159c15c76da2ee92e9
5
5
  SHA512:
6
- metadata.gz: f79f1bd48245a247f2d4844d028afcc69eaa29e2fa469ec401e5b6aa6f79059df39957c43cb5726eea261bba4b407012959ad895aee5483915da2b68eb427b11
7
- data.tar.gz: 7e84b3eb5948d177b2c2532cc7b7b2e0278ff0b6a467ea37369b0346fad488fa77954d08593d74ea15bfdd3126db7c70fd6fb90836560a34ba87682efc333423
6
+ metadata.gz: 32bb3cc41d55574f44af28370da22ef8e21954f3b3165874926b3dd0bcf3e864e14c8ed5f8d2e1221ff2e4de67d0255d9bc5ff624b8952b0e9f32bc277ce8068
7
+ data.tar.gz: '09824f4141ec972a719a8cfa95b68fbc9e34f09f05155cb5b9865b66ee90b512df1436e53ec5b12479eab27a538bbb5f8cf48e3055dea2d4dc446f080ae7d845'
data/example/Rakefile CHANGED
@@ -1,22 +1,2 @@
1
- require 'bundler/setup'
2
- require 'snails'
3
- require 'snails/notifier'
4
-
5
- class MyApp < Snails::App
6
- # register Snails::Assets
7
- # register Snails::Database
8
- end
9
-
10
- Notifier = Snails::Mailer.new({
11
- from: 'User <test@myapp.com>',
12
- smtp: {
13
- helo_domain: 'myapp.com'
14
- }
15
- })
16
-
17
- Notifier.email(:new_message) do |message|
18
- text = "You have a new message from: #{message.from.email}"
19
- send_email(to: message.to.email, subject: "New message!", body: text)
20
- end
21
-
1
+ require './app'
22
2
  require 'snails/tasks'
data/example/app.rb ADDED
@@ -0,0 +1,27 @@
1
+ require 'bundler/setup'
2
+ require 'snails'
3
+ require 'snails/mailer'
4
+
5
+ class MyApp < Snails::App
6
+ set :session_secret, 'foobar'
7
+
8
+ register Snails::Assets
9
+ register Snails::Sessions
10
+ # register Snails::Database
11
+
12
+ get '/' do
13
+ 'Hello world!'
14
+ end
15
+ end
16
+
17
+ Notifier = Snails::Mailer.new({
18
+ from: 'User <test@myapp.com>',
19
+ smtp: {
20
+ helo_domain: 'myapp.com'
21
+ }
22
+ })
23
+
24
+ Notifier.email(:new_message) do |message|
25
+ text = "You have a new message from: #{message.from.email}"
26
+ send_email(to: message.to.email, subject: "New message!", body: text)
27
+ end
data/example/config.ru CHANGED
@@ -1,12 +1,2 @@
1
- require 'bundler/setup'
2
- require 'snails'
3
-
4
- class MyApp < Snails::App
5
- set :session_secret, 'foobar'
6
-
7
- get '/' do
8
- 'Hello world!'
9
- end
10
- end
11
-
1
+ require './app'
12
2
  run MyApp
data/lib/snails/app.rb CHANGED
@@ -12,10 +12,17 @@ module Snails
12
12
 
13
13
  module All
14
14
 
15
+ # usage:
16
+ #
17
+ # class App < Snails::App
18
+ # register Snails::All
19
+ # end
20
+
15
21
  def self.registered(app)
16
22
  app.register Snails::Database
17
23
  app.register Snails::Locales
18
24
  app.register Snails::Assets
25
+ app.register Snails::Sessions
19
26
  end
20
27
 
21
28
  end
@@ -50,7 +57,7 @@ module Snails
50
57
 
51
58
  cwd = Pathname.new(Dir.pwd)
52
59
  app.set :locale, :es
53
- app.set :locales_path, app.respond_to?(:locales_path) ? app.locales_path : cwd.join('config', 'locales')
60
+ app.set :locales_path, app.setting(:locales_path, cwd.join('config', 'locales'))
54
61
 
55
62
  app.helpers do
56
63
  def t(key); I18n.t(key); end
@@ -93,8 +100,8 @@ module Snails
93
100
  cwd = Pathname.new(Dir.pwd)
94
101
  app.set :sprockets, Sprockets::Environment.new(cwd)
95
102
  app.set :digest_assets, false
96
- app.set :assets_prefix, app.respond_to?(:assets_prefix) ? app.assets_prefix : '/assets' # URL
97
- app.set :assets_paths, app.respond_to?(:assets_paths) ? app.assets_paths : %w(assets) # source files
103
+ app.set :assets_prefix, app.setting(:assets_prefix, '/assets') # URL
104
+ app.set :assets_paths, app.setting(:assets_paths, %w(assets)) # source files
98
105
  app.set :assets_public_path, -> { cwd.join('public', 'assets') } # output dir
99
106
  app.set :assets_precompile, %w(js/main.js css/main.css)
100
107
  app.set :assets_remove_digests, false
@@ -150,7 +157,7 @@ module Snails
150
157
  module Tasks
151
158
 
152
159
  def self.precompile_for(app)
153
- unless app.respond_to?(:assets_public_path)
160
+ unless app.respond_tobno?(:assets_public_path)
154
161
  return puts "#{app.name} doesn't have the Asset module included."
155
162
  end
156
163
 
@@ -371,6 +378,21 @@ module Snails
371
378
 
372
379
  end
373
380
 
381
+ module Sessions
382
+
383
+ def self.registered(app)
384
+ app.set :sessions, {
385
+ key: app.setting(:session_key, 'snails.session'),
386
+ path: app.setting(:session_path, '/'),
387
+ expire_after: app.setting(:session_expire_after, 2592000), # one month in seconds
388
+ secret: app.session_secret # uses previous set :session_secret or generates one
389
+ }
390
+
391
+ app.register Sinatra::Flash
392
+ end
393
+
394
+ end
395
+
374
396
  class App < Sinatra::Base
375
397
 
376
398
  def self.inherited(base)
@@ -378,18 +400,19 @@ module Snails
378
400
  super
379
401
  end
380
402
 
403
+ def self.setting(key, default)
404
+ respond_to?(key) ? public_send(key) : default.respond_to?(:call) ? default.call : default
405
+ end
406
+
381
407
  set :protection, except: :frame_options
382
- set :views, Snails.root.join('lib', 'views')
383
- set :session_secret, ENV.fetch('SESSION_SECRET') { SecureRandom.hex }
408
+ set :views, setting(:views, Snails.root.join('lib', 'views'))
384
409
  set :static_paths, %w(/css /img /js /files /fonts favicon.ico)
385
410
 
386
- enable :sessions
387
411
  enable :method_override
388
412
  enable :logging
389
413
 
390
- register Sinatra::Flash
391
414
  use Rack::CommonLogger, Snails.logger
392
- use Rack::Static, urls: static_paths, root: 'public'
415
+ use Rack::Static, urls: static_paths, root: 'public' unless Snails.env.production?
393
416
 
394
417
  configure :production, :staging do
395
418
  set :raise_errors, true
@@ -398,6 +421,7 @@ module Snails
398
421
 
399
422
  configure :development do
400
423
  set :raise_errors, true
424
+ set :dump_errors, false
401
425
  set :show_exceptions, true
402
426
  set :log_level, Logger::DEBUG
403
427
  end
@@ -413,7 +437,8 @@ module Snails
413
437
  err = request.env['sinatra.error']
414
438
  logger.error err.message
415
439
  logger.error err.backtrace.first(3).join("\n")
416
- halt(500, err.message)
440
+ # halt(500, err.message)
441
+ show_error(500)
417
442
  end
418
443
 
419
444
  not_found do
data/lib/snails.rb CHANGED
@@ -3,8 +3,11 @@ require 'pathname'
3
3
 
4
4
  module Snails
5
5
  class Environment
6
+ include Comparable
7
+
6
8
  def initialize(str); @str = str.to_s.freeze; end
7
9
  def to_s; @str; end
10
+ def <=>(str); @str <=> str.to_s; end
8
11
  def inspect; @str.inspect; end
9
12
 
10
13
  %w(production staging development test).each do |key|
data/snails.gemspec CHANGED
@@ -3,7 +3,7 @@
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "snails"
6
- s.version = '0.2.4'
6
+ s.version = '0.2.5'
7
7
  s.platform = Gem::Platform::RUBY
8
8
  s.authors = ['Tomás Pollak']
9
9
  s.email = ['tomas@forkhq.com']
data/spec/app_spec.rb ADDED
@@ -0,0 +1,16 @@
1
+ require './lib/snails'
2
+
3
+ require 'rspec/mocks'
4
+ require 'rspec/expectations'
5
+
6
+ describe 'App' do
7
+
8
+ let(:subject) {
9
+ Snails::App.new
10
+ }
11
+
12
+ it 'works' do
13
+ expect(subject.class).to eq(Sinatra::Wrapper)
14
+ end
15
+
16
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: snails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomás Pollak
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-01-24 00:00:00.000000000 Z
11
+ date: 2019-01-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -154,6 +154,7 @@ files:
154
154
  - Rakefile
155
155
  - example/Gemfile
156
156
  - example/Rakefile
157
+ - example/app.rb
157
158
  - example/config.ru
158
159
  - lib/snails.rb
159
160
  - lib/snails/app.rb
@@ -162,6 +163,7 @@ files:
162
163
  - lib/snails/tasks.rb
163
164
  - lib/snails/util.rb
164
165
  - snails.gemspec
166
+ - spec/app_spec.rb
165
167
  homepage:
166
168
  licenses: []
167
169
  metadata: {}
@@ -181,7 +183,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
181
183
  version: 1.3.6
182
184
  requirements: []
183
185
  rubyforge_project:
184
- rubygems_version: 2.6.13
186
+ rubygems_version: 2.7.3
185
187
  signing_key:
186
188
  specification_version: 4
187
189
  summary: Ruby on Snails.