methodmissing-erubis_template_handler 0.0.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.
data/README.textile ADDED
@@ -0,0 +1,8 @@
1
+ h1. Erubis Template Handler
2
+
3
+ h2. Usage
4
+
5
+ A drop in replacement for the ERB template handler.
6
+
7
+ sudo gem install erubis
8
+ sudo gem install methodmissing-erubis_template_handler -s http://gems.github.com
@@ -0,0 +1,46 @@
1
+ module ActionView
2
+ module Helpers
3
+ module ErubisHelper
4
+
5
+ def capture(*args, &block)
6
+ if block_called_from_erb?(block)
7
+ with_output_buffer { block.call(*args) }
8
+ elsif block_called_from_erubis?(block)
9
+ # Thanks Mack
10
+ buffer = eval( "@output_buffer", block.binding, __FILE__, __LINE__) rescue nil
11
+ if buffer.nil?
12
+ block.call(*args)
13
+ else
14
+ pos = buffer.length
15
+ block.call(*args)
16
+ result = buffer[pos..-1]
17
+ buffer[pos..-1] = ''
18
+ result
19
+ end
20
+ else
21
+ with_output_buffer { return block.call(*args) }
22
+ end
23
+ end
24
+
25
+ private
26
+ BLOCK_CALLED_FROM_ERUBIS = 'defined? __in_erubis_template'
27
+
28
+ if RUBY_VERSION < '1.9.0'
29
+ def block_called_from_erubis?(block)
30
+ block && eval(BLOCK_CALLED_FROM_ERUBIS, block)
31
+ end
32
+ else
33
+ def block_called_from_erubis?(block)
34
+ block && eval(BLOCK_CALLED_FROM_ERUBIS, block.binding)
35
+ end
36
+ end
37
+
38
+ end
39
+ end
40
+ end
41
+
42
+ module ActionView
43
+ class Base
44
+ include ActionView::Helpers::ErubisHelper
45
+ end
46
+ end
@@ -0,0 +1,27 @@
1
+ require 'output_buffer_enhancer'
2
+
3
+ module ActionView
4
+ module TemplateHandlers
5
+ class EnhancedEruby < Erubis::FastEruby
6
+ include ::Erubis::PercentLineEnhancer
7
+ include ::Erubis::DeleteIndentEnhancer
8
+ include ::Erubis::OutputBufferEnhancer
9
+ end
10
+
11
+ class Erubis < TemplateHandler
12
+ include Compilable
13
+
14
+ def self.install!
15
+ ActionView::Template.register_default_template_handler :erb, self
16
+ end
17
+
18
+ def compile(template)
19
+ options = {}
20
+ EnhancedEruby.new(template.source, options).src
21
+ end
22
+
23
+ end
24
+ end
25
+ end
26
+
27
+ ActionView::TemplateHandlers::Erubis.install!
@@ -0,0 +1,13 @@
1
+ module Erubis
2
+ module OutputBufferEnhancer
3
+
4
+ def self.desc # :nodoc:
5
+ "set '@output_buffer = _buf = \"\";'"
6
+ end
7
+
8
+ def add_preamble(src)
9
+ src << "__in_erubis_template=true; @output_buffer = _buf = '';"
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,11 @@
1
+ class ProductsController < ActionController::Base
2
+
3
+ helper :products
4
+
5
+ def index
6
+ @products = %w(one two three)
7
+ end
8
+
9
+ def rescue_action(e) raise e end
10
+
11
+ end
@@ -0,0 +1,16 @@
1
+ require File.join( File.dirname(__FILE__), 'test_helper' )
2
+
3
+ class ErubisHandlerTest < ActionController::TestCase
4
+
5
+ def setup
6
+ @request = ActionController::TestRequest.new
7
+ @response = ActionController::TestResponse.new
8
+ @controller = ProductsController.new
9
+ end
10
+
11
+ test "should be able to render with success" do
12
+ get :index
13
+ assert_response 200
14
+ end
15
+
16
+ end
@@ -0,0 +1,7 @@
1
+ module ProductsHelper
2
+
3
+ def with_pagination( &block )
4
+ concat( "pagination_before " + capture(&block) + " pagination_after" )
5
+ end
6
+
7
+ end
@@ -0,0 +1,58 @@
1
+ require 'init'
2
+
3
+ RAILS_ROOT = '' unless Object.const_defined?('RAILS_ROOT')
4
+
5
+ module ActionView
6
+ module TemplateHandlers
7
+ module Test
8
+ class Erubis
9
+ class << self
10
+
11
+ def setup!
12
+ dependencies!
13
+ routing!
14
+ logger!
15
+ dependencies!
16
+ view_and_helper_paths!
17
+ end
18
+
19
+ private
20
+
21
+ def dependencies!
22
+ require 'action_controller/test_process'
23
+ require 'test_help'
24
+ end
25
+
26
+ def routing!
27
+ ::ActionController::Routing::Routes.draw do |map|
28
+ map.connect ':controller/:action/:id'
29
+ map.connect ':controller/:action/:id.:format'
30
+ end
31
+ end
32
+
33
+ def logger!
34
+ ::ActionController::Base.logger = Logger.new( STDOUT )
35
+ end
36
+
37
+ def dependencies!
38
+ %w(helpers controllers).each do |dir|
39
+ ::ActiveSupport::Dependencies.load_paths << relative( dir )
40
+ end
41
+ end
42
+
43
+ def view_and_helper_paths!
44
+ ::ActionController::Base.helpers_dir = relative( 'helpers' )
45
+ ::ActionController::Base.view_paths = relative( 'views' )
46
+ end
47
+
48
+ def relative( *path )
49
+ File.join( File.dirname(__FILE__), *path )
50
+ end
51
+
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
57
+
58
+ ActionView::TemplateHandlers::Test::Erubis.setup!
@@ -0,0 +1 @@
1
+ <p><%= product.to_s %></p>
@@ -0,0 +1,3 @@
1
+ <% with_pagination do %>
2
+ <%= render :partial => 'product', :collection => @products %>
3
+ <% end %>
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: methodmissing-erubis_template_handler
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - "Lourens Naud\xC3\xA9"
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-02-07 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Rails 2.3 / Edge template handler for erubis ( http://www.kuwata-lab.com/erubis/ )
17
+ email: lourens@methodmissing.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - README.textile
26
+ - lib/action_view
27
+ - lib/action_view/helpers
28
+ - lib/action_view/helpers/erubis_helper.rb
29
+ - lib/action_view/template_handlers
30
+ - lib/action_view/template_handlers/erubis.rb
31
+ - lib/output_buffer_enhancer.rb
32
+ - test/controllers
33
+ - test/controllers/products_controller.rb
34
+ - test/erubis_handler_test.rb
35
+ - test/helpers
36
+ - test/helpers/products_helper.rb
37
+ - test/test_helper.rb
38
+ - test/views
39
+ - test/views/products
40
+ - test/views/products/_product.erb
41
+ - test/views/products/index.erb
42
+ has_rdoc: true
43
+ homepage: http://github.com/methodmissing/erubis_template_handler
44
+ post_install_message:
45
+ rdoc_options:
46
+ - --inline-source
47
+ - --charset=UTF-8
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: "0"
55
+ version:
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: "0"
61
+ version:
62
+ requirements: []
63
+
64
+ rubyforge_project:
65
+ rubygems_version: 1.2.0
66
+ signing_key:
67
+ specification_version: 2
68
+ summary: Rails 2.3 / Edge template handler for erubis ( http://www.kuwata-lab.com/erubis/ )
69
+ test_files: []
70
+