aerogel-core 1.1.1 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/aerogel-core.gemspec +2 -2
- data/app/helpers/assets.rb +11 -15
- data/app/helpers/config.rb +5 -9
- data/app/helpers/core.rb +10 -14
- data/app/helpers/csrf.rb +12 -16
- data/app/helpers/output_buffer.rb +19 -23
- data/app/helpers/render.rb +4 -4
- data/app/helpers/tags.rb +26 -25
- data/app/routes/core.rb +9 -13
- data/app/routes/static.rb +0 -4
- data/lib/aerogel/core/application.rb +17 -15
- data/lib/aerogel/core/config.rb +55 -23
- data/lib/aerogel/core/core.rb +18 -0
- data/lib/aerogel/core/db.rb +34 -5
- data/lib/aerogel/core/db/model.rb +34 -0
- data/lib/aerogel/core/errors.rb +11 -0
- data/lib/aerogel/core/helpers.rb +21 -2
- data/lib/aerogel/core/reloader.rb +72 -0
- data/lib/aerogel/core/render.rb +1 -0
- data/lib/aerogel/core/render/scope.rb +26 -0
- data/lib/aerogel/core/routes.rb +48 -1
- data/lib/aerogel/core/routes/namespace.rb +37 -0
- data/lib/aerogel/core/routes/sinatra_ex.rb +11 -0
- data/lib/aerogel/core/version.rb +1 -1
- metadata +39 -34
- data/db/model/model.rb.template +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b0b6c95d4a960593785baf5d48ffdf798bcaf5da
|
4
|
+
data.tar.gz: 2c964b75f82fb8b0c141c93ca81ee3c9909a270f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d544fb26f5f875bd4a27bffb261cadbd8638141d98188d47e15bd4ce3aaea77bc96eb2ca660087f9a71e266d425a2c13664c2d6361b7a833dfb177efab7d0de3
|
7
|
+
data.tar.gz: 9dd900eb31268b5f3a523f1cb5326b6631dd2dd1aacc597404920cc172b9338e53dca948f867184f1ec975a1737a3a1e3986fa3974762a93a7cf865f65033c6b
|
data/aerogel-core.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ["alex@kukushk.in"]
|
11
11
|
spec.description = %q{Aerogel core module}
|
12
12
|
spec.summary = %q{Aerogel is a modular opinionated CMS}
|
13
|
-
spec.homepage = ""
|
13
|
+
spec.homepage = "https://github.com/kukushkin/aerogel-core"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
16
|
spec.files = `git ls-files`.split($/)
|
@@ -26,7 +26,7 @@ Gem::Specification.new do |spec|
|
|
26
26
|
spec.add_dependency 'coffee-script'
|
27
27
|
spec.add_dependency 'uglifier'
|
28
28
|
spec.add_dependency 'yui-compressor'
|
29
|
-
spec.add_dependency 'aerogel-configurator'
|
29
|
+
spec.add_dependency 'aerogel-configurator', "~> 1.3"
|
30
30
|
spec.add_dependency 'mongoid'
|
31
31
|
|
32
32
|
spec.add_development_dependency "bundler", "~> 1.3"
|
data/app/helpers/assets.rb
CHANGED
@@ -1,15 +1,11 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
(javascript_tag filename.to_s)
|
13
|
-
end
|
14
|
-
|
15
|
-
end # module Aerogel::Helpers
|
1
|
+
# Include styles and javascript tags for assets grouped by scope.
|
2
|
+
#
|
3
|
+
# Intended use is either:
|
4
|
+
# <%= assets %> # for application assets
|
5
|
+
# or:
|
6
|
+
# <% assets 'controller/name' %> # for controller specific assets
|
7
|
+
#
|
8
|
+
def assets( filename = :application )
|
9
|
+
(stylesheet_tag filename.to_s) +
|
10
|
+
(javascript_tag filename.to_s)
|
11
|
+
end
|
data/app/helpers/config.rb
CHANGED
data/app/helpers/core.rb
CHANGED
@@ -1,15 +1,11 @@
|
|
1
|
-
|
1
|
+
def find_template(views, name, engine, &block)
|
2
|
+
Array(views).each { |v| super(v, name, engine, &block) }
|
3
|
+
end
|
2
4
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
else
|
11
|
-
env['rack.logger.'+name.to_s] or raise("Logger with name '#{name}' is not registered")
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
end # module Aerogel::Helpers
|
5
|
+
def logger( name = nil )
|
6
|
+
if name.nil?
|
7
|
+
env['rack.logger']
|
8
|
+
else
|
9
|
+
env['rack.logger.'+name.to_s] or raise("Logger with name '#{name}' is not registered")
|
10
|
+
end
|
11
|
+
end
|
data/app/helpers/csrf.rb
CHANGED
@@ -1,19 +1,15 @@
|
|
1
|
-
|
1
|
+
def csrf_field_name
|
2
|
+
'authenticity_token'
|
3
|
+
end
|
2
4
|
|
3
|
-
|
4
|
-
|
5
|
-
|
5
|
+
def csrf_token
|
6
|
+
session[:csrf] ||= SecureRandom.hex(32) if defined?(session)
|
7
|
+
end
|
6
8
|
|
7
|
-
|
8
|
-
|
9
|
-
|
9
|
+
def csrf_token_field
|
10
|
+
tag :input, type: 'hidden', name: csrf_field_name, value: csrf_token
|
11
|
+
end
|
10
12
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
def csrf_protected?
|
16
|
-
true
|
17
|
-
end
|
18
|
-
|
19
|
-
end # module Aerogel::Helpers
|
13
|
+
def csrf_protected?
|
14
|
+
true
|
15
|
+
end
|
@@ -1,26 +1,22 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
else # theres no template to concat, return the text directly
|
9
|
-
text
|
10
|
-
end
|
1
|
+
def output_concat( text )
|
2
|
+
if self.respond_to?(:is_haml?) && is_haml?
|
3
|
+
haml_concat(text)
|
4
|
+
elsif !Aerogel::Render::OutputBuffer.buffer.nil? # has_erb_buffer?
|
5
|
+
Aerogel::Render::OutputBuffer.buffer.concat text
|
6
|
+
else # theres no template to concat, return the text directly
|
7
|
+
text
|
11
8
|
end
|
9
|
+
end
|
12
10
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
end
|
11
|
+
def output_capture( inner_block = nil, &block )
|
12
|
+
inner_block = block if inner_block.nil?
|
13
|
+
if self.respond_to?(:is_haml?) && is_haml? && (block_is_haml?(inner_block) rescue false)
|
14
|
+
# haml
|
15
|
+
capture_haml(nil, &block)
|
16
|
+
elsif Aerogel::Render::OutputBuffer.block_is_erb? block
|
17
|
+
# erb
|
18
|
+
Aerogel::Render::OutputBuffer.capture( &block )
|
19
|
+
else
|
20
|
+
block.call
|
24
21
|
end
|
25
|
-
|
26
|
-
end # module Aerogel::Helpers
|
22
|
+
end
|
data/app/helpers/render.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
module Aerogel::Helpers
|
1
|
+
# module Aerogel::Helpers
|
2
2
|
|
3
3
|
# Escapes html string.
|
4
4
|
#
|
@@ -8,8 +8,8 @@ module Aerogel::Helpers
|
|
8
8
|
|
9
9
|
# Renders erb template.
|
10
10
|
#
|
11
|
-
def view( name )
|
12
|
-
erb "#{name}.html".to_sym
|
11
|
+
def view( name, *args )
|
12
|
+
erb( "#{name}.html".to_sym, *args )
|
13
13
|
end
|
14
14
|
|
15
15
|
# Renders partial erb template.
|
@@ -21,4 +21,4 @@ module Aerogel::Helpers
|
|
21
21
|
erb name_parts.join('/').to_sym, opts
|
22
22
|
end
|
23
23
|
|
24
|
-
end # module Aerogel::Helpers
|
24
|
+
# end # module Aerogel::Helpers
|
data/app/helpers/tags.rb
CHANGED
@@ -1,28 +1,29 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
end
|
11
|
-
attrs = args.shift || {}
|
1
|
+
# Creates tag.
|
2
|
+
#
|
3
|
+
def tag( name, *args, &block )
|
4
|
+
if block_given?
|
5
|
+
content = output_capture(&block)
|
6
|
+
elsif args.first.is_a? String
|
7
|
+
content = args.shift
|
8
|
+
end
|
9
|
+
attrs = args.shift || {}
|
12
10
|
# t_attrs = attrs.map{|k,v| v.nil? ? " #{k}" : " #{k}=\"#{h(v)}\""}
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
end
|
19
|
-
if Aerogel::Render::OutputBuffer.block_is_template?(block)
|
20
|
-
output_concat(output)
|
21
|
-
return nil
|
22
|
-
else
|
23
|
-
return output
|
24
|
-
end
|
11
|
+
t_attrs = attrs.map{|k,v| v.nil? ? " #{k}" : " #{k}=\"#{(v)}\""}
|
12
|
+
if content
|
13
|
+
output = "<#{name}#{t_attrs.join}>"+content+"</#{name}>"
|
14
|
+
else
|
15
|
+
output = "<#{name}#{t_attrs.join}/>"
|
25
16
|
end
|
17
|
+
if Aerogel::Render::OutputBuffer.block_is_template?(block)
|
18
|
+
output_concat(output)
|
19
|
+
return nil
|
20
|
+
else
|
21
|
+
return output
|
22
|
+
end
|
23
|
+
end
|
26
24
|
|
27
|
-
|
28
|
-
|
25
|
+
# Creates <a href=''..>...</a> tag.
|
26
|
+
#
|
27
|
+
def link_to( url, text = url, opts = {} )
|
28
|
+
tag :a, text, opts.merge( href: url )
|
29
|
+
end
|
data/app/routes/core.rb
CHANGED
@@ -1,15 +1,11 @@
|
|
1
|
-
|
1
|
+
get "/" do
|
2
|
+
view :index
|
3
|
+
end
|
2
4
|
|
3
|
-
|
4
|
-
|
5
|
-
|
5
|
+
get "/:action" do
|
6
|
+
view params['action'] # rescue raise Sinatra::NotFound.new
|
7
|
+
end
|
6
8
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
not_found do
|
12
|
-
erb :"errors/404.html", layout: false
|
13
|
-
end
|
14
|
-
|
15
|
-
end
|
9
|
+
not_found do
|
10
|
+
erb :"errors/404.html", layout: false
|
11
|
+
end
|
data/app/routes/static.rb
CHANGED
@@ -1,36 +1,38 @@
|
|
1
1
|
require 'sinatra/base'
|
2
2
|
|
3
|
+
require 'aerogel/core/reloader'
|
3
4
|
require 'aerogel/core/config'
|
4
5
|
require 'aerogel/core/helpers'
|
5
6
|
require 'aerogel/core/routes'
|
6
7
|
require 'aerogel/core/assets'
|
7
8
|
require 'aerogel/core/db'
|
8
9
|
require 'aerogel/core/render'
|
10
|
+
require 'aerogel/core/errors'
|
9
11
|
|
10
12
|
class Aerogel::Application < Sinatra::Base
|
11
13
|
|
12
14
|
# Loads and configures application modules
|
13
15
|
#
|
14
16
|
def self.load
|
15
|
-
|
17
|
+
Aerogel.on_load_callbacks.each do |callback|
|
18
|
+
callback.call self
|
19
|
+
end
|
20
|
+
puts "** Aerogel application configured v#{Aerogel::version}-#{environment}"
|
16
21
|
self
|
17
22
|
end
|
18
23
|
|
19
|
-
|
24
|
+
end # class Aerogel::Application
|
20
25
|
|
26
|
+
Aerogel.on_load do |app|
|
21
27
|
# Loads application environment
|
22
28
|
#
|
23
|
-
|
24
|
-
|
25
|
-
Aerogel.register_path( Aerogel.application_path )
|
26
|
-
|
27
|
-
register Aerogel::Helpers
|
28
|
-
register Aerogel::Config
|
29
|
-
register Aerogel::Routes
|
30
|
-
register Aerogel::Assets
|
31
|
-
register Aerogel::Db
|
32
|
-
register Aerogel::Render
|
33
|
-
puts "** Aerogel application configured v#{Aerogel::version}-#{environment}"
|
34
|
-
end
|
29
|
+
# application path is registered last
|
30
|
+
Aerogel.register_path( Aerogel.application_path )
|
35
31
|
|
36
|
-
|
32
|
+
app.register Aerogel::Config
|
33
|
+
app.register Aerogel::Helpers
|
34
|
+
app.register Aerogel::Routes
|
35
|
+
app.register Aerogel::Assets
|
36
|
+
app.register Aerogel::Db
|
37
|
+
app.register Aerogel::Render
|
38
|
+
end
|
data/lib/aerogel/core/config.rb
CHANGED
@@ -1,34 +1,66 @@
|
|
1
1
|
require 'aerogel/configurator'
|
2
2
|
require 'rack-flash'
|
3
|
+
require 'sinatra/multi_route'
|
3
4
|
|
4
|
-
module Aerogel
|
5
|
+
module Aerogel
|
5
6
|
|
6
|
-
#
|
7
|
+
# Returns Aerogel application's config object.
|
7
8
|
#
|
8
|
-
def self.
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
9
|
+
def self.config
|
10
|
+
@config ||= Configurator.new
|
11
|
+
end
|
12
|
+
|
13
|
+
module Config
|
14
|
+
# Configures application.
|
15
|
+
#
|
16
|
+
def self.registered(app)
|
17
|
+
app.set :root, Aerogel.application_path
|
18
|
+
app.set :views, Aerogel.get_resource_paths( :views ).reverse
|
19
|
+
app.set :erb, trim: '-', layout: "layouts/application.html".to_sym
|
20
|
+
|
21
|
+
reset!(app)
|
22
|
+
# Load configs
|
23
|
+
Aerogel.get_resource_list( :config, '*.conf', app.environment ).each do |config_filename|
|
24
|
+
Aerogel.config.load config_filename
|
25
|
+
end
|
26
|
+
# register reloader
|
27
|
+
setup_reloader(app) if Aerogel.config.aerogel.reloader?
|
28
|
+
|
29
|
+
# set :protection, true
|
30
|
+
# set :protect_from_csrf, true
|
31
|
+
app.set :sessions, true
|
32
|
+
# TODO: demand to configure session secret on application level
|
33
|
+
# set :session_secret, '$aer0G31'
|
34
|
+
app.use Rack::Protection::AuthenticityToken
|
35
|
+
app.use Rack::Flash, :sweep => true
|
36
|
+
|
37
|
+
app.register Sinatra::MultiRoute
|
16
38
|
end
|
17
39
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
40
|
+
private
|
41
|
+
|
42
|
+
# Resets loaded config files.
|
43
|
+
#
|
44
|
+
def self.reset!(app)
|
45
|
+
Aerogel.config.clear!
|
46
|
+
Aerogel.config.aerogel.reloader = app.development?
|
47
|
+
end
|
48
|
+
|
49
|
+
# Sets up reloader for config files.
|
50
|
+
#
|
51
|
+
def self.setup_reloader(app)
|
52
|
+
app.use Aerogel::Reloader, ->{
|
53
|
+
Aerogel.get_resource_list( :config, '*.conf', app.environment )
|
54
|
+
} do |files|
|
55
|
+
# reset routes
|
56
|
+
reset!(app)
|
57
|
+
files.each do |filename|
|
58
|
+
Aerogel.config.load filename
|
59
|
+
end
|
60
|
+
end
|
22
61
|
end
|
23
62
|
|
24
|
-
|
25
|
-
# set :protect_from_csrf, true
|
26
|
-
app.set :sessions, true
|
27
|
-
# TODO: demand to configure session secret on application level
|
28
|
-
# set :session_secret, '$aer0G31'
|
29
|
-
app.use Rack::Protection::AuthenticityToken
|
30
|
-
app.use Rack::Flash
|
63
|
+
end # module Config
|
31
64
|
|
32
|
-
|
33
|
-
end # module Aerogel::Config
|
65
|
+
end # module Aerogel
|
34
66
|
|
data/lib/aerogel/core/core.rb
CHANGED
@@ -93,5 +93,23 @@ module Aerogel
|
|
93
93
|
true
|
94
94
|
end
|
95
95
|
|
96
|
+
# Requires file, loads into context of a module/class.
|
97
|
+
#
|
98
|
+
def self.require_into( mod_class, filename )
|
99
|
+
mod_class.class_eval File.read(filename), filename
|
100
|
+
end
|
101
|
+
|
102
|
+
# Returns registered on-load callbacks.
|
103
|
+
#
|
104
|
+
def self.on_load_callbacks
|
105
|
+
@on_load_callbacks || []
|
106
|
+
end
|
107
|
+
|
108
|
+
# Registers on-load callback.
|
109
|
+
#
|
110
|
+
def self.on_load( &block )
|
111
|
+
@on_load_callbacks ||= []
|
112
|
+
@on_load_callbacks << block
|
113
|
+
end
|
96
114
|
|
97
115
|
end # module Aerogel
|
data/lib/aerogel/core/db.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'mongoid'
|
2
2
|
require 'aerogel/configurator'
|
3
|
+
require 'aerogel/core/db/model'
|
3
4
|
|
4
5
|
module Aerogel::Db
|
5
6
|
|
@@ -12,14 +13,20 @@ module Aerogel::Db
|
|
12
13
|
#
|
13
14
|
def self.registered( app )
|
14
15
|
self.environment = app.environment
|
15
|
-
raise "Database connection is not configured in your application's config/*" if
|
16
|
+
raise "Database connection is not configured in your application's config/*" if Aerogel.config.db.nil?
|
16
17
|
Mongoid.configure do |config|
|
17
18
|
config.sessions = {
|
18
|
-
default: { hosts:
|
19
|
+
default: { hosts: Aerogel.config.db.hosts, database: Aerogel.config.db.name }
|
20
|
+
}
|
21
|
+
config.options = {
|
22
|
+
raise_not_found_error: false
|
19
23
|
}
|
20
24
|
end
|
21
25
|
load_models
|
22
26
|
|
27
|
+
# register reloader
|
28
|
+
setup_reloader(app) if Aerogel.config.aerogel.reloader
|
29
|
+
|
23
30
|
# disable [deprecated] warning in Mongoid method calls
|
24
31
|
I18n.enforce_available_locales = false if defined? I18n
|
25
32
|
end
|
@@ -48,14 +55,36 @@ private
|
|
48
55
|
# Loads all models from the folder db/model/*
|
49
56
|
#
|
50
57
|
def self.load_models
|
51
|
-
|
52
|
-
Aerogel.get_resource_list( 'db/model', '*.rb'
|
53
|
-
|
58
|
+
reset!
|
59
|
+
Aerogel.get_resource_list( 'db/model', '*.rb' ).each do |model_filename|
|
60
|
+
load model_filename
|
54
61
|
class_name = File.basename( model_filename, '.rb' ).camelize
|
55
62
|
self.models << eval(class_name)
|
56
63
|
end
|
57
64
|
end
|
58
65
|
|
66
|
+
# Resets models.
|
67
|
+
#
|
68
|
+
def self.reset!(app = nil)
|
69
|
+
self.models ||= []
|
70
|
+
# reset model classes
|
71
|
+
self.models.each do |model|
|
72
|
+
Object.send(:remove_const, model.name.to_sym)
|
73
|
+
end
|
74
|
+
self.models = []
|
75
|
+
end
|
76
|
+
|
77
|
+
#
|
78
|
+
# Configures reloader for models.
|
79
|
+
#
|
80
|
+
def self.setup_reloader(app)
|
81
|
+
app.use Aerogel::Reloader, ->{ Aerogel.get_resource_list( "db/model", "*.rb" ) } do
|
82
|
+
reset!(app)
|
83
|
+
load_models
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
|
59
88
|
# Create database indexes for all models
|
60
89
|
#
|
61
90
|
def self.create_indexes!
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# Mixin module for all model classes.
|
2
|
+
#
|
3
|
+
module Model
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
include Mongoid::Document
|
8
|
+
|
9
|
+
# Finds document by id.
|
10
|
+
# Raises error if document is not found.
|
11
|
+
#
|
12
|
+
def self.find!( *args )
|
13
|
+
raise_not_found_error_was = Mongoid.raise_not_found_error
|
14
|
+
begin
|
15
|
+
Mongoid.raise_not_found_error = true
|
16
|
+
self.find *args
|
17
|
+
ensure
|
18
|
+
Mongoid.raise_not_found_error = raise_not_found_error_was
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
module NonPersistent
|
25
|
+
extend ActiveSupport::Concern
|
26
|
+
included do
|
27
|
+
include Mongoid::Document
|
28
|
+
before_save do
|
29
|
+
raise "Attempt to save non-persistent model"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end # module NonPersistent
|
33
|
+
|
34
|
+
end # module Model
|
data/lib/aerogel/core/helpers.rb
CHANGED
@@ -1,10 +1,29 @@
|
|
1
|
-
|
1
|
+
# Aerogel::Helpers are registered both as Sinatra extensions and Sinatra helpers,
|
2
|
+
# so any helper is available both at application and request scope level.
|
3
|
+
#
|
2
4
|
module Aerogel::Helpers
|
3
5
|
|
4
6
|
def self.registered(app)
|
5
7
|
# load helpers
|
6
|
-
Aerogel.
|
8
|
+
Aerogel.get_resource_list( :app, "helpers/**/*.rb" ).each do |filename|
|
9
|
+
Aerogel.require_into( Aerogel::Helpers, filename )
|
10
|
+
end
|
7
11
|
app.helpers Aerogel::Helpers
|
12
|
+
|
13
|
+
# register reloader
|
14
|
+
setup_reloader(app) if Aerogel.config.aerogel.reloader?
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
# Sets up reloader for helpers.
|
20
|
+
#
|
21
|
+
def self.setup_reloader(app)
|
22
|
+
app.use Aerogel::Reloader, ->{ Aerogel.get_resource_list( :app, "helpers/**/*.rb" ) } do |files|
|
23
|
+
files.each do |filename|
|
24
|
+
Aerogel.require_into( Aerogel::Helpers, filename )
|
25
|
+
end
|
26
|
+
end
|
8
27
|
end
|
9
28
|
|
10
29
|
end # module Aerogel::Helpers
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# Middleware which checks and reloads modified files.
|
2
|
+
#
|
3
|
+
module Aerogel
|
4
|
+
class Reloader
|
5
|
+
# Use as middleware:
|
6
|
+
#
|
7
|
+
# # single file
|
8
|
+
# use Aerogel::Reloader, "file1.rb" { load 'file1.rb' }
|
9
|
+
#
|
10
|
+
# # list of files
|
11
|
+
# use Aerogel::Reloader, ["file1.rb", "file2.rb"] do |files|
|
12
|
+
# files.each{|f| load f }
|
13
|
+
# end
|
14
|
+
#
|
15
|
+
# # dynamic list of files
|
16
|
+
# use Aerogel::Reloader, ->(){ Dir.glob["*.rb"] } do |files|
|
17
|
+
# files.each{|f| load f}
|
18
|
+
# end
|
19
|
+
#
|
20
|
+
def initialize( app, files, &blk )
|
21
|
+
@app = app
|
22
|
+
@files = files
|
23
|
+
@action = blk
|
24
|
+
@file_list = file_list( @files )
|
25
|
+
@signature = signature( @file_list )
|
26
|
+
end
|
27
|
+
|
28
|
+
def call( env )
|
29
|
+
check!
|
30
|
+
@app.call( env )
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
# Checks if files are changed and reloads if so.
|
36
|
+
#
|
37
|
+
def check!
|
38
|
+
@file_list = file_list( @files )
|
39
|
+
new_signature = signature( @file_list )
|
40
|
+
if @signature != new_signature
|
41
|
+
# reload file list
|
42
|
+
puts "* Aerogel::Reloader reloading: #{@file_list}"
|
43
|
+
@action.call @file_list
|
44
|
+
@signature = new_signature
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# Re-calculates file list
|
49
|
+
#
|
50
|
+
def file_list( files )
|
51
|
+
case files
|
52
|
+
when String
|
53
|
+
[files]
|
54
|
+
when Array
|
55
|
+
files
|
56
|
+
when Proc
|
57
|
+
files.call # result should respond to #each
|
58
|
+
else
|
59
|
+
[]
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def signature( file_list )
|
64
|
+
sig = []
|
65
|
+
file_list.each do |filename|
|
66
|
+
sig << File.mtime(filename).to_i
|
67
|
+
end
|
68
|
+
sig.sort
|
69
|
+
end
|
70
|
+
|
71
|
+
end # class Reloader
|
72
|
+
end # module Aerogel
|
data/lib/aerogel/core/render.rb
CHANGED
@@ -0,0 +1,26 @@
|
|
1
|
+
module Aerogel::Render
|
2
|
+
|
3
|
+
# A render scope is to be incluced in other module or class.
|
4
|
+
# Provides access to render methods and helpers.
|
5
|
+
#
|
6
|
+
module Scope
|
7
|
+
|
8
|
+
|
9
|
+
def self.included(mod)
|
10
|
+
mod.instance_eval do
|
11
|
+
include Sinatra::Templates
|
12
|
+
include Aerogel::Helpers
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def template_cache
|
17
|
+
@template_cache ||= Tilt::Cache.new
|
18
|
+
end
|
19
|
+
|
20
|
+
def settings
|
21
|
+
Aerogel::Application
|
22
|
+
end
|
23
|
+
|
24
|
+
end # module Scope
|
25
|
+
|
26
|
+
end # module Aerogel::Render
|
data/lib/aerogel/core/routes.rb
CHANGED
@@ -1,7 +1,54 @@
|
|
1
|
+
require 'aerogel/core/routes/namespace'
|
2
|
+
require 'aerogel/core/routes/sinatra_ex'
|
3
|
+
|
1
4
|
module Aerogel::Routes
|
5
|
+
|
2
6
|
def self.registered(app)
|
7
|
+
reset!(app)
|
3
8
|
# load routes
|
4
|
-
Aerogel
|
9
|
+
Aerogel.get_resource_list( :app, "routes/**/*.rb" ).reverse.each do |filename|
|
10
|
+
Aerogel.require_into( Aerogel::Application, filename )
|
11
|
+
end
|
12
|
+
|
13
|
+
# register reloader
|
14
|
+
setup_reloader(app) if Aerogel.config.aerogel.reloader?
|
15
|
+
end
|
16
|
+
|
5
17
|
|
18
|
+
# Starts a new route namespace:
|
19
|
+
#
|
20
|
+
# get '/bar' do
|
21
|
+
# # matches '/bar' route
|
22
|
+
# end
|
23
|
+
#
|
24
|
+
# namespace '/foo' do
|
25
|
+
# get '/bar' do
|
26
|
+
# # matches '/foo/bar' route
|
27
|
+
# end
|
28
|
+
# end
|
29
|
+
#
|
30
|
+
def namespace( path, *args, &block )
|
31
|
+
Namespace.new self, path, &block
|
6
32
|
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
# Resets items defined in app/routes/*.
|
37
|
+
#
|
38
|
+
def self.reset!(app)
|
39
|
+
app.reset_routes!
|
40
|
+
end
|
41
|
+
|
42
|
+
# Sets up reloader for routes.
|
43
|
+
#
|
44
|
+
def self.setup_reloader(app)
|
45
|
+
app.use Aerogel::Reloader, ->{ Aerogel.get_resource_list( :app, "routes/**/*.rb" ) } do |files|
|
46
|
+
# reset routes
|
47
|
+
reset!(app)
|
48
|
+
files.reverse.each do |filename|
|
49
|
+
Aerogel.require_into( Aerogel::Application, filename )
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
7
54
|
end # module Aerogel::Routes
|
@@ -0,0 +1,37 @@
|
|
1
|
+
|
2
|
+
module Aerogel::Routes
|
3
|
+
class Namespace
|
4
|
+
|
5
|
+
def initialize( base, path, &block )
|
6
|
+
@base = base
|
7
|
+
@prefix_path = path
|
8
|
+
instance_eval &block
|
9
|
+
end
|
10
|
+
|
11
|
+
def method_missing( method, *args, &block )
|
12
|
+
@base.send method, *args, &block
|
13
|
+
end
|
14
|
+
|
15
|
+
def prefixed( method, *args, &block )
|
16
|
+
options = Hash === args.last ? args.pop : {}
|
17
|
+
routes = [*(args.pop || '')]
|
18
|
+
routes, args = routes+args, [] unless method == :route
|
19
|
+
routes.map!{|r| @prefix_path+r }
|
20
|
+
routes = [routes] if method == :route
|
21
|
+
p_args = []
|
22
|
+
p_args += args unless args.empty?
|
23
|
+
p_args += routes # unless routes.empty?
|
24
|
+
p_args += options unless options.empty?
|
25
|
+
@base.send method, *p_args, &block
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.prefix( *methods )
|
29
|
+
methods.each do |method|
|
30
|
+
define_method(method) {|*args, &block| prefixed( method, *args, &block ) }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
prefix :get, :post, :put, :delete, :before, :after, :namespace, :route
|
35
|
+
|
36
|
+
end # class Namespace
|
37
|
+
end # module Aerogel::Routes
|
data/lib/aerogel/core/version.rb
CHANGED
metadata
CHANGED
@@ -1,181 +1,181 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aerogel-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Kukushkin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-02-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sinatra
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: sinatra-contrib
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: sinatra-asset-pipeline
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rack-flash3
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: sass
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '0'
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- -
|
80
|
+
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: coffee-script
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- -
|
87
|
+
- - ">="
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: '0'
|
90
90
|
type: :runtime
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- -
|
94
|
+
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: uglifier
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- -
|
101
|
+
- - ">="
|
102
102
|
- !ruby/object:Gem::Version
|
103
103
|
version: '0'
|
104
104
|
type: :runtime
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
|
-
- -
|
108
|
+
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: yui-compressor
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
|
-
- -
|
115
|
+
- - ">="
|
116
116
|
- !ruby/object:Gem::Version
|
117
117
|
version: '0'
|
118
118
|
type: :runtime
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
|
-
- -
|
122
|
+
- - ">="
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
126
|
name: aerogel-configurator
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
128
128
|
requirements:
|
129
|
-
- -
|
129
|
+
- - "~>"
|
130
130
|
- !ruby/object:Gem::Version
|
131
|
-
version: '
|
131
|
+
version: '1.3'
|
132
132
|
type: :runtime
|
133
133
|
prerelease: false
|
134
134
|
version_requirements: !ruby/object:Gem::Requirement
|
135
135
|
requirements:
|
136
|
-
- -
|
136
|
+
- - "~>"
|
137
137
|
- !ruby/object:Gem::Version
|
138
|
-
version: '
|
138
|
+
version: '1.3'
|
139
139
|
- !ruby/object:Gem::Dependency
|
140
140
|
name: mongoid
|
141
141
|
requirement: !ruby/object:Gem::Requirement
|
142
142
|
requirements:
|
143
|
-
- -
|
143
|
+
- - ">="
|
144
144
|
- !ruby/object:Gem::Version
|
145
145
|
version: '0'
|
146
146
|
type: :runtime
|
147
147
|
prerelease: false
|
148
148
|
version_requirements: !ruby/object:Gem::Requirement
|
149
149
|
requirements:
|
150
|
-
- -
|
150
|
+
- - ">="
|
151
151
|
- !ruby/object:Gem::Version
|
152
152
|
version: '0'
|
153
153
|
- !ruby/object:Gem::Dependency
|
154
154
|
name: bundler
|
155
155
|
requirement: !ruby/object:Gem::Requirement
|
156
156
|
requirements:
|
157
|
-
- - ~>
|
157
|
+
- - "~>"
|
158
158
|
- !ruby/object:Gem::Version
|
159
159
|
version: '1.3'
|
160
160
|
type: :development
|
161
161
|
prerelease: false
|
162
162
|
version_requirements: !ruby/object:Gem::Requirement
|
163
163
|
requirements:
|
164
|
-
- - ~>
|
164
|
+
- - "~>"
|
165
165
|
- !ruby/object:Gem::Version
|
166
166
|
version: '1.3'
|
167
167
|
- !ruby/object:Gem::Dependency
|
168
168
|
name: rake
|
169
169
|
requirement: !ruby/object:Gem::Requirement
|
170
170
|
requirements:
|
171
|
-
- -
|
171
|
+
- - ">="
|
172
172
|
- !ruby/object:Gem::Version
|
173
173
|
version: '0'
|
174
174
|
type: :development
|
175
175
|
prerelease: false
|
176
176
|
version_requirements: !ruby/object:Gem::Requirement
|
177
177
|
requirements:
|
178
|
-
- -
|
178
|
+
- - ">="
|
179
179
|
- !ruby/object:Gem::Version
|
180
180
|
version: '0'
|
181
181
|
description: Aerogel core module
|
@@ -185,7 +185,7 @@ executables: []
|
|
185
185
|
extensions: []
|
186
186
|
extra_rdoc_files: []
|
187
187
|
files:
|
188
|
-
- .gitignore
|
188
|
+
- ".gitignore"
|
189
189
|
- Gemfile
|
190
190
|
- LICENSE.txt
|
191
191
|
- README.md
|
@@ -206,7 +206,6 @@ files:
|
|
206
206
|
- config/database.conf.template
|
207
207
|
- config/development/.keep
|
208
208
|
- config/production/.keep
|
209
|
-
- db/model/model.rb.template
|
210
209
|
- db/seed/development/.keep
|
211
210
|
- db/seed/production/.keep
|
212
211
|
- db/seed/seed.template
|
@@ -216,11 +215,17 @@ files:
|
|
216
215
|
- lib/aerogel/core/config.rb
|
217
216
|
- lib/aerogel/core/core.rb
|
218
217
|
- lib/aerogel/core/db.rb
|
218
|
+
- lib/aerogel/core/db/model.rb
|
219
|
+
- lib/aerogel/core/errors.rb
|
219
220
|
- lib/aerogel/core/helpers.rb
|
221
|
+
- lib/aerogel/core/reloader.rb
|
220
222
|
- lib/aerogel/core/render.rb
|
221
223
|
- lib/aerogel/core/render/block_helper.rb
|
222
224
|
- lib/aerogel/core/render/output_buffer.rb
|
225
|
+
- lib/aerogel/core/render/scope.rb
|
223
226
|
- lib/aerogel/core/routes.rb
|
227
|
+
- lib/aerogel/core/routes/namespace.rb
|
228
|
+
- lib/aerogel/core/routes/sinatra_ex.rb
|
224
229
|
- lib/aerogel/core/version.rb
|
225
230
|
- lib/aerogel/rake.rb
|
226
231
|
- public/favicon.ico
|
@@ -232,7 +237,7 @@ files:
|
|
232
237
|
- views/index.html.erb
|
233
238
|
- views/layouts/application.html.erb
|
234
239
|
- views/lorem.html.erb
|
235
|
-
homepage:
|
240
|
+
homepage: https://github.com/kukushkin/aerogel-core
|
236
241
|
licenses:
|
237
242
|
- MIT
|
238
243
|
metadata: {}
|
@@ -242,17 +247,17 @@ require_paths:
|
|
242
247
|
- lib
|
243
248
|
required_ruby_version: !ruby/object:Gem::Requirement
|
244
249
|
requirements:
|
245
|
-
- -
|
250
|
+
- - ">="
|
246
251
|
- !ruby/object:Gem::Version
|
247
252
|
version: '0'
|
248
253
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
249
254
|
requirements:
|
250
|
-
- -
|
255
|
+
- - ">="
|
251
256
|
- !ruby/object:Gem::Version
|
252
257
|
version: '0'
|
253
258
|
requirements: []
|
254
259
|
rubyforge_project:
|
255
|
-
rubygems_version: 2.
|
260
|
+
rubygems_version: 2.2.2
|
256
261
|
signing_key:
|
257
262
|
specification_version: 4
|
258
263
|
summary: Aerogel is a modular opinionated CMS
|