view_models 2.0.1 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.bundle/config +2 -0
- data/.gitignore +8 -0
- data/.rspec +2 -0
- data/.rvmrc +1 -0
- data/.travis.yml +19 -0
- data/.yardoc/checksums +13 -0
- data/.yardoc/object_types +0 -0
- data/.yardoc/objects/root.dat +0 -0
- data/.yardoc/proxy_types +0 -0
- data/Appraisals +15 -0
- data/CHANGELOG +31 -0
- data/Gemfile +13 -0
- data/Gemfile.lock +174 -0
- data/MIT-LICENSE +20 -0
- data/README.textile +199 -0
- data/Rakefile +24 -0
- data/doc/ModulesInRenderHierarchy.html +186 -0
- data/doc/ModulesInRenderHierarchy/ClassMethods.html +188 -0
- data/doc/ViewModels.html +202 -0
- data/doc/ViewModels/Base.html +1342 -0
- data/doc/ViewModels/ContextExtractor.html +406 -0
- data/doc/ViewModels/Extensions.html +128 -0
- data/doc/ViewModels/Extensions/ModelReader.html +255 -0
- data/doc/ViewModels/Extensions/ModelReader/FilteredDelegationInstaller.html +908 -0
- data/doc/ViewModels/Extensions/ModelReader/Options.html +551 -0
- data/doc/ViewModels/Extensions/View.html +303 -0
- data/doc/ViewModels/Helpers.html +129 -0
- data/doc/ViewModels/Helpers/Mapping.html +562 -0
- data/doc/ViewModels/Helpers/Mapping/Collection.html +844 -0
- data/doc/ViewModels/Helpers/View.html +287 -0
- data/doc/ViewModels/PathStore.html +745 -0
- data/doc/ViewModels/RenderOptions.html +126 -0
- data/doc/ViewModels/RenderOptions/Base.html +1187 -0
- data/doc/ViewModels/RenderOptions/Partial.html +231 -0
- data/doc/ViewModels/RenderOptions/Template.html +231 -0
- data/doc/ViewModels/View.html +414 -0
- data/doc/ViewModelsGenerator.html +410 -0
- data/doc/_index.html +317 -0
- data/doc/class_list.html +53 -0
- data/doc/css/common.css +1 -0
- data/doc/css/full_list.css +57 -0
- data/doc/css/style.css +328 -0
- data/doc/file.README.html +113 -0
- data/doc/file_list.html +55 -0
- data/doc/frames.html +28 -0
- data/doc/index.html +113 -0
- data/doc/js/app.js +214 -0
- data/doc/js/full_list.js +173 -0
- data/doc/js/jquery.js +4 -0
- data/doc/method_list.html +628 -0
- data/doc/top-level-namespace.html +114 -0
- data/feature_support/testapp/app/controllers/heroes_controller.rb +6 -0
- data/feature_support/testapp/app/controllers/users_controller.rb +6 -0
- data/feature_support/testapp/app/helpers/application_helper.rb +8 -0
- data/feature_support/testapp/app/models/hero.rb +8 -0
- data/feature_support/testapp/app/models/user.rb +3 -0
- data/feature_support/testapp/app/view_models/hero.rb +8 -0
- data/feature_support/testapp/app/view_models/test.rb +8 -0
- data/feature_support/testapp/app/view_models/user.rb +14 -0
- data/feature_support/testapp/app/views/heroes/show.html.slim +6 -0
- data/feature_support/testapp/app/views/users/_box.html.slim +8 -0
- data/feature_support/testapp/app/views/users/show.html.slim +6 -0
- data/feature_support/testapp/config/application.rb +64 -0
- data/feature_support/testapp/config/cucumber.yml +8 -0
- data/feature_support/testapp/config/database.yml +28 -0
- data/feature_support/testapp/config/environments/cucumber.rb +11 -0
- data/feature_support/testapp/config/environments/test.rb +27 -0
- data/feature_support/testapp/config/routes.rb +4 -0
- data/feature_support/testapp/db/migrate/1_create_users.rb +13 -0
- data/feature_support/testapp/features/inheritance.feature +16 -0
- data/feature_support/testapp/features/step_definitions/testapp_steps.rb +16 -0
- data/feature_support/testapp/features/support/env.rb +13 -0
- data/feature_support/testapp/features/users.feature +15 -0
- data/feature_support/testapp/lib/tasks/cucumber.rake +31 -0
- data/feature_support/testapp/spec/factories/heroes.rb +7 -0
- data/feature_support/testapp/spec/factories/users.rb +7 -0
- data/features/rails_integration.feature +21 -0
- data/features/step_definitions/rails_steps.rb +112 -0
- data/features/support/env.rb +6 -0
- data/gemfiles/3.0.Gemfile +13 -0
- data/gemfiles/3.1.Gemfile +15 -0
- data/gemfiles/3.2.gemfile +15 -0
- data/lib/rails/generators/view_models/USAGE +6 -0
- data/lib/rails/generators/view_models/templates/views/_collection.html.erb +6 -0
- data/lib/{rails2/generators/view_models/templates/views/view_models/collection → rails/generators/view_models/templates/views}/_collection.html.haml +1 -2
- data/lib/rails/generators/view_models/templates/views/_collection.html.slim +6 -0
- data/lib/{rails2/generators/view_models/templates/views/_empty.html.haml → rails/generators/view_models/templates/views/_empty.html.erb} +0 -0
- data/lib/rails/generators/view_models/templates/views/_empty.html.haml +0 -0
- data/lib/rails/generators/view_models/templates/views/_empty.html.slim +0 -0
- data/lib/rails/generators/view_models/templates/views/_list.html.erb +6 -0
- data/lib/rails/generators/view_models/templates/views/_list.html.haml +4 -0
- data/lib/rails/generators/view_models/templates/views/_list.html.slim +5 -0
- data/lib/rails/generators/view_models/templates/views/_pagination.html.erb +18 -0
- data/lib/{rails2/generators/view_models/templates/views/view_models/collection → rails/generators/view_models/templates/views}/_pagination.html.haml +2 -2
- data/lib/rails/generators/view_models/templates/views/_pagination.html.slim +12 -0
- data/lib/rails/generators/view_models/templates/views/_table.html.erb +10 -0
- data/lib/{rails2/generators/view_models/templates/views/view_models/collection → rails/generators/view_models/templates/views}/_table.html.haml +0 -0
- data/lib/rails/generators/view_models/templates/views/_table.html.slim +5 -0
- data/lib/rails/generators/view_models/view_models_generator.rb +57 -0
- data/lib/view_models.rb +15 -5
- data/lib/{shared/lib/view_models → view_models}/base.rb +148 -37
- data/lib/{shared/lib/view_models → view_models}/context_extractor.rb +6 -2
- data/lib/{shared/lib/view_models → view_models}/extensions/model_reader.rb +27 -13
- data/lib/{rails2/lib → view_models}/extensions/view.rb +6 -1
- data/lib/view_models/helpers/collection.rb +113 -0
- data/lib/{shared/lib/view_models → view_models}/helpers/mapping.rb +12 -15
- data/lib/{rails2/lib → view_models}/helpers/view.rb +5 -1
- data/lib/{shared/lib/view_models → view_models}/path_store.rb +6 -1
- data/lib/{shared/lib/view_models → view_models}/render_options.rb +19 -4
- data/lib/view_models/version.rb +5 -0
- data/lib/{rails2/lib/view_models → view_models}/view.rb +7 -6
- data/spec/{rails2/lib → lib}/view_models/base_spec.rb +38 -5
- data/spec/{rails2/lib → lib/view_models}/extensions/model_reader_spec.rb +4 -4
- data/spec/{shared/lib → lib/view_models}/helpers/collection_spec.rb +21 -1
- data/spec/{shared/lib → lib/view_models}/helpers/mapping_spec.rb +6 -5
- data/spec/{rails2/lib → lib/view_models}/helpers/view_spec.rb +1 -1
- data/spec/lib/view_models/view_spec.rb +42 -0
- data/spec/spec_helper.rb +32 -0
- data/spec/spec_helper_extensions.rb +13 -0
- data/view_models.gemspec +36 -0
- metadata +411 -142
- data/lib/init.rb +0 -1
- data/lib/padrino/README.textile +0 -3
- data/lib/padrino/init.rb +0 -10
- data/lib/padrino/lib/helpers/collection.rb +0 -27
- data/lib/padrino/lib/padrino/view_models.rb +0 -19
- data/lib/padrino/lib/view_models/base.rb +0 -65
- data/lib/rails2/README.textile +0 -3
- data/lib/rails2/TODO.textile +0 -5
- data/lib/rails2/generators/view_models/USAGE +0 -6
- data/lib/rails2/generators/view_models/templates/README +0 -1
- data/lib/rails2/generators/view_models/templates/spec/view_model_spec.rb +0 -7
- data/lib/rails2/generators/view_models/templates/view_models/view_model.rb +0 -5
- data/lib/rails2/generators/view_models/templates/views/view_models/collection/_collection.html.erb +0 -1
- data/lib/rails2/generators/view_models/templates/views/view_models/collection/_collection.text.erb +0 -6
- data/lib/rails2/generators/view_models/templates/views/view_models/collection/_list.html.erb +0 -1
- data/lib/rails2/generators/view_models/templates/views/view_models/collection/_list.text.erb +0 -6
- data/lib/rails2/generators/view_models/templates/views/view_models/collection/_pagination.text.erb +0 -3
- data/lib/rails2/generators/view_models/templates/views/view_models/collection/_table.text.erb +0 -10
- data/lib/rails2/generators/view_models/view_models_generator.rb +0 -47
- data/lib/rails2/init.rb +0 -18
- data/lib/rails2/lib/experimental/README.textile +0 -32
- data/lib/rails2/lib/experimental/modules_in_render_hierarchy.rb +0 -21
- data/lib/rails2/lib/helpers/collection.rb +0 -27
- data/lib/rails2/lib/view_models.rb +0 -1
- data/lib/rails2/lib/view_models/base.rb +0 -99
- data/lib/shared/README.textile +0 -3
- data/lib/shared/init.rb +0 -11
- data/lib/shared/lib/view_models.rb +0 -4
- data/lib/shared/lib/view_models/extensions/active_record.rb +0 -27
- data/lib/shared/lib/view_models/helpers/collection.rb +0 -110
- data/spec/padrino/integration/integration_spec.rb +0 -287
- data/spec/padrino/lib/helpers/collection_spec.rb +0 -30
- data/spec/rails2/integration/integration_spec.rb +0 -279
- data/spec/rails2/lib/extensions/active_record_spec.rb +0 -31
- data/spec/rails2/lib/helpers/collection_spec.rb +0 -30
- data/spec/rails2/lib/view_models/view_spec.rb +0 -12
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'cucumber/rake/task'
|
2
|
+
|
3
|
+
namespace :cucumber do
|
4
|
+
Cucumber::Rake::Task.new({:ok => 'db:test:prepare'}, 'Run features that should pass') do |t|
|
5
|
+
t.fork = true # You may get faster startup if you set this to false
|
6
|
+
t.profile = 'default'
|
7
|
+
end
|
8
|
+
|
9
|
+
Cucumber::Rake::Task.new({:wip => 'db:test:prepare'}, 'Run features that are being worked on') do |t|
|
10
|
+
t.fork = true # You may get faster startup if you set this to false
|
11
|
+
t.profile = 'wip'
|
12
|
+
end
|
13
|
+
|
14
|
+
Cucumber::Rake::Task.new({:rerun => 'db:test:prepare'}, 'Record failing features and run only them if any exist') do |t|
|
15
|
+
t.fork = true # You may get faster startup if you set this to false
|
16
|
+
t.profile = 'rerun'
|
17
|
+
end
|
18
|
+
|
19
|
+
desc 'Run all features'
|
20
|
+
task :all => [:ok, :wip]
|
21
|
+
|
22
|
+
task :statsetup do
|
23
|
+
require 'rails/code_statistics'
|
24
|
+
::STATS_DIRECTORIES << %w(Cucumber\ features features) if File.exist?('features')
|
25
|
+
::CodeStatistics::TEST_TYPES << "Cucumber features" if File.exist?('features')
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
task :cucumber => 'cucumber:all'
|
30
|
+
|
31
|
+
task :default => :cucumber
|
@@ -0,0 +1,21 @@
|
|
1
|
+
Feature: integrate with Rails
|
2
|
+
|
3
|
+
Background:
|
4
|
+
When I generate a new rails application
|
5
|
+
And I copy the generic app files from the support folder into the generated app
|
6
|
+
And I configure the application to use the view_models gem from this project
|
7
|
+
And I configure the application to use the following gems
|
8
|
+
| Name | Version | Require |
|
9
|
+
| factory_girl_rails | ~> 1.7.0 | |
|
10
|
+
| factory_girl | ~> 2.6.4 | |
|
11
|
+
| cucumber-rails | ~> 1.3.0 | false |
|
12
|
+
| rspec-rails | ~> 2.11.0 | |
|
13
|
+
| capybara | ~> 1.1.2 | |
|
14
|
+
| slim-rails | ~> 1.0.3 | |
|
15
|
+
And I successfully run `bundle install --local`
|
16
|
+
And I successfully run `bundle exec rake db:migrate`
|
17
|
+
|
18
|
+
Scenario:
|
19
|
+
When I successfully run `bundle exec rake cucumber`
|
20
|
+
Then the output should contain "2 scenarios (2 passed)"
|
21
|
+
And the output should contain "17 steps (17 passed)"
|
@@ -0,0 +1,112 @@
|
|
1
|
+
PROJECT_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..', '..')).freeze
|
2
|
+
APP_NAME = 'testapp'.freeze
|
3
|
+
|
4
|
+
BUNDLE_ENV_VARS = %w(RUBYOPT BUNDLE_PATH BUNDLE_BIN_PATH BUNDLE_GEMFILE)
|
5
|
+
ORIGINAL_BUNDLE_VARS = Hash[ENV.select{ |key,value| BUNDLE_ENV_VARS.include?(key) }]
|
6
|
+
|
7
|
+
Before do
|
8
|
+
ENV['BUNDLE_GEMFILE'] = File.join(Dir.pwd, ENV['BUNDLE_GEMFILE']) unless ENV['BUNDLE_GEMFILE'].start_with?(Dir.pwd)
|
9
|
+
end
|
10
|
+
|
11
|
+
After do
|
12
|
+
ORIGINAL_BUNDLE_VARS.each_pair do |key, value|
|
13
|
+
ENV[key] = value
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
When 'I generate a new rails application' do
|
18
|
+
steps %{
|
19
|
+
When I run `rails new #{APP_NAME}`
|
20
|
+
And I cd to "#{APP_NAME}"
|
21
|
+
And I comment out the gem "turn" from the Gemfile
|
22
|
+
And I comment out the gem "coffee-rails" from the Gemfile
|
23
|
+
And I comment out the gem "uglifier" from the Gemfile
|
24
|
+
And I reset Bundler environment variables
|
25
|
+
And I set the "BUNDLE_GEMFILE" environment variable to "Gemfile"
|
26
|
+
And I successfully run `bundle install --local`
|
27
|
+
}
|
28
|
+
if RUBY_VERSION >= "1.9.3"
|
29
|
+
append_to_gemfile %(gem "rake", "~> 0.9.3.beta.1")
|
30
|
+
step %(I successfully run `bundle update rake`)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
When /^I copy the generic app files from the support folder into the generated app$/ do
|
35
|
+
FileUtils.cp_r File.join(PROJECT_ROOT, 'feature_support/testapp'), File.join(PROJECT_ROOT, 'tmp/aruba'), :remove_destination => true
|
36
|
+
end
|
37
|
+
|
38
|
+
When /^I configure the application to use the (.+) gem from this project$/ do |name|
|
39
|
+
append_to_gemfile "gem '#{name}', :path => '#{PROJECT_ROOT}'"
|
40
|
+
end
|
41
|
+
|
42
|
+
When /^I configure the application to use "([^\"]+)" from this project in test and development$/ do |name|
|
43
|
+
append_to_gemfile <<-GEMFILE
|
44
|
+
group :test, :development do
|
45
|
+
gem '#{name}', :path => '#{PROJECT_ROOT}'
|
46
|
+
end
|
47
|
+
GEMFILE
|
48
|
+
end
|
49
|
+
|
50
|
+
When 'I run the rspec generator' do
|
51
|
+
steps %{
|
52
|
+
When I successfully run `rails generate rspec:install`
|
53
|
+
}
|
54
|
+
end
|
55
|
+
|
56
|
+
When 'I configure the application to use the following gems' do |table|
|
57
|
+
table.hashes.each do |hash|
|
58
|
+
if hash[:Require] && hash[:Require].strip.size > 0
|
59
|
+
append_to_gemfile "gem '#{hash[:Name]}', '#{hash[:Version]}', :require => #{hash[:Require]}\n"
|
60
|
+
else
|
61
|
+
append_to_gemfile "gem '#{hash[:Name]}', '#{hash[:Version]}'\n"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
When /^I set the "([^"]*)" environment variable to "([^"]*)"$/ do |key, value|
|
68
|
+
ENV[key] = value
|
69
|
+
end
|
70
|
+
|
71
|
+
When 'I append gems from Appraisal Gemfile' do
|
72
|
+
File.read(ENV['BUNDLE_GEMFILE']).split("\n").each do |line|
|
73
|
+
if line =~ /^gem "(?!rails|appraisal)/
|
74
|
+
append_to_gemfile line.strip
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
When 'I reset Bundler environment variables' do
|
80
|
+
BUNDLE_ENV_VARS.each do |key|
|
81
|
+
ENV[key] = nil
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
When /^I comment out the gem "([^"]*)" from the Gemfile$/ do |gemname|
|
86
|
+
comment_out_gem_in_gemfile(gemname)
|
87
|
+
end
|
88
|
+
|
89
|
+
module FileHelpers
|
90
|
+
def append_to(path, contents)
|
91
|
+
in_current_dir do
|
92
|
+
File.open(path, "a") do |file|
|
93
|
+
file.puts
|
94
|
+
file.puts contents
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def append_to_gemfile(contents)
|
100
|
+
append_to('Gemfile', contents)
|
101
|
+
end
|
102
|
+
|
103
|
+
def comment_out_gem_in_gemfile(gemname)
|
104
|
+
in_current_dir do
|
105
|
+
gemfile = File.read("Gemfile")
|
106
|
+
gemfile.sub!(/^(\s*)(gem\s*['"]#{gemname})/, "\\1# \\2")
|
107
|
+
File.open("Gemfile", 'w'){ |file| file.write(gemfile) }
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
World(FileHelpers)
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source :rubygems
|
4
|
+
|
5
|
+
gem "sqlite3", :platform=>:ruby
|
6
|
+
gem "activerecord-jdbc-adapter", :platform=>:jruby
|
7
|
+
gem "activerecord-jdbcsqlite3-adapter", :platform=>:jruby
|
8
|
+
gem "jdbc-sqlite3", :platform=>:jruby
|
9
|
+
gem "jruby-openssl", :platform=>:jruby
|
10
|
+
gem "therubyrhino", :platform=>:jruby
|
11
|
+
gem "rails", "~> 3.0.0"
|
12
|
+
|
13
|
+
gemspec :path=>"../"
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source :rubygems
|
4
|
+
|
5
|
+
gem "sqlite3", :platform=>:ruby
|
6
|
+
gem "activerecord-jdbc-adapter", :platform=>:jruby
|
7
|
+
gem "activerecord-jdbcsqlite3-adapter", :platform=>:jruby
|
8
|
+
gem "jdbc-sqlite3", :platform=>:jruby
|
9
|
+
gem "jruby-openssl", :platform=>:jruby
|
10
|
+
gem "therubyrhino", :platform=>:jruby
|
11
|
+
gem "rails", "~> 3.1.0"
|
12
|
+
gem "jquery-rails"
|
13
|
+
gem "sass-rails"
|
14
|
+
|
15
|
+
gemspec :path=>"../"
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source :rubygems
|
4
|
+
|
5
|
+
gem "sqlite3", :platform=>:ruby
|
6
|
+
gem "activerecord-jdbc-adapter", :platform=>:jruby
|
7
|
+
gem "activerecord-jdbcsqlite3-adapter", :platform=>:jruby
|
8
|
+
gem "jdbc-sqlite3", :platform=>:jruby
|
9
|
+
gem "jruby-openssl", :platform=>:jruby
|
10
|
+
gem "therubyrhino", :platform=>:jruby
|
11
|
+
gem "rails", "~> 3.2.0"
|
12
|
+
gem "jquery-rails"
|
13
|
+
gem "sass-rails"
|
14
|
+
|
15
|
+
gemspec :path=>"../"
|
@@ -2,7 +2,6 @@
|
|
2
2
|
- collection.each do |item|
|
3
3
|
- view_model = view_model_for item
|
4
4
|
%li
|
5
|
-
|
6
|
-
= view_model.render_as template_name, options
|
5
|
+
= view_model.render_as template_name
|
7
6
|
= separator unless item == collection.entries.last
|
8
7
|
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,18 @@
|
|
1
|
+
<%- if collection.page_count > 1 -%>
|
2
|
+
<p>
|
3
|
+
<%- if collection.previous_page? -%>
|
4
|
+
<%= link_to 'previous', :page => collection.page-1 -%>
|
5
|
+
<%- end -%>
|
6
|
+
<%- 1.upto(collection.page_count) do |page| -%>
|
7
|
+
<%- if page == collection.page -%>
|
8
|
+
<%= page.to_s -%>
|
9
|
+
<%- else -%>
|
10
|
+
<%= link_to page, :page => page -%>
|
11
|
+
<%- end -%>
|
12
|
+
<%- end -%>
|
13
|
+
<%= separator unless collection.last_page? -%>
|
14
|
+
<%- if collection.next_page? -%>
|
15
|
+
<%= link_to 'next', :page => collection.page+1 -%>
|
16
|
+
<%- end -%>
|
17
|
+
</p>
|
18
|
+
<%- end -%>
|
@@ -1,7 +1,7 @@
|
|
1
1
|
- if collection.page_count > 1
|
2
2
|
%p
|
3
3
|
- if collection.previous_page?
|
4
|
-
= link_to '
|
4
|
+
= link_to 'previous', :page => collection.page-1
|
5
5
|
- 1.upto(collection.page_count) do |page|
|
6
6
|
- if page == collection.page
|
7
7
|
= page.to_s
|
@@ -9,4 +9,4 @@
|
|
9
9
|
= link_to page, :page => page
|
10
10
|
= separator unless collection.last_page?
|
11
11
|
- if collection.next_page?
|
12
|
-
= link_to '
|
12
|
+
= link_to 'next', :page => collection.page+1
|
@@ -0,0 +1,12 @@
|
|
1
|
+
- if collection.page_count > 1
|
2
|
+
p
|
3
|
+
- if collection.previous_page?
|
4
|
+
= link_to 'previous', :page => collection.page-1
|
5
|
+
- 1.upto(collection.page_count) do |page|
|
6
|
+
- if page == collection.page
|
7
|
+
= page.to_s
|
8
|
+
- else
|
9
|
+
= link_to page, :page => page
|
10
|
+
= separator unless collection.last_page?
|
11
|
+
- if collection.next_page?
|
12
|
+
= link_to 'next', :page => collection.page+1
|
File without changes
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# A generator for view models
|
2
|
+
#
|
3
|
+
class ViewModelsGenerator < Rails::Generators::Base
|
4
|
+
source_root File.expand_path('../templates', __FILE__)
|
5
|
+
argument :class_name, :type => :string
|
6
|
+
class_option :views, :type => :string, :default => 'erb', :desc => "Render view files in erb, haml or slim (use the language name as the argument)"
|
7
|
+
|
8
|
+
# Generate the view models given
|
9
|
+
#
|
10
|
+
def generate_view_models
|
11
|
+
file_name = class_name.underscore
|
12
|
+
|
13
|
+
create_model class_name, file_name
|
14
|
+
|
15
|
+
create_views file_name if options.views.present?
|
16
|
+
end
|
17
|
+
|
18
|
+
# Create views corresponding to view models
|
19
|
+
#
|
20
|
+
def create_views file_name
|
21
|
+
%W(list_item main_item).each do |view|
|
22
|
+
create_file "app/views/#{file_name.pluralize}/_#{view}.html.#{options.views.downcase}", File.read(File.join(File.expand_path('../templates', __FILE__), "/views/_empty.html.#{options.views.downcase}"))
|
23
|
+
end
|
24
|
+
|
25
|
+
# Copy collection views.
|
26
|
+
#
|
27
|
+
%W(collection list pagination table).each do |view|
|
28
|
+
create_file "app/views/#{file_name.pluralize}/_#{view}.html.#{options.views.downcase}", File.read(File.join(File.expand_path('../templates', __FILE__), "/views/_#{view}.html.#{options.views.downcase}"))
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# Create the view model files for the view models given
|
33
|
+
#
|
34
|
+
def create_model class_name, file_name
|
35
|
+
# ViewModels
|
36
|
+
#
|
37
|
+
create_file "app/view_models/#{file_name}.rb", <<-FILE
|
38
|
+
class ViewModels::#{class_name} < ViewModels::Project
|
39
|
+
|
40
|
+
# model_reader :icon, :filter_through => [:h]
|
41
|
+
|
42
|
+
end
|
43
|
+
FILE
|
44
|
+
|
45
|
+
# Specs
|
46
|
+
#
|
47
|
+
|
48
|
+
create_file "spec/view_models/#{file_name}_spec.rb", <<-FILE
|
49
|
+
require 'spec_helper'
|
50
|
+
|
51
|
+
describe ViewModels::#{class_name} do
|
52
|
+
|
53
|
+
end
|
54
|
+
FILE
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
data/lib/view_models.rb
CHANGED
@@ -1,5 +1,15 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
require 'view_models/extensions/model_reader'
|
2
|
+
|
3
|
+
require 'view_models/helpers/mapping'
|
4
|
+
require 'view_models/helpers/collection'
|
5
|
+
require 'view_models/helpers/view'
|
6
|
+
|
7
|
+
require 'view_models/path_store'
|
8
|
+
require 'view_models/render_options'
|
9
|
+
require 'view_models/context_extractor'
|
10
|
+
require 'view_models/base'
|
11
|
+
|
12
|
+
require 'view_models/view'
|
13
|
+
|
14
|
+
ActionController::Base.send :include, ViewModels::Helpers::Mapping
|
15
|
+
ActionView::Base.send :include, ViewModels::Helpers::Mapping
|