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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5f78add168e5ace6b49d5f75903b43c4f684be0a
4
- data.tar.gz: e20f29677e6b3c1325ed319f948198ea0c89872c
3
+ metadata.gz: 34096608560195b108c8293d58d750ecd2c71e55
4
+ data.tar.gz: aef77ff72c91c44dcc31773ab1db82898fdf18af
5
5
  SHA512:
6
- metadata.gz: 9c43359f0b61ea67a960a776474ce4b936c5dec58f3a4b2262a86d31a35089a35b618ad192b602caf694c927ac844487a8c6b682f93a5e3a378574b7c03e73e4
7
- data.tar.gz: 2e39951fc23ca1c2d7a2664e6e2c84c40f1e9974b311bcbebbc8c0601cfef59fcdf305c7ba09c1a942ce071f53b1151bc74c41039cf987197d9d07147e5b8d97
6
+ metadata.gz: 6110c5fd235c225219491bf76f2050fd8a4230870302f246dffcb32aa70e0054ac14efcd380275789060e9789658a777c234393c1795f42282b005028d0ae7e2
7
+ data.tar.gz: 9a54b53fe15a2d57c841fc056bbaf04168125c606ade574e2a0f333545ce3e605296a3920b9f07c22e4062f29d5b3b1137585e524bebf28702c99172aca872d5
data/aerogel-core.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  # coding: utf-8
2
2
  lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'aerogel-core/version'
4
+ require 'aerogel/core/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "aerogel-core"
@@ -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,9 @@
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
@@ -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-core/version'
2
- require 'aerogel-core/core'
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-core/application"
13
+ require "aerogel/core/application"
@@ -1,10 +1,11 @@
1
1
  require 'sinatra/base'
2
2
 
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'
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
@@ -0,0 +1,3 @@
1
+ module Aerogel
2
+ VERSION = '1.1.0'
3
+ end
@@ -1,5 +1,5 @@
1
1
  require 'sinatra/asset_pipeline/task'
2
- require 'aerogel-core'
2
+ require 'aerogel/core'
3
3
 
4
4
  Aerogel::Application.load
5
5
  Sinatra::AssetPipeline::Task.define! Aerogel::Application
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
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-24 00:00:00.000000000 Z
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-core.rb
195
- - lib/aerogel-core/application.rb
196
- - lib/aerogel-core/assets.rb
197
- - lib/aerogel-core/config.rb
198
- - lib/aerogel-core/core.rb
199
- - lib/aerogel-core/db.rb
200
- - lib/aerogel-core/helpers.rb
201
- - lib/aerogel-core/rake.rb
202
- - lib/aerogel-core/routes.rb
203
- - lib/aerogel-core/version.rb
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
@@ -1,3 +0,0 @@
1
- module Aerogel
2
- VERSION = '1.0.4'
3
- end