Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Rails 3 compatibility.

  • Loading branch information...
commit 061dd3069d275bfad972ce443d5d79ef8ede465a 1 parent 2736e00
@josevalim josevalim authored
View
0  lib/locale/en.yml → lib/locales/en.yml
File renamed without changes
View
14 lib/show_for.rb
@@ -1,4 +1,3 @@
-require 'active_support/i18n'
require 'show_for/helper'
module ShowFor
@@ -47,10 +46,17 @@ def self.setup
yield self
end
- class Railtie < ::Rails::Engine
- engine_name :show_for
+ class Railtie < ::Rails::Railtie
+ railtie_name :show_for
- paths.config.locales = "lib/locale"
+ # Add load paths straight to I18n, so engines and application can overwrite it.
+ require 'active_support/i18n'
+ I18n.load_path << File.expand_path('../locales/en.yml', __FILE__)
+
+ # Remove this conditional on next Rails beta
+ if config.generators.respond_to?(:templates)
+ config.generators.templates << File.expand_path('../templates', __FILE__)
+ end
initializer "show_for.initialize_values" do |app|
config.show_for.each do |setting, value|
View
9 lib/show_for/builder.rb
@@ -23,8 +23,8 @@ def object_name #:nodoc:
end
def wrap_label_and_content(name, value, options, &block) #:nodoc:
- wrap_with(:wrapper, label(name, options, false) + ShowFor.separator.to_s +
- content(value, options, false, &block), options, true, value.is_a?(Proc))
+ wrap_with(:wrapper, label(name, options, false) + ShowFor.separator.to_s.html_safe +
+ content(value, options, false, &block), options, value.is_a?(Proc))
end
# Set "#{object_name}_#{attribute_name}" as in the wrapper tag.
@@ -37,7 +37,7 @@ def apply_default_options!(name, options) #:nodoc:
# Gets the default tag set in ShowFor module and apply (if defined)
# around the given content. It also check for html_options in @options
# hash related to the current type.
- def wrap_with(type, content, options, safe=false, concat=false) #:nodoc:
+ def wrap_with(type, content, options, concat=false) #:nodoc:
tag = options.delete(:"#{type}_tag") || ShowFor.send(:"#{type}_tag")
html = if tag
@@ -48,8 +48,7 @@ def wrap_with(type, content, options, safe=false, concat=false) #:nodoc:
content
end
- html.html_safe! if safe && html.respond_to?(:html_safe!)
- concat ? @template.concat(html) : html
+ concat ? @template.safe_concat(html) : html.html_safe
end
# Returns true if the block is supposed to iterate through a collection,
View
6 lib/templates/erb/scaffold/show.html.erb
@@ -1,7 +1,7 @@
-<%% show_for @<%= singular_name %> do |u| %>
+<%% show_for @<%= singular_name %> do |o| %>
<% attributes.each do |attribute| -%>
- <%%= u.<%= attribute.reference? ? :association : :attribute %> :<%= attribute.name %> %>
-<% end %>
+ <%%= o.<%= attribute.reference? ? :association : :attribute %> :<%= attribute.name %> %>
+<% end -%>
<%% end %>
<%%= link_to 'Edit', edit_<%= singular_name %>_path(@<%= singular_name %>) %> |
View
56 show_for.gemspec
@@ -0,0 +1,56 @@
+# Generated by jeweler
+# DO NOT EDIT THIS FILE DIRECTLY
+# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
+# -*- encoding: utf-8 -*-
+
+Gem::Specification.new do |s|
+ s.name = %q{show_for}
+ s.version = "0.2.0"
+
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
+ s.authors = ["Jos\303\251 Valim"]
+ s.date = %q{2010-02-06}
+ s.description = %q{Wrap your objects with a helper to easily show them}
+ s.email = %q{contact@plataformatec.com.br}
+ s.extra_rdoc_files = [
+ "README.rdoc"
+ ]
+ s.files = [
+ "lib/generators/show_for_install/USAGE",
+ "lib/generators/show_for_install/show_for_install_generator.rb",
+ "lib/generators/show_for_install/templates/show_for.rb",
+ "lib/locales/en.yml",
+ "lib/show_for.rb",
+ "lib/show_for/association.rb",
+ "lib/show_for/attribute.rb",
+ "lib/show_for/builder.rb",
+ "lib/show_for/content.rb",
+ "lib/show_for/helper.rb",
+ "lib/show_for/label.rb",
+ "lib/show_for/version.rb",
+ "lib/templates/erb/scaffold/show.html.erb"
+ ]
+ s.homepage = %q{http://github.com/plataformatec/show_for}
+ s.rdoc_options = ["--charset=UTF-8"]
+ s.require_paths = ["lib"]
+ s.rubygems_version = %q{1.3.5}
+ s.summary = %q{Wrap your objects with a helper to easily show them}
+ s.test_files = [
+ "test/builder_test.rb",
+ "test/helper_test.rb",
+ "test/support/misc_helpers.rb",
+ "test/support/models.rb",
+ "test/test_helper.rb"
+ ]
+
+ if s.respond_to? :specification_version then
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
+ s.specification_version = 3
+
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
+ else
+ end
+ else
+ end
+end
+
View
6 test/support/models.rb
@@ -1,12 +1,16 @@
require 'ostruct'
class Company < Struct.new(:id, :name)
+ extend ActiveModel::Naming
+
def alternate_name
"Alternate #{self.name}"
end
end
class Tag < Struct.new(:id, :name)
+ extend ActiveModel::Naming
+
def self.all(options={})
(1..3).map{ |i| Tag.new(i, "Tag #{i}") }
end
@@ -17,6 +21,8 @@ def alternate_name
end
class User < OpenStruct
+ extend ActiveModel::Naming
+
# Get rid of deprecation warnings
undef_method :id
View
4 test/test_helper.rb
@@ -1,9 +1,13 @@
require 'rubygems'
require 'test/unit'
+require 'active_model'
require 'action_controller'
require 'action_view/test_case'
+require 'rails/railtie'
+require 'rails/backtrace_cleaner'
+
begin
require 'ruby-debug'
rescue LoadError
Please sign in to comment.
Something went wrong with that request. Please try again.