Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge remote-tracking branch 'upstream/master'

Conflicts:
	padrino-helpers/test/test_tag_helpers.rb
  • Loading branch information...
commit d2de420153b4fd4fb5618058b24e3b9132b07b5d 2 parents 21312fe + a35faf0
@agios agios authored
Showing with 137 additions and 64 deletions.
  1. +1 −1  .travis.yml
  2. +2 −3 Gemfile
  3. +2 −2 Rakefile
  4. +7 −3 padrino-admin/lib/padrino-admin/generators/admin_app.rb
  5. +7 −0 padrino-admin/lib/padrino-admin/generators/orm.rb
  6. +2 −2 padrino-admin/lib/padrino-admin/generators/templates/app/controllers/{sessions.rb → sessions.rb.tt}
  7. +1 −1  padrino-admin/lib/padrino-admin/generators/templates/erb/app/layouts/application.erb.tt
  8. +1 −1  padrino-admin/lib/padrino-admin/generators/templates/haml/app/layouts/application.haml.tt
  9. +1 −1  padrino-admin/lib/padrino-admin/generators/templates/slim/app/layouts/application.slim.tt
  10. +1 −1  padrino-admin/lib/padrino-admin/helpers/view_helpers.rb
  11. +18 −0 padrino-admin/test/generators/test_admin_app_generator.rb
  12. +3 −0  padrino-cache/lib/padrino-cache/helpers/fragment.rb
  13. +1 −1  padrino-core/lib/padrino-core/cli/base.rb
  14. +1 −0  padrino-core/lib/padrino-core/loader.rb
  15. +1 −1  padrino-core/lib/padrino-core/support_lite.rb
  16. +1 −1  padrino-core/lib/padrino-core/version.rb
  17. +14 −0 padrino-gen/lib/padrino-gen/generators/actions.rb
  18. +1 −1  padrino-gen/lib/padrino-gen/generators/cli.rb
  19. +3 −0  padrino-gen/lib/padrino-gen/generators/components/orms/activerecord.rb
  20. +2 −1  padrino-gen/lib/padrino-gen/generators/components/orms/mini_record.rb
  21. +1 −1  padrino-gen/lib/padrino-gen/generators/templates/static
  22. +19 −25 padrino-gen/lib/padrino-gen/padrino-tasks/activerecord.rb
  23. +3 −3 padrino-gen/lib/padrino-gen/padrino-tasks/mongoid.rb
  24. +11 −1 padrino-gen/test/test_model_generator.rb
  25. +2 −2 padrino-helpers/lib/padrino-helpers/format_helpers.rb
  26. +9 −9 padrino-helpers/lib/padrino-helpers/tag_helpers.rb
  27. +5 −0 padrino-helpers/test/test_asset_tag_helpers.rb
  28. +2 −2 padrino-helpers/test/test_format_helpers.rb
  29. +15 −1 padrino-helpers/test/test_tag_helpers.rb
View
2  .travis.yml
@@ -1,4 +1,4 @@
-# before_install: sudo apt-get install redis-server libmemcache-dev memcached
+lang: ruby
install:
- gem update --system
- bundle update
View
5 Gemfile
@@ -31,9 +31,8 @@ group :development do
gem "builder", ">= 2.1.2"
gem "bcrypt-ruby", :require => "bcrypt"
platforms :mri_18 do
- gem "ruby-debug"
- gem "rcov", "~> 0.9.8"
- gem "ruby-prof", ">= 0.9.1"
+ # gem "rcov", "~> 0.9.8"
+ # gem "ruby-prof", ">= 0.9.1"
gem "system_timer", ">= 1.0"
end
platforms :jruby do
View
4 Rakefile
@@ -57,10 +57,10 @@ desc "Bumps the version number based on given version"
task :bump, [:version] do |t, args|
raise "Please specify version=x.x.x !" unless args.version
version_path = File.dirname(__FILE__) + '/padrino-core/lib/padrino-core/version.rb'
- version_text = File.read(version_path).sub(/VERSION = '[\d\.]+'/, "VERSION = '#{args.version}'")
+ version_text = File.read(version_path).sub(/VERSION = '[a-z0-9\.]+'/, "VERSION = '#{args.version}'")
say "Updating Padrino to version #{args.version}"
File.open(version_path, 'w') { |f| f.write version_text }
- sh 'git commit -a -m "Bumped version to %s"' % args.version
+ sh 'git commit -am "Bumped version to %s"' % args.version
end
desc "Executes a fresh install removing all padrino version and then reinstall all gems"
View
10 padrino-admin/lib/padrino-admin/generators/admin_app.rb
@@ -59,6 +59,7 @@ def create_admin
directory "templates/assets", destination_root("public", "admin")
template "templates/app.rb.tt", destination_root("admin/app.rb")
append_file destination_root("config/apps.rb"), "\nPadrino.mount(\"Admin\").to(\"/admin\")"
+ insert_middleware 'ActiveRecord::ConnectionAdapters::ConnectionManagement', 'admin' if [:mini_record, :activerecord].include?(orm)
account_params = [
options[:admin_model].underscore, "name:string", "surname:string", "email:string", "crypted_password:string", "role:string",
@@ -103,10 +104,13 @@ def create_admin
template "templates/#{ext}/app/layouts/application.#{ext}.tt", destination_root("admin/views/layouts/application.#{ext}")
template "templates/#{ext}/app/sessions/new.#{ext}.tt", destination_root("admin/views/sessions/new.#{ext}")
- add_project_module :accounts
+ model_singular = options[:admin_model].underscore
+ model_plural = model_singular.pluralize
+
+ add_project_module model_plural
require_dependencies('bcrypt-ruby', :require => 'bcrypt')
- gsub_file destination_root("admin/views/accounts/_form.#{ext}"), "f.text_field :role, :class => :text_field", "f.select :role, :options => access_control.roles"
- gsub_file destination_root("admin/controllers/accounts.rb"), "if account.destroy", "if account != current_account && account.destroy"
+ gsub_file destination_root("admin/views/#{model_plural}/_form.#{ext}"), "f.text_field :role, :class => :text_field", "f.select :role, :options => access_control.roles"
+ gsub_file destination_root("admin/controllers/#{model_plural}.rb"), "if #{model_singular}.destroy", "if #{model_singular} != current_account && #{model_singular}.destroy"
return if self.behavior == :revoke
instructions = []
View
7 padrino-admin/lib/padrino-admin/generators/orm.rb
@@ -25,6 +25,13 @@ def initialize(name, orm, columns=nil, column_fields=nil)
raise OrmError, "Model '#{klass_name}' could not be found!" if @columns.nil? && @klass.nil?
end
+ def activerecord?
+ case orm
+ when :activerecord, :mini_record then true
+ else false
+ end
+ end
+
def field_type(type)
type = :string if type.nil? # couchrest-Hack to avoid the next line to fail
type = type.to_s.demodulize.downcase.to_sym unless type.is_a?(Symbol)
View
4 ...ors/templates/app/controllers/sessions.rb → .../templates/app/controllers/sessions.rb.tt
@@ -5,11 +5,11 @@
end
post :create do
- if account = Account.authenticate(params[:email], params[:password])
+ if account = <%= options[:admin_model] %>.authenticate(params[:email], params[:password])
set_current_account(account)
redirect url(:base, :index)
elsif Padrino.env == :development && params[:bypass]
- account = Account.first
+ account = <%= options[:admin_model] %>.first
set_current_account(account)
redirect url(:base, :index)
else
View
2  padrino-admin/lib/padrino-admin/generators/templates/erb/app/layouts/application.erb.tt
@@ -11,7 +11,7 @@
<h1><%%= link_to "Padrino Admin", url(:base_index) %></h1>
<div id="user-navigation">
<ul class="wat-cf">
- <li><%%= link_to pat(:profile), url(:accounts, :edit, :id => current_account.id) %></li>
+ <li><%%= link_to pat(:profile), url(:<%= options[:admin_model].underscore.pluralize %>, :edit, :id => current_account.id) %></li>
<li><%%= button_to pat(:logout), url(:sessions, :destroy), :method => :delete, :class => :button_to %></li>
</ul>
</div>
View
2  padrino-admin/lib/padrino-admin/generators/templates/haml/app/layouts/application.haml.tt
@@ -10,7 +10,7 @@
%h1=link_to "Padrino Admin", url(:base_index)
#user-navigation
%ul.wat-cf
- %li=link_to pat(:profile), url(:accounts, :edit, :id => current_account.id)
+ %li=link_to pat(:profile), url(:<%= options[:admin_model].underscore.pluralize %>, :edit, :id => current_account.id)
%li=button_to pat(:logout), url(:sessions, :destroy), :method => :delete, :class => :button_to
#main-navigation
%ul.wat-cf
View
2  padrino-admin/lib/padrino-admin/generators/templates/slim/app/layouts/application.slim.tt
@@ -11,7 +11,7 @@ html lang="en" xmlns="http://www.w3.org/1999/xhtml"
h1==link_to "Padrino Admin", url(:base_index)
#user-navigation
ul.wat-cf
- li==link_to pat(:profile), url(:accounts, :edit, :id => current_account.id)
+ li==link_to pat(:profile), url(:<%= options[:admin_model].underscore.pluralize %>, :edit, :id => current_account.id)
li==button_to pat(:logout), url(:sessions, :destroy), :method => :delete, :class => :button_to
#main-navigation
ul.wat-cf
View
2  padrino-admin/lib/padrino-admin/helpers/view_helpers.rb
@@ -41,7 +41,7 @@ def padrino_admin_translate(word, default=nil)
# @return [String] The translated attribute name for the current locale.
#
# @example
- # # => t("models.account.email", :default => "Email")
+ # # => t("models.account.attributes.email", :default => "Email")
# mat(:account, :email)
#
def model_attribute_translate(model, attribute)
View
18 padrino-admin/test/generators/test_admin_app_generator.rb
@@ -158,6 +158,24 @@ def teardown
assert_match_in_file 'button_to pat(:logout)', "#{@apptmp}/sample_project/admin/views/layouts/application.haml"
end
+ should 'not add activerecord middleware for #datamapper' do
+ capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '-d=datamapper', '-e=haml') }
+ capture_io { generate(:admin_app,"-a=/admin", "--root=#{@apptmp}/sample_project") }
+ assert_no_match_in_file(/ use ActiveRecord::ConnectionAdapters::ConnectionManagemen/m, "#{@apptmp}/sample_project/admin/app.rb")
+ end
+
+ should 'add activerecord middleware for #activerecord' do
+ capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '-d=activerecord', '-e=haml') }
+ capture_io { generate(:admin_app,"-a=/admin", "--root=#{@apptmp}/sample_project") }
+ assert_match_in_file(/ use ActiveRecord::ConnectionAdapters::ConnectionManagemen/m, "#{@apptmp}/sample_project/admin/app.rb")
+ end
+
+ should 'add activerecord middleware for #mini_record' do
+ capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '-d=mini_record', '-e=haml') }
+ capture_io { generate(:admin_app,"-a=/admin", "--root=#{@apptmp}/sample_project") }
+ assert_match_in_file(/ use ActiveRecord::ConnectionAdapters::ConnectionManagemen/m, "#{@apptmp}/sample_project/admin/app.rb")
+ end
+
should 'not conflict with existing seeds file' do
capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '-d=activerecord', '-e=erb') }
View
3  padrino-cache/lib/padrino-cache/helpers/fragment.rb
@@ -60,6 +60,9 @@ def cache(key, opts = nil, &block)
logger.debug "SET Fragment", began_at, key.to_s if defined?(logger)
concat_content(value)
end
+ else
+ value = capture_html(&block)
+ concat_content(value)
end
end
end # Fragment
View
2  padrino-core/lib/padrino-core/cli/base.rb
@@ -60,10 +60,10 @@ def console
prepare :console
require File.expand_path("../../version", __FILE__)
ARGV.clear
- puts "=> Loading #{options.environment} console (Padrino v.#{Padrino.version})"
require 'irb'
require "irb/completion"
require File.expand_path('config/boot.rb')
+ puts "=> Loading #{Padrino.env} console (Padrino v.#{Padrino.version})"
require File.expand_path('../console', __FILE__)
IRB.start
end
View
1  padrino-core/lib/padrino-core/loader.rb
@@ -94,6 +94,7 @@ def clear!
# Method for reloading required applications and their files.
#
def reload!
+ return unless Padrino::Reloader.changed?
Padrino.before_load.each(&:call) # Run before hooks
Padrino::Reloader.reload! # detects the modified files
Padrino.after_load.each(&:call) # Run after hooks
View
2  padrino-core/lib/padrino-core/support_lite.rb
@@ -11,7 +11,7 @@
require 'active_support/inflector/inflections' # pluralize
require 'active_support/inflections' # load default inflections
require 'yaml' unless defined?(YAML) # load yaml for i18n
-require 'Win32/Console/ANSI' if RUBY_PLATFORM =~ /win32/ # ruby color suppor for win
+require 'win32console' if RUBY_PLATFORM =~ /(win|m)32/ # ruby color support for win
##
# This is an adapted version of active_support/core_ext/string/inflections.rb
View
2  padrino-core/lib/padrino-core/version.rb
@@ -6,7 +6,7 @@
#
module Padrino
# The version constant for the current version of Padrino.
- VERSION = '0.10.6.c' unless defined?(Padrino::VERSION)
+ VERSION = '0.10.6.e' unless defined?(Padrino::VERSION)
#
# The current Padrino version.
View
14 padrino-gen/lib/padrino-gen/generators/actions.rb
@@ -293,6 +293,20 @@ def insert_hook(include_text, where)
inject_into_file('config/boot.rb', " #{include_text}\n", :after => "Padrino.#{where} do\n")
end
+ # Inserts a middlware inside app.rb
+ #
+ # @param [String] include_text
+ # Text to include into hooks in boot.rb
+ #
+ # @example
+ # insert_middleware(ActiveRecord::ConnectionAdapters::ConnectionManagement)
+ #
+ # @api public
+ def insert_middleware(include_text, app=nil)
+ name = app || (options[:name].present? ? @app_name.downcase : 'app')
+ inject_into_file("#{name}/app.rb", " use #{include_text}\n", :after => "Padrino::Application\n")
+ end
+
# Registers and Creates Initializer.
#
# @param [Symbol] name
View
2  padrino-gen/lib/padrino-gen/generators/cli.rb
@@ -29,7 +29,7 @@ def load_boot
# If we are outside app we need to load support_lite
require 'padrino-core/support_lite' unless defined?(SupportLite)
end
- rescue Exception => e
+ rescue StandardError => e
puts "=> Problem loading #{boot}"
puts ["=> #{e.message}", *e.backtrace].join("\n ")
ensure
View
3  padrino-gen/lib/padrino-gen/generators/components/orms/activerecord.rb
@@ -118,6 +118,7 @@ def setup_orm
require_dependencies 'sqlite3'
end
require_dependencies 'activerecord', :require => 'active_record'
+ insert_middleware 'ActiveRecord::ConnectionAdapters::ConnectionManagement'
create_file("config/database.rb", ar)
end
@@ -134,6 +135,7 @@ def create_model_file(name, options={})
create_file(model_path, model_contents,:skip => true)
end
+
AR_MIGRATION = (<<-MIGRATION) unless defined?(AR_MIGRATION)
class !FILECLASS! < ActiveRecord::Migration
def self.up
@@ -149,6 +151,7 @@ def self.down
AR_MODEL_UP_MG = (<<-MIGRATION).gsub(/^/, ' ') unless defined?(AR_MODEL_UP_MG)
create_table :!TABLE! do |t|
!FIELDS!
+ t.timestamps
end
MIGRATION
View
3  padrino-gen/lib/padrino-gen/generators/components/orms/mini_record.rb
@@ -102,7 +102,8 @@ def setup_orm
end
require_dependencies 'mini_record'
create_file('config/database.rb', ar)
- insert_hook('ActiveRecord::Base.descendants.each(&:auto_upgrade!)', :after_load)
+ insert_hook('ActiveRecord::Base.auto_upgrade!', :after_load)
+ insert_middleware 'ActiveRecord::ConnectionAdapters::ConnectionManagement'
end
MR_MODEL = (<<-MODEL) unless defined?(MR_MODEL)
2  padrino-gen/lib/padrino-gen/generators/templates/static
@@ -1 +1 @@
-Subproject commit ece972daaa4e5be7751040be749dfedff3551722
+Subproject commit 8e0262ef67634d982a0c8e13d97c973a59736ea4
View
44 padrino-gen/lib/padrino-gen/padrino-tasks/activerecord.rb
@@ -42,8 +42,9 @@ def create_database(config)
Dir.mkdir File.dirname(config[:database]) unless File.exist?(File.dirname(config[:database]))
ActiveRecord::Base.establish_connection(config)
ActiveRecord::Base.connection
- rescue
- $stderr.puts $!, *($!.backtrace)
+ rescue StandardError => e
+ $stderr.puts *(e.backtrace)
+ $stderr.puts e.inspect
$stderr.puts "Couldn't create database for #{config.inspect}"
end
end
@@ -62,23 +63,11 @@ def create_database(config)
ActiveRecord::Base.establish_connection(config.merge(:database => nil))
ActiveRecord::Base.connection.create_database(config[:database], creation_options)
ActiveRecord::Base.establish_connection(config)
- rescue Mysql::Error => sqlerr
- if sqlerr.errno == Mysql::Error::ER_ACCESS_DENIED_ERROR
- print "#{sqlerr.error}. \nPlease provide the root password for your mysql installation\n>"
- root_password = $stdin.gets.strip
- grant_statement = "GRANT ALL PRIVILEGES ON #{config[:database]}.* " \
- "TO '#{config[:username]}'@'localhost' " \
- "IDENTIFIED BY '#{config[:password]}' WITH GRANT OPTION;"
- ActiveRecord::Base.establish_connection(config.merge(
- :database => nil, :username => 'root', :password => root_password))
- ActiveRecord::Base.connection.create_database(config[:database], creation_options)
- ActiveRecord::Base.connection.execute grant_statement
- ActiveRecord::Base.establish_connection(config)
- else
- $stderr.puts sqlerr.error
- $stderr.puts "Couldn't create database for #{config.inspect}, charset: #{config[:charset] || @charset}, collation: #{config[:collation] || @collation}"
- $stderr.puts "(if you set the charset manually, make sure you have a matching collation)" if config[:charset]
- end
+ rescue StandardError => e
+ $stderr.puts *(e.backtrace)
+ $stderr.puts e.inspect
+ $stderr.puts "Couldn't create database for #{config.inspect}, charset: #{config[:charset] || @charset}, collation: #{config[:collation] || @collation}"
+ $stderr.puts "(if you set the charset manually, make sure you have a matching collation)" if config[:charset]
end
when 'postgresql'
@encoding = config[:encoding] || ENV['CHARSET'] || 'utf8'
@@ -86,8 +75,9 @@ def create_database(config)
ActiveRecord::Base.establish_connection(config.merge(:database => 'postgres', :schema_search_path => 'public'))
ActiveRecord::Base.connection.create_database(config[:database], config.merge(:encoding => @encoding))
ActiveRecord::Base.establish_connection(config)
- rescue
- $stderr.puts $!, *($!.backtrace)
+ rescue StandardError => e
+ $stderr.puts *(e.backtrace)
+ $stderr.puts e.inspect
$stderr.puts "Couldn't create database for #{config.inspect}"
end
end
@@ -105,8 +95,10 @@ def create_database(config)
begin
# Only connect to local databases
local_database?(config) { drop_database(config) }
- rescue Exception => e
- puts "Couldn't drop #{config[:database]} : #{e.inspect}"
+ rescue StandardError => e
+ $stderr.puts *(e.backtrace)
+ $stderr.puts e.inspect
+ $stderr.puts "Couldn't drop #{config[:database]}"
end
end
end
@@ -117,8 +109,10 @@ def create_database(config)
config = ActiveRecord::Base.configurations[Padrino.env || :development]
begin
drop_database(config)
- rescue Exception => e
- puts "Couldn't drop #{config[:database]} : #{e.inspect}"
+ rescue StandardError => e
+ $stderr.puts *(e.backtrace)
+ $stderr.puts e.inspect
+ $stderr.puts "Couldn't drop #{config[:database]}"
end
end
View
6 padrino-gen/lib/padrino-gen/padrino-tasks/mongoid.rb
@@ -9,7 +9,7 @@
# Helper to retrieve a list of models.
def get_mongoid_models
documents = []
- Dir['{app,}/models/*.rb'].sort.each do |file|
+ Dir['{app,.}/models/*.rb'].sort.each do |file|
model_path = file[0..-4].split('/')[2..-1]
begin
@@ -85,7 +85,7 @@ def collection_names
begin
collection.rename("#{collection_name}_old")
- rescue Exception => e
+ rescue StandardError => e
puts "Unable to rename database #{collection_name} to #{collection_name}_old"
puts "reason: #{e.message}\n\n"
end
@@ -95,7 +95,7 @@ def collection_names
begin
new_collection.rename(collection_name)
- rescue Exception => e
+ rescue StandardError => e
puts "Unable to rename database #{new_collection.name} to #{collection_name}"
puts "reason: #{e.message}\n\n"
end
View
12 padrino-gen/test/test_model_generator.rb
@@ -80,6 +80,11 @@ def teardown
# ACTIVERECORD
context "model generator using activerecord" do
+ should "add activerecord middleware" do
+ capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-d=activerecord') }
+ assert_match_in_file(/ use ActiveRecord::ConnectionAdapters::ConnectionManagemen/m, "#{@apptmp}/sample_project/app/app.rb")
+ end
+
should "generate model file" do
capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=activerecord') }
capture_io { generate(:model, 'user', "-r=#{@apptmp}/sample_project") }
@@ -122,11 +127,16 @@ def teardown
should "generate hooks for auto upgrade" do
capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=mini_record') }
assert_match_in_file(
- "Padrino.after_load do\n ActiveRecord::Base.descendants.each(&:auto_upgrade!)",
+ "Padrino.after_load do\n ActiveRecord::Base.auto_upgrade!",
"#{@apptmp}/sample_project/config/boot.rb"
)
end
+ should "add activerecord middleware" do
+ capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-d=activerecord') }
+ assert_match_in_file(/ use ActiveRecord::ConnectionAdapters::ConnectionManagemen/m, "#{@apptmp}/sample_project/app/app.rb")
+ end
+
should "generate model file" do
capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=mini_record') }
capture_io { generate(:model, 'user', 'name:string', 'surname:string', 'age:integer', "-r=#{@apptmp}/sample_project") }
View
4 padrino-helpers/lib/padrino-helpers/format_helpers.rb
@@ -81,11 +81,11 @@ def strip_tags(html)
# @api public
def simple_format(text, options={})
t = options.delete(:tag) || :p
- start_tag = tag(t, options)
+ start_tag = tag(t, options, true)
text = text.to_s.dup
text.gsub!(/\r\n?/, "\n") # \r\n and \r -> \n
text.gsub!(/\n\n+/, "</#{t}>\n\n#{start_tag}") # 2+ newline -> paragraph
- text.gsub!(/([^\n]\n)(?=[^\n])/, '\1<br>') # 1 newline -> br
+ text.gsub!(/([^\n]\n)(?=[^\n])/, '\1<br />') # 1 newline -> br
text.insert 0, start_tag
text << "</#{t}>"
end
View
18 padrino-helpers/lib/padrino-helpers/tag_helpers.rb
@@ -138,16 +138,16 @@ def content_tag(name, content = nil, options = nil, &block)
#
# @example
# input_tag :text, :name => 'handle'
- # # => <input type="test" name="handle">
+ # # => <input type="test" name="handle" />
#
# input_tag :password, :name => 'password', :size => 20
- # # => <input type="password" name="password" size="20">
+ # # => <input type="password" name="password" size="20" />
#
# input_tag :text, :name => 'username', :required => true, :autofocus => true
- # # => <input type="text" name="username" required autofocus>
+ # # => <input type="text" name="username" required autofocus />
#
# input_tag :number, :name => 'credit_card', :autocomplete => :off
- # # => <input type="number" autocomplete="off">
+ # # => <input type="number" autocomplete="off" />
#
# @api semipublic
def input_tag(type, options = {})
@@ -172,17 +172,17 @@ def input_tag(type, options = {})
# # => <hr class="dotted">
#
# tag :input, :name => 'username', :type => :text
- # # => <input name="username" type="text">
+ # # => <input name="username" type="text" />
#
# tag :img, :src => 'images/pony.jpg', :alt => 'My Little Pony'
- # # => <img src="images/pony.jpg" alt="My Little Pony">
+ # # => <img src="images/pony.jpg" alt="My Little Pony" />
#
# tag :img, :src => 'sinatra.jpg, :data => { :nsfw => false, :geo => [34.087, -118.407] }
- # # => <img src="sinatra.jpg" data-nsfw="false" data-geo="34.087 -118.407">
+ # # => <img src="sinatra.jpg" data-nsfw="false" data-geo="34.087 -118.407" />
#
# @api public
- def tag(name, options = nil)
- "<#{name}#{tag_options(options) if options}>"
+ def tag(name, options = nil, open = false)
+ "<#{name}#{tag_options(options) if options}#{open ? '>' : ' />'}"
end
private
View
5 padrino-helpers/test/test_asset_tag_helpers.rb
@@ -176,6 +176,11 @@ def flash
self.class.expects(:asset_stamp).returns(false)
assert_has_tag('img', :src => "/absolute/pic.gif") { image_tag('/absolute/pic.gif') }
end
+
+ should "have xhtml convention tag" do
+ self.class.expects(:asset_stamp).returns(false)
+ assert_equal image_tag('/absolute/pic.gif'), '<img src="/absolute/pic.gif" />'
+ end
end
context 'for #stylesheet_link_tag method' do
View
4 padrino-helpers/test/test_format_helpers.rb
@@ -15,7 +15,7 @@ def setup
context 'for #simple_format method' do
should "format simple text into html format" do
actual_text = simple_format("Here is some basic text...\n...with a line break.")
- assert_equal "<p>Here is some basic text...\n<br>...with a line break.</p>", actual_text
+ assert_equal "<p>Here is some basic text...\n<br />...with a line break.</p>", actual_text
end
should "format more text into html format" do
@@ -31,7 +31,7 @@ def setup
context 'wrapped in a custom tag' do
should "format simple text into html format" do
actual_text = simple_format("Here is some basic text...\n...with a line break.", :tag => :div)
- assert_equal "<div>Here is some basic text...\n<br>...with a line break.</div>", actual_text
+ assert_equal "<div>Here is some basic text...\n<br />...with a line break.</div>", actual_text
end
should "format more text into html format" do
View
16 padrino-helpers/test/test_tag_helpers.rb
@@ -7,6 +7,15 @@ def app
end
context 'for #tag method' do
+ should("support tags with no content no attributes") do
+ assert_has_tag(:br) { tag(:br) }
+ end
+
+ should("support tags with no content with attributes") do
+ actual_html = tag(:br, :style => 'clear:both', :class => 'yellow')
+ assert_has_tag(:br, :class => 'yellow', :style=>'clear:both') { actual_html }
+ end
+
should "support selected attribute by using 'selected' if true" do
actual_html = tag(:option, :selected => true)
assert_has_tag('option', :selected => 'selected') { actual_html }
@@ -21,10 +30,15 @@ def app
actual_html = tag(:div, {:dojo => {:type => 'dijit.form.TextBox', :props => 'readOnly: true'}})
assert_has_tag(:div, 'data-dojo-type' => 'dijit.form.TextBox', 'data-dojo-props' => 'readOnly: true') { actual_html }
end
+
+ should "support open tags" do
+ actual_html = tag(:p, { :class => 'demo' }, true)
+ assert_equal "<p class=\"demo\">", actual_html
+ end
should "escape html" do
actual_html = tag(:br, :class => 'Example "bar"')
- assert_equal "<br class=\"Example &quot;bar&quot;\">", actual_html
+ assert_equal "<br class=\"Example &quot;bar&quot;\" />", actual_html
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.