snails 0.8.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/Gemfile +1 -1
- data/example/app.rb +1 -3
- data/example/app2.rb +1 -3
- data/example/boot.rb +7 -0
- data/example/config.ru +0 -4
- data/lib/snails/app.rb +25 -3
- data/lib/snails/loader.rb +19 -3
- data/lib/snails/mailer.rb +1 -2
- data/lib/snails.rb +2 -1
- data/snails.gemspec +1 -1
- metadata +8 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5bd58d0b9693a06138e4c59111c6549648cedd24187bf8edaf751c2d9631824f
|
4
|
+
data.tar.gz: b80ef3591f34a1ac4e8e0180192e3721025a9223f82ce92832cd515dcc49a3a9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0e6497eed09aa83b446ff727d9590418a8a9963cb75cfa85db83671360c3526b49d0adc70817325b44147932578416adaa6faf8a03e4bb44c1d71373afb94adb
|
7
|
+
data.tar.gz: 7d77f6f64280dba88e152dc56f9c41569df7a75fbb95ca37d6a6be68670d0e6a117f4d3ac2efae5a662c7924271ab95e111a6068d046d748e0dffe93a0e4d628
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
source
|
1
|
+
source 'https://rubygems.org'
|
2
2
|
gemspec # specified in gemspec
|
data/example/app.rb
CHANGED
data/example/app2.rb
CHANGED
data/example/boot.rb
ADDED
data/example/config.ru
CHANGED
data/lib/snails/app.rb
CHANGED
@@ -98,6 +98,7 @@ module Snails
|
|
98
98
|
require 'sprockets-helpers'
|
99
99
|
|
100
100
|
cwd = Pathname.new(Dir.pwd)
|
101
|
+
|
101
102
|
app.set :sprockets, Sprockets::Environment.new(cwd)
|
102
103
|
app.set :digest_assets, false
|
103
104
|
app.set :assets_prefix, app.setting(:assets_prefix, '/assets') # URL
|
@@ -346,19 +347,29 @@ module Snails
|
|
346
347
|
|
347
348
|
def partial(name, opts = {})
|
348
349
|
partial_name = name.to_s["/"] ? name.to_s.reverse.sub("/", "_/").reverse : "_#{name}"
|
349
|
-
|
350
|
+
locals = opts.delete(:locals) || {}
|
351
|
+
erb(partial_name.to_sym, { layout: false }.merge(opts), locals)
|
350
352
|
end
|
351
353
|
|
354
|
+
# Possible render options are:
|
355
|
+
# :content_type The content type to use, same arguments as content_type.
|
356
|
+
# :layout If set to something falsy, no layout is rendered, otherwise the specified layout is used (Ignored for sass)
|
357
|
+
# :layout_engine Engine to use for rendering the layout. :locals A hash with local variables that should be available in the template
|
358
|
+
# :scope If set, template is evaluate with the binding of the given object rather than the application instance.
|
359
|
+
# :views Views directory to use.
|
360
|
+
|
352
361
|
def view(view_name, opts = {})
|
353
362
|
layout = request.xhr? ? false : true
|
354
363
|
erb(view_name.to_sym, { layout: layout }.merge(opts))
|
355
364
|
end
|
356
365
|
|
357
|
-
def show_date(
|
358
|
-
|
366
|
+
def show_date(time)
|
367
|
+
time = Time.parse(time) if time.is_a?(String) && !time.blank?
|
368
|
+
time ? time.strftime("%d de %b, %Y") : ''
|
359
369
|
end
|
360
370
|
|
361
371
|
def show_time(time)
|
372
|
+
time = Time.parse(time) if time.is_a?(String) && !time.blank?
|
362
373
|
time ? time.strftime("%d de %b, %Y a las %H:%M") : ''
|
363
374
|
end
|
364
375
|
|
@@ -394,6 +405,9 @@ module Snails
|
|
394
405
|
path: app.setting(:session_path, '/'),
|
395
406
|
domain: app.setting(:session_domain, nil),
|
396
407
|
expire_after: app.setting(:session_expire_after, 2592000), # one month in seconds
|
408
|
+
same_site: app.setting(:session_same_site, false),
|
409
|
+
http_only: app.setting(:session_http_only, nil),
|
410
|
+
secure: app.setting(:session_secure, false),
|
397
411
|
secret: app.session_secret # uses previous set :session_secret or generates one
|
398
412
|
}
|
399
413
|
|
@@ -417,6 +431,10 @@ module Snails
|
|
417
431
|
set :views, Snails.root.join('lib', 'views')
|
418
432
|
set :static_paths, %w(/css /img /js /files /fonts /favicon.ico)
|
419
433
|
|
434
|
+
if defined?(Snails.loader) && Snails.loader.loaded?
|
435
|
+
set :lock, true if Snails.env.development?
|
436
|
+
end
|
437
|
+
|
420
438
|
enable :method_override
|
421
439
|
enable :logging
|
422
440
|
|
@@ -455,6 +473,10 @@ module Snails
|
|
455
473
|
show_error(404)
|
456
474
|
end
|
457
475
|
|
476
|
+
after do
|
477
|
+
Snails.loader.reload! if settings.lock
|
478
|
+
end
|
479
|
+
|
458
480
|
protected
|
459
481
|
|
460
482
|
def deliver(data, code = 200, format = :json)
|
data/lib/snails/loader.rb
CHANGED
@@ -10,19 +10,28 @@ module Snails
|
|
10
10
|
class Loader
|
11
11
|
|
12
12
|
attr_reader :loader
|
13
|
-
attr_accessor :load_paths, :preload_paths, :ignore_paths, :no_eager_load_paths
|
13
|
+
attr_accessor :load_paths, :preload_paths, :postload_paths, :ignore_paths, :no_eager_load_paths
|
14
14
|
|
15
|
-
def initialize(loader: nil, load_paths: nil, preload_paths: nil)
|
15
|
+
def initialize(loader: nil, load_paths: nil, preload_paths: nil, postload_paths: nil)
|
16
16
|
@loader = loader || Zeitwerk::Loader.new
|
17
17
|
@load_paths = load_paths || DEFAULT_LOAD_PATHS
|
18
18
|
@preload_paths = preload_paths || DEFAULT_PRELOAD_PATHS
|
19
|
+
@postload_paths = postload_paths || []
|
19
20
|
@ignore_paths = []
|
20
21
|
@no_eager_load_paths = []
|
21
22
|
end
|
22
23
|
|
24
|
+
def loaded?
|
25
|
+
@loaded
|
26
|
+
end
|
27
|
+
|
23
28
|
def load!(opts = {})
|
24
29
|
# $LOAD_PATH.unshift(File.join(Snails.root, 'lib'))
|
25
30
|
|
31
|
+
preload_paths.each do |path|
|
32
|
+
Dir.glob(Snails.root.join(path, '*.rb')).each { |f| require f }
|
33
|
+
end
|
34
|
+
|
26
35
|
load_paths.each do |path|
|
27
36
|
loader.push_dir(Snails.root.join(path))
|
28
37
|
end
|
@@ -38,11 +47,18 @@ module Snails
|
|
38
47
|
loader.enable_reloading if opts[:enable_reload]
|
39
48
|
loader.setup
|
40
49
|
|
41
|
-
|
50
|
+
postload_paths.each do |path|
|
42
51
|
Dir.glob(Snails.root.join(path, '*.rb')).each { |f| require f }
|
43
52
|
end
|
44
53
|
|
45
54
|
loader.eager_load if opts[:eager_load]
|
55
|
+
|
56
|
+
@loaded = true
|
57
|
+
|
58
|
+
# enable reloading for already defined apps
|
59
|
+
Snails.apps.each do |app|
|
60
|
+
app.set :lock, true
|
61
|
+
end if Snails.env.dev?
|
46
62
|
end
|
47
63
|
|
48
64
|
def reload!
|
data/lib/snails/mailer.rb
CHANGED
@@ -2,6 +2,7 @@ require 'snails/util'
|
|
2
2
|
require 'erb'
|
3
3
|
require 'tilt/erb'
|
4
4
|
require 'snails'
|
5
|
+
require 'stringio'
|
5
6
|
|
6
7
|
module Snails
|
7
8
|
|
@@ -169,8 +170,6 @@ A <%= @exception.class %> occurred in <%= @url %>:
|
|
169
170
|
def initialize(config = {})
|
170
171
|
@debug = config[:debug]
|
171
172
|
|
172
|
-
puts "-- #{config.inspect}"
|
173
|
-
|
174
173
|
if key = config.dig(:dkim, :private_key) and File.exist?(key)
|
175
174
|
config[:dkim][:private_key] = IO.read(key)
|
176
175
|
elsif config[:dkim]
|
data/lib/snails.rb
CHANGED
@@ -7,6 +7,7 @@ module Snails
|
|
7
7
|
|
8
8
|
def initialize(str); @str = str.to_s.freeze; end
|
9
9
|
def to_s; @str; end
|
10
|
+
def to_sym; @str.to_sym; end
|
10
11
|
def <=>(str); @str <=> str.to_s; end
|
11
12
|
def inspect; @str.inspect; end
|
12
13
|
|
@@ -44,7 +45,7 @@ end
|
|
44
45
|
# sinatra/activerecord only 'reads' RACK_ENV, so make sure it is set
|
45
46
|
ENV['RACK_ENV'] ||= ENV['RAILS_ENV']
|
46
47
|
|
47
|
-
require 'snails/app' unless Snails.env.test?
|
48
|
+
# require 'snails/app' unless Snails.env.test?
|
48
49
|
unless ENV['SILENT']
|
49
50
|
ruby_version = "#{RUBY_VERSION}" # -p#{RUBY_PATCHLEVEL}
|
50
51
|
ruby_version += " +YJIT" if RUBY_DESCRIPTION['YJIT']
|
data/snails.gemspec
CHANGED
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.
|
4
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tomás Pollak
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-07-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -156,6 +156,7 @@ files:
|
|
156
156
|
- example/Rakefile
|
157
157
|
- example/app.rb
|
158
158
|
- example/app2.rb
|
159
|
+
- example/boot.rb
|
159
160
|
- example/config.ru
|
160
161
|
- lib/snails.rb
|
161
162
|
- lib/snails/app.rb
|
@@ -167,10 +168,10 @@ files:
|
|
167
168
|
- lib/snails/util.rb
|
168
169
|
- snails.gemspec
|
169
170
|
- spec/app_spec.rb
|
170
|
-
homepage:
|
171
|
+
homepage:
|
171
172
|
licenses: []
|
172
173
|
metadata: {}
|
173
|
-
post_install_message:
|
174
|
+
post_install_message:
|
174
175
|
rdoc_options: []
|
175
176
|
require_paths:
|
176
177
|
- lib
|
@@ -185,8 +186,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
185
186
|
- !ruby/object:Gem::Version
|
186
187
|
version: 1.3.6
|
187
188
|
requirements: []
|
188
|
-
rubygems_version: 3.
|
189
|
-
signing_key:
|
189
|
+
rubygems_version: 3.5.3
|
190
|
+
signing_key:
|
190
191
|
specification_version: 4
|
191
192
|
summary: Ruby on Snails.
|
192
193
|
test_files: []
|