Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add haml template

closes #12
  • Loading branch information...
commit d08ffb16a79a402378ce7b28a9806726ed77903a 1 parent e76283d
@nashby nashby authored
View
1  CHANGELOG.rdoc
@@ -1,6 +1,7 @@
== master
* enhancements
+ * Add Haml template. (by github.com/nashby) Closes #12.
* Add `blank_html` tanslation. (by github.com/nashby)
* Add `show_for_class` configuration option. (by github.com/nashby)
View
1  Gemfile
@@ -4,4 +4,5 @@ gemspec
gem "rake"
gem "rdoc"
+gem 'railties'
gem "ruby-debug", :platform => :mri_18
View
11 Gemfile.lock
@@ -37,8 +37,17 @@ GEM
rack (1.4.1)
rack-cache (1.2)
rack (>= 0.4)
+ rack-ssl (1.3.2)
+ rack
rack-test (0.6.1)
rack (>= 1.0)
+ railties (3.2.3)
+ actionpack (= 3.2.3)
+ activesupport (= 3.2.3)
+ rack-ssl (~> 1.3.2)
+ rake (>= 0.8.7)
+ rdoc (~> 3.4)
+ thor (~> 0.14.6)
rake (0.9.2.2)
rbx-require-relative (0.0.9)
rdoc (3.12)
@@ -52,12 +61,14 @@ GEM
hike (~> 1.2)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
+ thor (0.14.6)
tilt (1.3.3)
PLATFORMS
ruby
DEPENDENCIES
+ railties
rake
rdoc
ruby-debug
View
1  gemfiles/Gemfile-rails.3.0.x
@@ -5,3 +5,4 @@ gem "rdoc"
gem 'show_for', :path => '..'
gem 'activemodel', '~> 3.0.0'
gem 'actionpack', '~> 3.0.0'
+gem 'railties', '~> 3.0.0'
View
1  gemfiles/Gemfile-rails.3.1.x
@@ -5,3 +5,4 @@ gem "rdoc"
gem 'show_for', :path => '..'
gem 'activemodel', '~> 3.1.0'
gem 'actionpack', '~> 3.1.0'
+gem 'railties', '~> 3.1.0'
View
6 lib/generators/show_for/install_generator.rb
@@ -2,6 +2,7 @@ module ShowFor
module Generators
class InstallGenerator < Rails::Generators::Base
desc "Copy ShowFor installation files"
+ class_option :template_engine, :desc => 'Template engine to be invoked (erb or haml or slim).'
source_root File.expand_path('../templates', __FILE__)
def copy_initializers
@@ -13,8 +14,9 @@ def copy_locale_file
end
def copy_generator_template
- copy_file 'show.html.erb', 'lib/templates/erb/scaffold/show.html.erb'
+ engine = options[:template_engine]
+ copy_file "show.html.#{engine}", "lib/templates/#{engine}/scaffold/show.html.#{engine}"
end
end
end
-end
+end
View
8 lib/generators/show_for/templates/show.html.haml
@@ -0,0 +1,8 @@
+= show_for(@<%= singular_name %>) do |s|
+<%- attributes.each do |attribute| -%>
+ = s.<%= attribute.reference? ? :association : :attribute %> :<%= attribute.name %>
+<% end -%>
+
+= link_to 'Edit', edit_<%= singular_name %>_path(@<%= singular_name %>)
+|
+= link_to 'Back', <%= plural_name %>_path
View
26 test/generators/show_for_generator_test.rb
@@ -0,0 +1,26 @@
+require 'test_helper'
+
+class ShowForGeneratorTest < Rails::Generators::TestCase
+ tests ShowFor::Generators::InstallGenerator
+ destination File.expand_path('../../tmp', __FILE__)
+ setup :prepare_destination
+ teardown { rm_rf(destination_root) }
+
+ test 'generates example locale file' do
+ run_generator
+ assert_file 'config/locales/show_for.en.yml'
+ end
+
+ test 'generates the show_for initializer' do
+ run_generator
+ assert_file 'config/initializers/show_for.rb',
+ /config.show_for_tag = :div/
+ end
+
+ %W(erb haml).each do |engine|
+ test "generates the scaffold template when using #{engine}" do
+ run_generator ['-e', engine]
+ assert_file "lib/templates/#{engine}/scaffold/show.html.#{engine}"
+ end
+ end
+end
View
3  test/test_helper.rb
@@ -9,6 +9,9 @@
require 'action_view/template'
require 'action_view/test_case'
+require "rails/generators/test_case"
+require 'generators/show_for/install_generator'
+
$:.unshift File.expand_path("../../lib", __FILE__)
require 'show_for'
Please sign in to comment.
Something went wrong with that request. Please try again.