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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 03745769b429a1a9f37d4cc55d91c33b134d18f3
4
- data.tar.gz: f1e55f86299fe31ff72c98fdce5ea959c9981bdc
3
+ metadata.gz: b0b6c95d4a960593785baf5d48ffdf798bcaf5da
4
+ data.tar.gz: 2c964b75f82fb8b0c141c93ca81ee3c9909a270f
5
5
  SHA512:
6
- metadata.gz: 38b100edb2a525b7f56351964d612e4f5a10655328d996fe7be1e938de34cd40a807c5864888ab0839dadfdd06ed48ba0f61ebd436c4ae1c27610e762be91dff
7
- data.tar.gz: ce62b0f6e225916d387226dd3d9c0edf484c73800d84bbb03c40a70d167c7488668329250f4aa6ec4bcf6fa96ba32c8ca69d66e87cbf9257fe263b09fa2a2d24
6
+ metadata.gz: d544fb26f5f875bd4a27bffb261cadbd8638141d98188d47e15bd4ce3aaea77bc96eb2ca660087f9a71e266d425a2c13664c2d6361b7a833dfb177efab7d0de3
7
+ data.tar.gz: 9dd900eb31268b5f3a523f1cb5326b6631dd2dd1aacc597404920cc172b9338e53dca948f867184f1ec975a1737a3a1e3986fa3974762a93a7cf865f65033c6b
@@ -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"
@@ -1,15 +1,11 @@
1
- module Aerogel::Helpers
2
-
3
- # Include styles and javascript tags for assets grouped by scope.
4
- #
5
- # Intended use is either:
6
- # <%= assets %> # for application assets
7
- # or:
8
- # <% assets 'controller/name' %> # for controller specific assets
9
- #
10
- def assets( filename = :application )
11
- (stylesheet_tag filename.to_s) +
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
@@ -1,9 +1,5 @@
1
- module Aerogel::Helpers
2
-
3
- # Quick access to config from views and routes
4
- #
5
- def config
6
- settings.config
7
- end
8
-
9
- end # module Aerogel::Helpers
1
+ # Quick access to config from views and routes
2
+ #
3
+ def config
4
+ Aerogel.config
5
+ end
@@ -1,15 +1,11 @@
1
- module Aerogel::Helpers
1
+ def find_template(views, name, engine, &block)
2
+ Array(views).each { |v| super(v, name, engine, &block) }
3
+ end
2
4
 
3
- def find_template(views, name, engine, &block)
4
- Array(views).each { |v| super(v, name, engine, &block) }
5
- end
6
-
7
- def logger( name = nil )
8
- if name.nil?
9
- env['rack.logger']
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
@@ -1,19 +1,15 @@
1
- module Aerogel::Helpers
1
+ def csrf_field_name
2
+ 'authenticity_token'
3
+ end
2
4
 
3
- def csrf_field_name
4
- 'authenticity_token'
5
- end
5
+ def csrf_token
6
+ session[:csrf] ||= SecureRandom.hex(32) if defined?(session)
7
+ end
6
8
 
7
- def csrf_token
8
- session[:csrf] ||= SecureRandom.hex(32) if defined?(session)
9
- end
9
+ def csrf_token_field
10
+ tag :input, type: 'hidden', name: csrf_field_name, value: csrf_token
11
+ end
10
12
 
11
- def csrf_token_field
12
- input_hidden_tag csrf_field_name, csrf_token
13
- end
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
- module Aerogel::Helpers
2
-
3
- def output_concat( text )
4
- if self.respond_to?(:is_haml?) && is_haml?
5
- haml_concat(text)
6
- elsif !Aerogel::Render::OutputBuffer.buffer.nil? # has_erb_buffer?
7
- Aerogel::Render::OutputBuffer.buffer.concat text
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
- def output_capture( inner_block = nil, &block )
14
- inner_block = block if inner_block.nil?
15
- if self.respond_to?(:is_haml?) && is_haml? && (block_is_haml?(inner_block) rescue false)
16
- # haml
17
- capture_haml(nil, &block)
18
- elsif Aerogel::Render::OutputBuffer.block_is_erb? block
19
- # erb
20
- Aerogel::Render::OutputBuffer.capture( &block )
21
- else
22
- block.call
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
@@ -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
@@ -1,28 +1,29 @@
1
- module Aerogel::Helpers
2
-
3
- # Creates tag.
4
- #
5
- def tag( name, *args, &block )
6
- if block_given?
7
- content = output_capture(&block)
8
- elsif args.first.is_a? String
9
- content = args.shift
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
- t_attrs = attrs.map{|k,v| v.nil? ? " #{k}" : " #{k}=\"#{(v)}\""}
14
- if content
15
- output = "<#{name}#{t_attrs.join}>"+content+"</#{name}>"
16
- else
17
- output = "<#{name}#{t_attrs.join}/>"
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
- end # module Aerogel::Helpers
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
@@ -1,15 +1,11 @@
1
- class Aerogel::Application
1
+ get "/" do
2
+ view :index
3
+ end
2
4
 
3
- get "/" do
4
- view :index
5
- end
5
+ get "/:action" do
6
+ view params['action'] # rescue raise Sinatra::NotFound.new
7
+ end
6
8
 
7
- get "/:action" do
8
- view params['action'] rescue raise Sinatra::NotFound.new
9
- end
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
@@ -1,5 +1,3 @@
1
- class Aerogel::Application
2
-
3
1
  get "/*" do |filename|
4
2
  pass if filename.blank?
5
3
  path = Aerogel.get_resource( :public, filename )
@@ -7,5 +5,3 @@ get "/*" do |filename|
7
5
  pass unless path
8
6
  send_file path
9
7
  end
10
-
11
- end # class Aerogel::Application
@@ -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
- on_load
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
- private
24
+ end # class Aerogel::Application
20
25
 
26
+ Aerogel.on_load do |app|
21
27
  # Loads application environment
22
28
  #
23
- def self.on_load
24
- # application path is registered last
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
- end # class Aerogel::Application
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
@@ -1,34 +1,66 @@
1
1
  require 'aerogel/configurator'
2
2
  require 'rack-flash'
3
+ require 'sinatra/multi_route'
3
4
 
4
- module Aerogel::Config
5
+ module Aerogel
5
6
 
6
- # Configures application.
7
+ # Returns Aerogel application's config object.
7
8
  #
8
- def self.registered(app)
9
- app.set :root, Aerogel.application_path
10
- app.set :views, Aerogel.get_resource_paths( :views ).reverse
11
- app.set :erb, layout: "layouts/application.html".to_sym
12
-
13
- require 'sinatra/reloader' if app.development?
14
- app.configure :development do
15
- app.register Sinatra::Reloader
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
- # Load configs
19
- app.set :config, Configurator.new
20
- Aerogel.get_resource_list( :config, '*.conf', app.environment ).each do |config_filename|
21
- app.config.load config_filename
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
- # set :protection, true
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
- end
33
- end # module Aerogel::Config
65
+ end # module Aerogel
34
66
 
@@ -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
@@ -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 app.config.db.nil?
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: app.config.db.hosts, database: app.config.db.name }
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
- self.models = []
52
- Aerogel.get_resource_list( 'db/model', '*.rb', environment ).each do |model_filename|
53
- require model_filename
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
@@ -0,0 +1,11 @@
1
+ module Aerogel
2
+ module Errors
3
+
4
+ class NotFoundError < StandardError
5
+
6
+ end # class NotFoundError
7
+
8
+ end # module Errors
9
+ end # module Aerogel
10
+
11
+ include Aerogel::Errors
@@ -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.require_resources( :app, "helpers/**/*.rb" )
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
@@ -1,5 +1,6 @@
1
1
  require 'aerogel/core/render/output_buffer'
2
2
  require 'aerogel/core/render/block_helper'
3
+ require 'aerogel/core/render/scope'
3
4
 
4
5
 
5
6
  module Aerogel::Render
@@ -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
@@ -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::require_resources_reverse( :app, "routes/**/*.rb" )
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
@@ -0,0 +1,11 @@
1
+ # A helper method to reset Sinatra routes.
2
+ #
3
+ class Sinatra::Base
4
+ class << self
5
+ def reset_routes!
6
+ @routes = {}
7
+ @filters = {:before => [], :after => []}
8
+ @errors = {}
9
+ end
10
+ end
11
+ end # class Sinatra::Base
@@ -1,3 +1,3 @@
1
1
  module Aerogel
2
- VERSION = '1.1.1'
2
+ VERSION = '1.3.0'
3
3
  end
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.1.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-01-28 00:00:00.000000000 Z
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: '0'
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: '0'
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.0.6
260
+ rubygems_version: 2.2.2
256
261
  signing_key:
257
262
  specification_version: 4
258
263
  summary: Aerogel is a modular opinionated CMS
@@ -1,11 +0,0 @@
1
-
2
- class Setting
3
- include Mongoid::Document
4
- field :name, type: String
5
- field :value, type: String
6
-
7
- validates_presence_of :name
8
- validates_uniqueness_of :name
9
-
10
- index( name: 1 )
11
- end