erector-rails4 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.coveralls.yml +2 -0
- data/.gitignore +10 -0
- data/.rspec +1 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +5 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +143 -0
- data/README.md +4 -0
- data/Rakefile +24 -0
- data/erector-rails4.gemspec +36 -0
- data/erector-rails4.sublimeproject +20 -0
- data/lib/erector/abstract_widget.rb +231 -0
- data/lib/erector/after_initialize.rb +29 -0
- data/lib/erector/attributes.rb +29 -0
- data/lib/erector/cache.rb +37 -0
- data/lib/erector/caching.rb +65 -0
- data/lib/erector/convenience.rb +98 -0
- data/lib/erector/dependencies.rb +24 -0
- data/lib/erector/dependency.rb +31 -0
- data/lib/erector/element.rb +113 -0
- data/lib/erector/externals.rb +104 -0
- data/lib/erector/html.rb +12 -0
- data/lib/erector/html_widget.rb +220 -0
- data/lib/erector/inline.rb +37 -0
- data/lib/erector/jquery.rb +28 -0
- data/lib/erector/mixin.rb +12 -0
- data/lib/erector/needs.rb +95 -0
- data/lib/erector/output.rb +144 -0
- data/lib/erector/promise.rb +141 -0
- data/lib/erector/rails/form_builder.rb +44 -0
- data/lib/erector/rails/railtie.rb +13 -0
- data/lib/erector/rails/template_handler.rb +16 -0
- data/lib/erector/rails/widget_renderer.rb +6 -0
- data/lib/erector/rails.rb +221 -0
- data/lib/erector/raw_string.rb +12 -0
- data/lib/erector/sass.rb +32 -0
- data/lib/erector/tag.rb +66 -0
- data/lib/erector/text.rb +123 -0
- data/lib/erector/unicode.rb +18185 -0
- data/lib/erector/unicode_builder.rb +67 -0
- data/lib/erector/version.rb +5 -0
- data/lib/erector/widget.rb +94 -0
- data/lib/erector/widgets.rb +5 -0
- data/lib/erector/xml_widget.rb +131 -0
- data/lib/erector.rb +28 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/controllers/application.rb +6 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/views/layouts/erb_as_layout.html.erb +2 -0
- data/spec/dummy/app/views/layouts/widget_as_layout.rb +8 -0
- data/spec/dummy/app/views/test/_erb.erb +1 -0
- data/spec/dummy/app/views/test/_erector.rb +5 -0
- data/spec/dummy/app/views/test/_partial_with_locals.rb +7 -0
- data/spec/dummy/app/views/test/bare.rb +5 -0
- data/spec/dummy/app/views/test/erb_from_erector.html.rb +5 -0
- data/spec/dummy/app/views/test/erector_from_erb.html.erb +1 -0
- data/spec/dummy/app/views/test/erector_with_locals_from_erb.html.erb +6 -0
- data/spec/dummy/app/views/test/implicit_assigns.html.rb +5 -0
- data/spec/dummy/app/views/test/needs.html.rb +7 -0
- data/spec/dummy/app/views/test/needs_subclass.html.rb +5 -0
- data/spec/dummy/app/views/test/protected_instance_variable.html.rb +5 -0
- data/spec/dummy/app/views/test/render_default.html.rb +5 -0
- data/spec/dummy/app/views/test/render_default_erb_with_layout.html.erb +1 -0
- data/spec/dummy/app/views/test/render_default_widget_with_layout.html.rb +5 -0
- data/spec/dummy/app/views/test/render_partial.html.rb +5 -0
- data/spec/dummy/app/views/test/render_with_widget_as_layout.rb +5 -0
- data/spec/dummy/app/views/test/render_with_widget_as_layout_using_content_for.rb +8 -0
- data/spec/dummy/config/application.rb +44 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/database.yml +22 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +22 -0
- data/spec/dummy/config/environments/production.rb +49 -0
- data/spec/dummy/config/environments/test.rb +36 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/inflections.rb +10 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +12 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +3 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/db/seeds.rb +7 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/dummy/spec/form_builder_spec.rb +21 -0
- data/spec/dummy/spec/rails_helpers_spec.rb +236 -0
- data/spec/dummy/spec/rails_spec_helper.rb +10 -0
- data/spec/dummy/spec/rails_widget_spec.rb +83 -0
- data/spec/dummy/spec/render_spec.rb +369 -0
- data/spec/erector/after_initialize_spec.rb +45 -0
- data/spec/erector/cache_spec.rb +133 -0
- data/spec/erector/caching_spec.rb +184 -0
- data/spec/erector/convenience_spec.rb +250 -0
- data/spec/erector/dependency_spec.rb +67 -0
- data/spec/erector/hello_from_readme.rb +18 -0
- data/spec/erector/hello_from_readme_spec.rb +11 -0
- data/spec/erector/html_spec.rb +585 -0
- data/spec/erector/indentation_spec.rb +211 -0
- data/spec/erector/inline_spec.rb +94 -0
- data/spec/erector/jquery_spec.rb +35 -0
- data/spec/erector/mixin_spec.rb +65 -0
- data/spec/erector/needs_spec.rb +141 -0
- data/spec/erector/output_spec.rb +293 -0
- data/spec/erector/promise_spec.rb +173 -0
- data/spec/erector/sample-file.txt +1 -0
- data/spec/erector/sass_spec.rb +57 -0
- data/spec/erector/tag_spec.rb +67 -0
- data/spec/erector/unicode_builder_spec.rb +75 -0
- data/spec/erector/widget_spec.rb +310 -0
- data/spec/erector/xml_widget_spec.rb +73 -0
- data/spec/spec_helper.rb +31 -0
- metadata +368 -0
@@ -0,0 +1 @@
|
|
1
|
+
<%= @erb_content %>
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require File.expand_path('../boot', __FILE__)
|
2
|
+
|
3
|
+
require 'rails/all'
|
4
|
+
|
5
|
+
# If you have a Gemfile, require the gems listed there, including any gems
|
6
|
+
# you've limited to :test, :development, or :production.
|
7
|
+
Bundler.require(:default, Rails.env) if defined?(Bundler)
|
8
|
+
|
9
|
+
module Dummy
|
10
|
+
class Application < Rails::Application
|
11
|
+
# Settings in config/environments/* take precedence over those specified here.
|
12
|
+
# Application configuration should go into files in config/initializers
|
13
|
+
# -- all .rb files in that directory are automatically loaded.
|
14
|
+
|
15
|
+
# Custom directories with classes and modules you want to be autoloadable.
|
16
|
+
config.autoload_paths += %W(#{config.root}/app)
|
17
|
+
|
18
|
+
config.cache_store = :memory_store
|
19
|
+
|
20
|
+
# Only load the plugins named here, in the order given (default is alphabetical).
|
21
|
+
# :all can be used as a placeholder for all plugins not explicitly named.
|
22
|
+
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]
|
23
|
+
|
24
|
+
# Activate observers that should always be running.
|
25
|
+
# config.active_record.observers = :cacher, :garbage_collector, :forum_observer
|
26
|
+
|
27
|
+
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
|
28
|
+
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
|
29
|
+
# config.time_zone = 'Central Time (US & Canada)'
|
30
|
+
|
31
|
+
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
|
32
|
+
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
|
33
|
+
# config.i18n.default_locale = :de
|
34
|
+
|
35
|
+
# JavaScript files you want as :defaults (application.js is always included).
|
36
|
+
# config.action_view.javascript_expansions[:defaults] = %w(jquery rails)
|
37
|
+
|
38
|
+
# Configure the default encoding used in templates for Ruby 1.9.
|
39
|
+
config.encoding = "utf-8"
|
40
|
+
|
41
|
+
# Configure sensitive parameters which will be filtered from the log file.
|
42
|
+
config.filter_parameters += [:password]
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# SQLite version 3.x
|
2
|
+
# gem install sqlite3-ruby (not necessary on OS X Leopard)
|
3
|
+
development:
|
4
|
+
adapter: sqlite3
|
5
|
+
database: db/development.sqlite3
|
6
|
+
pool: 5
|
7
|
+
timeout: 5000
|
8
|
+
|
9
|
+
# Warning: The database defined as "test" will be erased and
|
10
|
+
# re-generated from your development database when you run "rake".
|
11
|
+
# Do not set this db to the same as development or production.
|
12
|
+
test:
|
13
|
+
adapter: sqlite3
|
14
|
+
database: db/test.sqlite3
|
15
|
+
pool: 5
|
16
|
+
timeout: 5000
|
17
|
+
|
18
|
+
production:
|
19
|
+
adapter: sqlite3
|
20
|
+
database: db/production.sqlite3
|
21
|
+
pool: 5
|
22
|
+
timeout: 5000
|
@@ -0,0 +1,22 @@
|
|
1
|
+
Dummy::Application.configure do
|
2
|
+
# Settings specified here will take precedence over those in config/environment.rb
|
3
|
+
|
4
|
+
# In the development environment your application's code is reloaded on
|
5
|
+
# every request. This slows down response time but is perfect for development
|
6
|
+
# since you don't have to restart the webserver when you make code changes.
|
7
|
+
config.cache_classes = false
|
8
|
+
|
9
|
+
# Log error messages when you accidentally call methods on nil.
|
10
|
+
config.whiny_nils = true
|
11
|
+
|
12
|
+
# Show full error reports and disable caching
|
13
|
+
config.consider_all_requests_local = true
|
14
|
+
config.action_view.debug_rjs = true
|
15
|
+
config.action_controller.perform_caching = false
|
16
|
+
|
17
|
+
# Don't care if the mailer can't send
|
18
|
+
config.action_mailer.raise_delivery_errors = false
|
19
|
+
|
20
|
+
# Print deprecation notices to the Rails logger
|
21
|
+
config.active_support.deprecation = :log
|
22
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
Dummy::Application.configure do
|
2
|
+
# Settings specified here will take precedence over those in config/environment.rb
|
3
|
+
|
4
|
+
# The production environment is meant for finished, "live" apps.
|
5
|
+
# Code is not reloaded between requests
|
6
|
+
config.cache_classes = true
|
7
|
+
|
8
|
+
# Full error reports are disabled and caching is turned on
|
9
|
+
config.consider_all_requests_local = false
|
10
|
+
config.action_controller.perform_caching = true
|
11
|
+
|
12
|
+
# Specifies the header that your server uses for sending files
|
13
|
+
config.action_dispatch.x_sendfile_header = "X-Sendfile"
|
14
|
+
|
15
|
+
# For nginx:
|
16
|
+
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'
|
17
|
+
|
18
|
+
# If you have no front-end server that supports something like X-Sendfile,
|
19
|
+
# just comment this out and Rails will serve the files
|
20
|
+
|
21
|
+
# See everything in the log (default is :info)
|
22
|
+
# config.log_level = :debug
|
23
|
+
|
24
|
+
# Use a different logger for distributed setups
|
25
|
+
# config.logger = SyslogLogger.new
|
26
|
+
|
27
|
+
# Use a different cache store in production
|
28
|
+
# config.cache_store = :mem_cache_store
|
29
|
+
|
30
|
+
# Disable Rails's static asset server
|
31
|
+
# In production, Apache or nginx will already do this
|
32
|
+
config.serve_static_assets = false
|
33
|
+
|
34
|
+
# Enable serving of images, stylesheets, and javascripts from an asset server
|
35
|
+
# config.action_controller.asset_host = "http://assets.example.com"
|
36
|
+
|
37
|
+
# Disable delivery errors, bad email addresses will be ignored
|
38
|
+
# config.action_mailer.raise_delivery_errors = false
|
39
|
+
|
40
|
+
# Enable threaded mode
|
41
|
+
# config.threadsafe!
|
42
|
+
|
43
|
+
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
|
44
|
+
# the I18n.default_locale when a translation can not be found)
|
45
|
+
config.i18n.fallbacks = true
|
46
|
+
|
47
|
+
# Send deprecation notices to registered listeners
|
48
|
+
config.active_support.deprecation = :notify
|
49
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
Dummy::Application.configure do
|
2
|
+
# Settings specified here will take precedence over those in config/application.rb.
|
3
|
+
|
4
|
+
# The test environment is used exclusively to run your application's
|
5
|
+
# test suite. You never need to work with it otherwise. Remember that
|
6
|
+
# your test database is "scratch space" for the test suite and is wiped
|
7
|
+
# and recreated between test runs. Don't rely on the data there!
|
8
|
+
config.cache_classes = true
|
9
|
+
|
10
|
+
# Do not eager load code on boot. This avoids loading your whole application
|
11
|
+
# just for the purpose of running a single test. If you are using a tool that
|
12
|
+
# preloads Rails for running tests, you may have to set it to true.
|
13
|
+
config.eager_load = false
|
14
|
+
|
15
|
+
# Configure static asset server for tests with Cache-Control for performance.
|
16
|
+
config.serve_static_assets = true
|
17
|
+
config.static_cache_control = "public, max-age=3600"
|
18
|
+
|
19
|
+
# Show full error reports and disable caching.
|
20
|
+
config.consider_all_requests_local = true
|
21
|
+
config.action_controller.perform_caching = false
|
22
|
+
|
23
|
+
# Raise exceptions instead of rendering exception templates.
|
24
|
+
config.action_dispatch.show_exceptions = false
|
25
|
+
|
26
|
+
# Disable request forgery protection in test environment.
|
27
|
+
config.action_controller.allow_forgery_protection = false
|
28
|
+
|
29
|
+
# Tell Action Mailer not to deliver emails to the real world.
|
30
|
+
# The :test delivery method accumulates sent emails in the
|
31
|
+
# ActionMailer::Base.deliveries array.
|
32
|
+
config.action_mailer.delivery_method = :test
|
33
|
+
|
34
|
+
# Print deprecation notices to the stderr.
|
35
|
+
config.active_support.deprecation = :stderr
|
36
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
|
4
|
+
# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
|
5
|
+
|
6
|
+
# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
|
7
|
+
# Rails.backtrace_cleaner.remove_silencers!
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# Add new inflection rules using the following format
|
4
|
+
# (all these examples are active by default):
|
5
|
+
# ActiveSupport::Inflector.inflections do |inflect|
|
6
|
+
# inflect.plural /^(ox)$/i, '\1en'
|
7
|
+
# inflect.singular /^(ox)en/i, '\1'
|
8
|
+
# inflect.irregular 'person', 'people'
|
9
|
+
# inflect.uncountable %w( fish sheep )
|
10
|
+
# end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# Your secret key is used for verifying the integrity of signed cookies.
|
4
|
+
# If you change this key, all old signed cookies will become invalid!
|
5
|
+
|
6
|
+
# Make sure the secret is at least 30 characters and all random,
|
7
|
+
# no regular words or you'll be exposed to dictionary attacks.
|
8
|
+
# You can use `rake secret` to generate a secure secret key.
|
9
|
+
|
10
|
+
# Make sure your secret_key_base is kept private
|
11
|
+
# if you're sharing your code publicly.
|
12
|
+
Dummy::Application.config.secret_key_base = 'dcf4f83546f3f99b9aa881c3f7d78085a17b3e79155515da37ecd2b5265b2a7ceb3208a82fb9d7cf2feb494d89010baf8b67db330b6213d9c45c1124920194df'
|
@@ -0,0 +1,8 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
Dummy::Application.config.session_store :cookie_store, :key => '_rails_root_session'
|
4
|
+
|
5
|
+
# Use the database for sessions instead of the cookie-based default,
|
6
|
+
# which shouldn't be used to store highly confidential information
|
7
|
+
# (create the session table with "rake db:sessions:create")
|
8
|
+
# Dummy::Application.config.session_store :active_record_store
|
@@ -0,0 +1,7 @@
|
|
1
|
+
# This file should contain all the record creation needed to seed the database with its default values.
|
2
|
+
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
|
3
|
+
#
|
4
|
+
# Examples:
|
5
|
+
#
|
6
|
+
# cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }])
|
7
|
+
# Mayor.create(:name => 'Daley', :city => cities.first)
|
@@ -0,0 +1,6 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
|
3
|
+
|
4
|
+
APP_PATH = File.expand_path('../../config/application', __FILE__)
|
5
|
+
require File.expand_path('../../config/boot', __FILE__)
|
6
|
+
require 'rails/commands'
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/rails_spec_helper")
|
2
|
+
|
3
|
+
describe Erector::Rails::FormBuilder do
|
4
|
+
describe ".parent_builder_class" do
|
5
|
+
it "defaults to ActionView::Base.default_form_builder" do
|
6
|
+
Erector::Rails::FormBuilder.parent_builder_class.should == ActionView::Base.default_form_builder
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
describe ".wrapping" do
|
11
|
+
it "returns self when passed nil" do
|
12
|
+
Erector::Rails::FormBuilder.wrapping(nil).should == Erector::Rails::FormBuilder
|
13
|
+
end
|
14
|
+
|
15
|
+
it "returns a FormBuilder subclass with the specified parent_builder_class" do
|
16
|
+
my_form_builder = Class.new(ActionView::Base.default_form_builder)
|
17
|
+
Erector::Rails::FormBuilder.wrapping(my_form_builder).parent_builder_class.should == my_form_builder
|
18
|
+
Erector::Rails::FormBuilder.parent_builder_class.should == ActionView::Base.default_form_builder
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,236 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/rails_spec_helper")
|
2
|
+
|
3
|
+
describe Erector::Rails do
|
4
|
+
before do
|
5
|
+
@controller = ActionController::Base.new
|
6
|
+
@controller.request = ActionController::TestRequest.new
|
7
|
+
|
8
|
+
@view = ActionView::Base.new
|
9
|
+
@view.controller = @controller
|
10
|
+
|
11
|
+
def @view.protect_against_forgery?
|
12
|
+
false
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_render(&block)
|
17
|
+
Erector::Rails.render(Erector.inline(&block), @controller.view_context)
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "#link_to" do
|
21
|
+
it "renders a link" do
|
22
|
+
test_render do
|
23
|
+
link_to 'Test', '/foo'
|
24
|
+
end.should == %{<a href="/foo">Test</a>}
|
25
|
+
end
|
26
|
+
|
27
|
+
it "supports blocks" do
|
28
|
+
test_render do
|
29
|
+
link_to '/foo' do
|
30
|
+
strong "Test"
|
31
|
+
end
|
32
|
+
end.should == %{<a href="/foo"><strong>Test</strong></a>}
|
33
|
+
end
|
34
|
+
|
35
|
+
it "escapes input" do
|
36
|
+
test_render do
|
37
|
+
link_to 'This&that', '/foo?this=1&that=1'
|
38
|
+
end.should == %{<a href="/foo?this=1&that=1">This&that</a>}
|
39
|
+
end
|
40
|
+
|
41
|
+
it "isn't double rendered when 'text link_to' is used by mistake" do
|
42
|
+
test_render do
|
43
|
+
text link_to('Test', '/foo')
|
44
|
+
end.should == %{<a href="/foo">Test</a>}
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe "a regular helper" do
|
49
|
+
it "can be called directly" do
|
50
|
+
test_render do
|
51
|
+
text truncate("foo")
|
52
|
+
end.should == "foo"
|
53
|
+
end
|
54
|
+
|
55
|
+
it "can be called via capture" do
|
56
|
+
test_render do
|
57
|
+
text capture { text truncate("foo") }
|
58
|
+
end.should == "foo"
|
59
|
+
end
|
60
|
+
|
61
|
+
it "can be called via sub-widget" do
|
62
|
+
test_render do
|
63
|
+
widget Erector.inline { text truncate("foo") }
|
64
|
+
end.should == "foo"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe "a named route helper" do
|
69
|
+
before do
|
70
|
+
Rails.application.routes.draw do
|
71
|
+
root :to => "rails_helpers_spec#index"
|
72
|
+
end
|
73
|
+
@app_controller = ApplicationController.new
|
74
|
+
@app_controller.request = ActionController::TestRequest.new
|
75
|
+
def app_render(&block)
|
76
|
+
Erector::Rails.render(Erector.inline(&block), @app_controller.view_context)
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
it "can be called directly" do
|
82
|
+
app_render do
|
83
|
+
text root_path
|
84
|
+
end.should == "/"
|
85
|
+
end
|
86
|
+
|
87
|
+
it "can be called via parent" do
|
88
|
+
app_render do
|
89
|
+
text parent.root_path
|
90
|
+
end.should == "/"
|
91
|
+
end
|
92
|
+
|
93
|
+
it "respects default_url_options defined by the controller" do
|
94
|
+
def @app_controller.default_url_options(options = nil)
|
95
|
+
{ :host => "www.override.com" }
|
96
|
+
end
|
97
|
+
|
98
|
+
app_render do
|
99
|
+
text root_url
|
100
|
+
end.should == "http://www.override.com/"
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
describe "#auto_discovery_link_tag" do
|
105
|
+
it "renders tag" do
|
106
|
+
test_render do
|
107
|
+
auto_discovery_link_tag(:rss, "rails")
|
108
|
+
end.should == %{<link href="rails" rel="alternate" title="RSS" type="application/rss+xml" />}
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
describe "#javascript_include_tag" do
|
113
|
+
it "renders tag" do
|
114
|
+
test_render do
|
115
|
+
javascript_include_tag("rails")
|
116
|
+
end.should =~ %r{<script src="/javascripts/rails.js(?:\?\d+)?"></script>}
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
describe "#stylesheet_link_tag" do
|
121
|
+
it "renders tag" do
|
122
|
+
test_render do
|
123
|
+
stylesheet_link_tag("rails")
|
124
|
+
end.should == %{<link href="/stylesheets/rails.css" media="screen" rel="stylesheet" />}
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
describe "#favicon_link_tag" do
|
129
|
+
it "renders tag" do
|
130
|
+
test_render do
|
131
|
+
favicon_link_tag("rails.ico")
|
132
|
+
end.should == %{<link href="/images/rails.ico" rel="shortcut icon" type="image/vnd.microsoft.icon" />}
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
describe "#image_tag" do
|
137
|
+
it "renders tag" do
|
138
|
+
test_render do
|
139
|
+
image_tag("/foo")
|
140
|
+
end.should == %{<img alt="Foo" src="/foo" />}
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
describe "#javascript_tag" do
|
145
|
+
it "renders tag" do
|
146
|
+
test_render do
|
147
|
+
javascript_tag "alert('All is good')"
|
148
|
+
end.should == %{<script>\n//<![CDATA[\nalert('All is good')\n//]]>\n</script>}
|
149
|
+
end
|
150
|
+
|
151
|
+
it "supports block syntax" do
|
152
|
+
test_render do
|
153
|
+
javascript_tag do
|
154
|
+
text! "alert('All is good')"
|
155
|
+
end
|
156
|
+
end.should == %{<script>\n//<![CDATA[\nalert('All is good')\n//]]>\n</script>}
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
if defined?(ActionView::Helpers::ScriptaculousHelper)
|
161
|
+
[:sortable_element,
|
162
|
+
:draggable_element,
|
163
|
+
:drop_receiving_element].each do |helper|
|
164
|
+
describe "##{helper}" do
|
165
|
+
it "renders helper js" do
|
166
|
+
test_render do
|
167
|
+
send(helper, "rails", :url => "/foo")
|
168
|
+
end.should =~ %r{<script type="text/javascript">.*</script>}m
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
describe "#render" do
|
175
|
+
it "renders text" do
|
176
|
+
test_render do
|
177
|
+
render :text => "Test"
|
178
|
+
end.should == "Test"
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
describe "#form_tag" do
|
183
|
+
it "works without a block" do
|
184
|
+
test_render do
|
185
|
+
form_tag("/posts")
|
186
|
+
end.should == %{<form accept-charset="UTF-8" action="/posts" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓" /></div>}
|
187
|
+
end
|
188
|
+
|
189
|
+
it "can be mixed with erector and rails helpers" do
|
190
|
+
test_render do
|
191
|
+
form_tag("/posts") do
|
192
|
+
div { submit_tag 'Save' }
|
193
|
+
end
|
194
|
+
end.should == %{<form accept-charset="UTF-8" action="/posts" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓" /></div><div><input name="commit" type="submit" value="Save" /></div></form>}
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
describe "#form_for" do
|
199
|
+
it "produces expected output" do
|
200
|
+
test_render do
|
201
|
+
form_for(:something, :url => "/test") do |form|
|
202
|
+
form.label :my_input, "My input"
|
203
|
+
form.text_field :my_input
|
204
|
+
end
|
205
|
+
end.should == %{<form accept-charset="UTF-8" action="/test" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓" /></div><label for="something_my_input">My input</label><input id="something_my_input" name="something[my_input]" type="text" /></form>}
|
206
|
+
end
|
207
|
+
|
208
|
+
it "doesn't double render if 'text form.label' is used by mistake" do
|
209
|
+
test_render do
|
210
|
+
form_for(:something, :url => "/test") do |form|
|
211
|
+
text form.label(:my_input, "My input")
|
212
|
+
end
|
213
|
+
end.should == %{<form accept-charset="UTF-8" action="/test" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓" /></div><label for="something_my_input">My input</label></form>}
|
214
|
+
end
|
215
|
+
|
216
|
+
it "can be called from a nested widget" do
|
217
|
+
test_render do
|
218
|
+
widget Erector.inline { form_for(:something, :url => "/test") { |form| form.text_field :my_input } }
|
219
|
+
end.should =~ /^<form/
|
220
|
+
end
|
221
|
+
|
222
|
+
it "uses the specified builder" do
|
223
|
+
builder = Class.new(ActionView::Base.default_form_builder) do
|
224
|
+
def foo
|
225
|
+
"foo"
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
229
|
+
test_render do
|
230
|
+
form_for(:something, :url => "/test", :builder => builder) do |form|
|
231
|
+
text form.foo
|
232
|
+
end
|
233
|
+
end.should =~ /foo/
|
234
|
+
end
|
235
|
+
end
|
236
|
+
end
|