aerogel-core 1.0.4 → 1.1.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 +1 -1
- data/app/helpers/assets.rb +15 -0
- data/app/helpers/config.rb +9 -0
- data/app/helpers/output_buffer.rb +26 -0
- data/lib/{aerogel-core.rb → aerogel/core.rb} +4 -4
- data/lib/{aerogel-core → aerogel/core}/application.rb +7 -5
- data/lib/{aerogel-core → aerogel/core}/assets.rb +0 -0
- data/lib/{aerogel-core → aerogel/core}/config.rb +0 -0
- data/lib/{aerogel-core → aerogel/core}/core.rb +0 -0
- data/lib/{aerogel-core → aerogel/core}/db.rb +0 -0
- data/lib/{aerogel-core → aerogel/core}/helpers.rb +0 -0
- data/lib/aerogel/core/render.rb +13 -0
- data/lib/aerogel/core/render/block_helper.rb +46 -0
- data/lib/aerogel/core/render/output_buffer.rb +66 -0
- data/lib/{aerogel-core → aerogel/core}/routes.rb +0 -0
- data/lib/aerogel/core/version.rb +3 -0
- data/lib/{aerogel-core → aerogel}/rake.rb +1 -1
- metadata +18 -12
- data/lib/aerogel-core/version.rb +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 34096608560195b108c8293d58d750ecd2c71e55
|
4
|
+
data.tar.gz: aef77ff72c91c44dcc31773ab1db82898fdf18af
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6110c5fd235c225219491bf76f2050fd8a4230870302f246dffcb32aa70e0054ac14efcd380275789060e9789658a777c234393c1795f42282b005028d0ae7e2
|
7
|
+
data.tar.gz: 9a54b53fe15a2d57c841fc056bbaf04168125c606ade574e2a0f333545ce3e605296a3920b9f07c22e4062f29d5b3b1137585e524bebf28702c99172aca872d5
|
data/aerogel-core.gemspec
CHANGED
@@ -0,0 +1,15 @@
|
|
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
|
@@ -0,0 +1,26 @@
|
|
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 !OutputBuffer.buffer.nil? # has_erb_buffer?
|
7
|
+
OutputBuffer.buffer.concat text
|
8
|
+
else # theres no template to concat, return the text directly
|
9
|
+
text
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
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 OutputBuffer.block_is_erb? block
|
19
|
+
# erb
|
20
|
+
OutputBuffer.capture( &block )
|
21
|
+
else
|
22
|
+
block.call
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end # module Aerogel::Helpers
|
@@ -1,8 +1,8 @@
|
|
1
|
-
require 'aerogel
|
2
|
-
require 'aerogel
|
1
|
+
require 'aerogel/core/version'
|
2
|
+
require 'aerogel/core/core'
|
3
3
|
|
4
4
|
# Path to the aerogel gem
|
5
|
-
Aerogel.core_path = File.expand_path( File.join( File.dirname(__FILE__), ".." ) )
|
5
|
+
Aerogel.core_path = File.expand_path( File.join( File.dirname(__FILE__), "..", ".." ) )
|
6
6
|
|
7
7
|
# Default applicaiton path, may be overridden in application's config.ru
|
8
8
|
Aerogel.application_path = File.expand_path( Dir.pwd )
|
@@ -10,4 +10,4 @@ Aerogel.application_path = File.expand_path( Dir.pwd )
|
|
10
10
|
# Core path is registered first
|
11
11
|
Aerogel.register_path( Aerogel.core_path )
|
12
12
|
|
13
|
-
require "aerogel
|
13
|
+
require "aerogel/core/application"
|
@@ -1,10 +1,11 @@
|
|
1
1
|
require 'sinatra/base'
|
2
2
|
|
3
|
-
require 'aerogel
|
4
|
-
require 'aerogel
|
5
|
-
require 'aerogel
|
6
|
-
require 'aerogel
|
7
|
-
require 'aerogel
|
3
|
+
require 'aerogel/core/config'
|
4
|
+
require 'aerogel/core/helpers'
|
5
|
+
require 'aerogel/core/routes'
|
6
|
+
require 'aerogel/core/assets'
|
7
|
+
require 'aerogel/core/db'
|
8
|
+
require 'aerogel/core/render'
|
8
9
|
|
9
10
|
class Aerogel::Application < Sinatra::Base
|
10
11
|
|
@@ -28,6 +29,7 @@ private
|
|
28
29
|
register Aerogel::Routes
|
29
30
|
register Aerogel::Assets
|
30
31
|
register Aerogel::Db
|
32
|
+
register Aerogel::Render
|
31
33
|
puts "** Aerogel application configured v#{Aerogel::version}-#{environment}"
|
32
34
|
end
|
33
35
|
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'aerogel/core/render/output_buffer'
|
2
|
+
require 'aerogel/core/render/block_helper'
|
3
|
+
|
4
|
+
|
5
|
+
module Aerogel::Render
|
6
|
+
|
7
|
+
# Configures application.
|
8
|
+
#
|
9
|
+
def self.registered(app)
|
10
|
+
app.set :erb, outvar: 'Aerogel::Render::OutputBuffer.buffer'
|
11
|
+
end
|
12
|
+
|
13
|
+
end # module Aerogel::Render
|
@@ -0,0 +1,46 @@
|
|
1
|
+
#
|
2
|
+
# BlockHelper
|
3
|
+
# Template level helper.
|
4
|
+
# Base class for DSL magic in view helpers.
|
5
|
+
#
|
6
|
+
|
7
|
+
module Aerogel::Render
|
8
|
+
|
9
|
+
class BlockHelper
|
10
|
+
|
11
|
+
# Creates a block helper object.
|
12
|
+
# args will be passed to the block as arguments.
|
13
|
+
#
|
14
|
+
def initialize( *args, &block )
|
15
|
+
@args = args
|
16
|
+
@block = block
|
17
|
+
|
18
|
+
# makes methods and helpers accessible at the self instance scope
|
19
|
+
@self_before_instance_eval = eval "self", @block.binding
|
20
|
+
end
|
21
|
+
|
22
|
+
# Wraps captured content with custom tags or text.
|
23
|
+
# Most of the time, method should be redefined by descendant class.
|
24
|
+
# A good example would be a form helper, that surrounds captured content with <form ..></form> tags.
|
25
|
+
#
|
26
|
+
def wrap( content )
|
27
|
+
content
|
28
|
+
end
|
29
|
+
|
30
|
+
# Renders output to the template or returns it as a string.
|
31
|
+
#
|
32
|
+
def render
|
33
|
+
content = output_capture(@block) do
|
34
|
+
instance_exec( *@args, &@block )
|
35
|
+
end
|
36
|
+
content_wrapped = output_capture() { wrap( content ) }
|
37
|
+
output_concat content_wrapped
|
38
|
+
end
|
39
|
+
|
40
|
+
def method_missing(method, *args, &block)
|
41
|
+
@self_before_instance_eval.send method, *args, &block
|
42
|
+
end
|
43
|
+
|
44
|
+
end # class BlockHelper
|
45
|
+
|
46
|
+
end # module Aerogel::Render
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# Global rendering buffer.
|
2
|
+
# Output capture functionality for ERb and Haml blocks.
|
3
|
+
#
|
4
|
+
module Aerogel::Render
|
5
|
+
module OutputBuffer
|
6
|
+
|
7
|
+
# Returns instance of a string buffer
|
8
|
+
#
|
9
|
+
def self.buffer
|
10
|
+
@buffer
|
11
|
+
end
|
12
|
+
|
13
|
+
# Sets instance of a string buffer
|
14
|
+
#
|
15
|
+
def self.buffer=( text )
|
16
|
+
@buffer = text
|
17
|
+
end
|
18
|
+
|
19
|
+
# Saves current buffer in a stack and creates a new empty one.
|
20
|
+
#
|
21
|
+
def self.push
|
22
|
+
@buffer_stack ||= []
|
23
|
+
@buffer_stack.unshift @buffer
|
24
|
+
@buffer = ''
|
25
|
+
end
|
26
|
+
|
27
|
+
# Returns current buffer contents as a string and restores previous
|
28
|
+
# buffer state from a stack.
|
29
|
+
#
|
30
|
+
def self.pop
|
31
|
+
result = @buffer
|
32
|
+
@buffer = @buffer_stack.shift
|
33
|
+
result
|
34
|
+
end
|
35
|
+
|
36
|
+
# Executes block and captures content rendered into buffer.
|
37
|
+
# If no content is rendered into buffer, returns block yield result as a content.
|
38
|
+
#
|
39
|
+
def self.capture(*args, &block)
|
40
|
+
self.push
|
41
|
+
blk_result = yield *args
|
42
|
+
buf_result = self.pop
|
43
|
+
buf_result.nil? || buf_result.empty? ? blk_result : buf_result
|
44
|
+
end
|
45
|
+
|
46
|
+
# Returns true if block is defined within a ERb template.
|
47
|
+
#
|
48
|
+
def self.block_is_erb?( block )
|
49
|
+
!@buffer.nil? || block && eval('defined? __in_erb_template', block.binding)
|
50
|
+
end
|
51
|
+
|
52
|
+
# Returns true if block is defined within a ERb template.
|
53
|
+
#
|
54
|
+
def self.block_is_haml?( block )
|
55
|
+
block && eval('block_is_haml?(self)', block.binding)
|
56
|
+
end
|
57
|
+
|
58
|
+
# Returns true if block is defined within any template.
|
59
|
+
#
|
60
|
+
def self.block_is_template?( block )
|
61
|
+
block && ( block_is_erb?(block) || block_is_haml?( block ) )
|
62
|
+
end
|
63
|
+
|
64
|
+
end # module OutputBuffer
|
65
|
+
end # module Aerogel::Render
|
66
|
+
|
File without changes
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aerogel-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.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-
|
11
|
+
date: 2014-01-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sinatra
|
@@ -177,7 +177,10 @@ files:
|
|
177
177
|
- README.md
|
178
178
|
- Rakefile
|
179
179
|
- aerogel-core.gemspec
|
180
|
+
- app/helpers/assets.rb
|
181
|
+
- app/helpers/config.rb
|
180
182
|
- app/helpers/core.rb
|
183
|
+
- app/helpers/output_buffer.rb
|
181
184
|
- app/helpers/render.rb
|
182
185
|
- app/routes/core.rb
|
183
186
|
- app/routes/static.rb
|
@@ -191,16 +194,19 @@ files:
|
|
191
194
|
- db/seed/development/.keep
|
192
195
|
- db/seed/production/.keep
|
193
196
|
- db/seed/seed.template
|
194
|
-
- lib/aerogel
|
195
|
-
- lib/aerogel
|
196
|
-
- lib/aerogel
|
197
|
-
- lib/aerogel
|
198
|
-
- lib/aerogel
|
199
|
-
- lib/aerogel
|
200
|
-
- lib/aerogel
|
201
|
-
- lib/aerogel
|
202
|
-
- lib/aerogel
|
203
|
-
- lib/aerogel
|
197
|
+
- lib/aerogel/core.rb
|
198
|
+
- lib/aerogel/core/application.rb
|
199
|
+
- lib/aerogel/core/assets.rb
|
200
|
+
- lib/aerogel/core/config.rb
|
201
|
+
- lib/aerogel/core/core.rb
|
202
|
+
- lib/aerogel/core/db.rb
|
203
|
+
- lib/aerogel/core/helpers.rb
|
204
|
+
- lib/aerogel/core/render.rb
|
205
|
+
- lib/aerogel/core/render/block_helper.rb
|
206
|
+
- lib/aerogel/core/render/output_buffer.rb
|
207
|
+
- lib/aerogel/core/routes.rb
|
208
|
+
- lib/aerogel/core/version.rb
|
209
|
+
- lib/aerogel/rake.rb
|
204
210
|
- public/favicon.ico
|
205
211
|
- public/humans.txt
|
206
212
|
- public/robots.txt.development
|
data/lib/aerogel-core/version.rb
DELETED