shoestrap 1.0.0.pre3 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8dd1664ff03eceb5244ebbe95ed3bf3820019621
4
- data.tar.gz: b85a06876965e48d6cd18d01fc3dfafcc20bd886
3
+ metadata.gz: b55de56d065f7ee9e83d2fe37589e882ea9aed96
4
+ data.tar.gz: b071ba2c4aa2b53c3d0fbfbf552b568948d5e939
5
5
  SHA512:
6
- metadata.gz: 6f20b5a995193ed3903de4bcae6b0c591fa08255b87521063d0e05eb7aa7245838e86d36d5b45793d56ecfe6899d342305cd4bceee80f8a227f89f627c3eea8f
7
- data.tar.gz: 8f72be11198fd660455aeb916886d458d2de588ea104a6910bf107ae0617f643621ceab9993ef349509abdea66041053586a3a6d35ab6b030f5c1a969662839c
6
+ metadata.gz: c564e07a2a4f2db6b34fe6776ba2d90591a17a04486b4b1bbb5908947e8f11ccae61253656e95f126536c12a7432a9bba34bf155fd9765d6ab91c2e6d95eddfd
7
+ data.tar.gz: 526244fef52e7144ac7e177d5be3a94e42a8343db8e277514e94c7496b9872ef61dad9a585ad37ff5b5adeea8380199c1af8ace510e486ee114489eb13d32399
@@ -1,5 +1,9 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 1.0.0 - 2013-09-26
4
+
5
+ - Cleaned up cms generator
6
+
3
7
  ## 1.0.0.pre3 - 2013-09-18
4
8
 
5
9
  - Implemented CMS Generator
data/README.md CHANGED
@@ -11,11 +11,7 @@ work. Your mileage may vary!
11
11
  # Features
12
12
 
13
13
  * generate new rails apps with a sc flavored setup
14
- * generate admin backens similar to rails_admin and ative_admin, with
15
- some notable differences:
16
-
17
- TBD: elaborate on differences between rails_admin/active_admin, i.e
18
- why whe built it
14
+ * generate admin backends with view inheritance and inhertied_resources
19
15
 
20
16
  ## Test shoestrap "compliance"
21
17
 
@@ -214,11 +214,6 @@ describe 'application generated with shoestrap new <application_name>' do
214
214
  expect(application_rb_content).to match "g.helper false"
215
215
  end
216
216
 
217
- it 'uses simple_form as form builder' do
218
- expect(application_rb_content).to match(/form_builder :simple_form/)
219
- end
220
-
221
-
222
217
  context 'mailcatcher' do
223
218
  it 'is configured for development environment' do
224
219
  expect(development_rb_content).to match(/config\.action_mailer\.delivery_method = :smtp/)
@@ -2,7 +2,7 @@ require_relative '../../features_helper'
2
2
 
3
3
  describe 'rails generate shoestrap:cms' do
4
4
 
5
- context 'without default cms' do
5
+ context 'without kuhsaft' do
6
6
 
7
7
  options = {kuhsaft: false}
8
8
  let(:cars_controller) { application_file('app/controllers/cms/cars_controller.rb', options) }
@@ -20,8 +20,7 @@ describe 'rails generate shoestrap:cms' do
20
20
  context 'generating a cms resource' do
21
21
  let(:navigation_config_path) { File.join(app_path, 'config/navigation.rb') }
22
22
  let(:navigation_config) { application_file('config/navigation.rb', options) }
23
- let (:gemfile_content) { application_file('Gemfile', options) }
24
-
23
+ let(:gemfile_content) { application_file('Gemfile', options) }
25
24
 
26
25
  before :all do
27
26
  rails 'generate shoestrap:cms car tires:integer model:string', options
@@ -32,37 +31,23 @@ describe 'rails generate shoestrap:cms' do
32
31
  expect(application_file('config/routes.rb', options)).to match(/namespace :cms do/)
33
32
  end
34
33
 
35
- context 'with navigation' do
36
- it 'sets up the cms navigation file' do
37
- expect(File.exists? navigation_config_path).to be_true
38
- end
39
-
40
- it 'contains no example entries' do
41
- expect(navigation_config).not_to match(/^\s*primary\.item :key/)
42
- end
43
- end
44
-
45
34
  it 'sets up controller inheritance for the cms backend' do
46
- expect(application_file('app/controllers/shoestrap/base_controller.rb', options)).to match('InheritedResources::Base')
35
+ expect(application_file('app/controllers/shoestrap/base_controller.rb', options)).to match('ActionController::Base')
36
+ expect(application_file('app/controllers/shoestrap/base_controller.rb', options)).to match('inherit_resources')
47
37
  end
48
38
 
39
+ it 'generates inherited resource views' do
40
+ views = Dir[File.join(app_path, 'app/views/shoestrap/base/*.html.haml')]
41
+ views.map!{|v| v.scan(/^.+app\/views\/shoestrap\/base\/(.*).html.haml/).flatten.first.to_sym }
42
+ expected_action_views = [:edit, :index, :new, :"_form"]
43
+ expect(expected_action_views - views).to be_empty
44
+ end
49
45
  end
50
46
 
51
-
52
- it 'generates a controller with CRUD actions' do
53
- expect(cars_controller).to match(/Shoestrap..BaseController/)
54
- expect(cars_controller).to match('respond_to :html')
55
- expect(cars_controller).to match(/action.+all.+except.+show/)
56
- expect(cars_controller).not_to match(/Cms::Car\./)
57
- expect(cars_controller).not_to match(/params\[:cms_car\]/)
58
- end
59
-
60
- it 'generates inherited CRUD views' do
61
- views = Dir[File.join(app_path, 'app/views/cms/cars/*.html.haml')]
62
- views.map!{|v| v.scan(/^.+app\/views\/cms\/cars\/(.*).html.haml/).flatten.first.to_sym }
63
-
64
- expected_action_views = [:edit, :index, :new, :show]
65
- expect(expected_action_views - views).to be_empty
47
+ context 'generates a CRUD controller' do
48
+ it 'inherits from the shoestrap base controller' do
49
+ expect(cars_controller).to match(/Shoestrap..BaseController/)
50
+ end
66
51
  end
67
52
 
68
53
  it 'generates a model' do
@@ -77,16 +62,6 @@ describe 'rails generate shoestrap:cms' do
77
62
  expect(application_file('config/routes.rb', options)).to match(/resources :cars/)
78
63
  end
79
64
 
80
- it 'generates integration tests for the CRUD actions' do
81
- request_spec = File.join(app_path, 'spec/requests/cms/cms_cars_spec.rb')
82
- expect(File.exists? request_spec).to be_true
83
- end
84
-
85
- it 'adds the generated resource to the cms navigation' do
86
- expect(navigation_config).to match('cms_cars_path')
87
- end
88
-
89
-
90
65
  it 'does not generate routing specs' do
91
66
  routing_spec = File.join(app_path, 'spec/routing/cars_routing_spec.rb')
92
67
  expect(File.exists? routing_spec).to be_false
@@ -118,11 +93,12 @@ describe 'rails generate shoestrap:cms' do
118
93
  end # without default cms
119
94
 
120
95
  context 'with kuhsaft' do
121
-
122
96
  options = {kuhsaft: true}
123
97
  let(:cars_controller) { application_file('app/controllers/cms/cars_controller.rb', options) }
124
- let (:gemfile_content) { application_file('Gemfile', options) }
98
+ let(:gemfile_content) { application_file('Gemfile', options) }
125
99
  let(:app_path){ application_path(options) }
100
+ let(:navigation_config_path) { File.join(app_path, 'config/cms_navigation.rb') }
101
+ let(:navigation_config) { application_file('config/cms_navigation.rb', options) }
126
102
 
127
103
  before :all do
128
104
  generate_test_app_with_shoestrap options
@@ -133,8 +109,10 @@ describe 'rails generate shoestrap:cms' do
133
109
  rails 'generate shoestrap:cms car tires:integer model:string', options
134
110
  end
135
111
 
136
- it 'generates a controller inheriting from kuhsaft AdminController' do
137
- expect(cars_controller).to match('Kuhsaft::Cms::AdminController')
112
+ context 'the shoestrap base controller' do
113
+ it 'inherits from the kuhsaft admin controller' do
114
+ expect(application_file('app/controllers/shoestrap/base_controller.rb', options)).to match('Kuhsaft::Cms::AdminController')
115
+ end
138
116
  end
139
117
 
140
118
  it 'should contain the kuhsaft gem' do
@@ -144,8 +122,14 @@ describe 'rails generate shoestrap:cms' do
144
122
  it 'should have the kuhsaft initializer' do
145
123
  expect(File.exists?(File.join(app_path, 'config/initializers/kuhsaft.rb'))).to be_true
146
124
  end
147
- end
148
125
 
126
+ it 'sets up the cms navigation file' do
127
+ expect(File.exists? navigation_config_path).to be_true
128
+ end
149
129
 
130
+ it 'adds the generated resource to the cms navigation' do
131
+ expect(navigation_config).to match('cms_cars_path')
132
+ end
133
+ end
150
134
  end # with kuhsaft
151
135
  end # rails generate shoestrap:cms
@@ -1,53 +1,95 @@
1
1
  require 'rails/generators'
2
+ require 'fileutils'
2
3
  require_relative '../../shoestrap/shell'
3
4
  require_relative 'base_generator'
4
5
 
5
6
  module Shoestrap
6
7
  class CmsGenerator < BaseGenerator
8
+
9
+ def set_up_shoestrap_cms
10
+ unless shoestrap_cms_already_installed?
11
+ setup_base_controller
12
+ setup_base_views
13
+ setup_navigation
14
+ setup_translation_file
15
+ end
16
+ end
17
+
7
18
  def add_route
8
19
  generate 'resource_route', resource_route_name
9
20
  end
10
21
 
11
22
  def add_navigation_link
12
- link_definition = "\n primary.item #{model_name.to_sym.inspect}, #{model_name.pluralize.inspect}, cms_#{model_name.pluralize}_path\n"
13
- inject_into_file 'config/navigation.rb', link_definition, after: /navigation.items.+do.+primary.*$/
23
+ if kuhsaft_is_installed?
24
+ inject_into_file 'config/cms_navigation.rb', :before => 'primary.dom_class = \'nav\'' do
25
+ "primary.item :#{model_name}_nav, t('cms.#{model_name}.navigation.title'), #{route_name}_path\n "
26
+ end
27
+ end
14
28
  end
15
29
 
16
- def add_model
30
+ def add_model_and_migration
17
31
  generate 'model', model_name
32
+ #TODO: this results in a very messed up indentation in the model. fix!
33
+ inject_into_file "app/models/#{model_name}.rb", before: 'end' do
34
+ " class << self
35
+ # define what attributes are shown in form and permitted by strong parameters
36
+ def editable_attributes
37
+ []
38
+ end
39
+
40
+ # define what attributes are shown in index view
41
+ def index_attributes
42
+ []
43
+ end
44
+ end\n
45
+ "
46
+ end
18
47
  end
19
48
 
20
- def add_controller
21
- generate 'scaffold_controller', resource_route_name, scaffold_controller_options
22
-
23
- controller_content = File.read(controller_path)
24
-
25
- base_controller = kuhsaft_is_used? ? 'Kuhsaft::Cms::AdminController' : 'Shoestrap::BaseController'
26
- controller_content.gsub!('ApplicationController', base_controller)
49
+ def add_resource_translations
50
+ copy_file 'translations/resource.yml', "config/locales/de/#{model_name}.yml"
51
+ end
27
52
 
28
- model_class = resource_route_name.camelize
29
- controller_content.gsub!(/#{model_class}\./, model_class.gsub('Cms::','')+'.')
53
+ def add_controller
54
+ generate 'controller', controller_name, " --controller-specs=no --view-specs=no"
55
+ gsub_file "app/controllers/#{controller_name}_controller.rb", 'ApplicationController', 'Shoestrap::BaseController'
56
+ end
30
57
 
31
- controller_content.gsub!("params\[:cms_#{model_name}]", "params\[:#{model_name}]")
58
+ private
32
59
 
33
- File.open(controller_path, 'w') { |file| file.puts controller_content }
60
+ def shoestrap_cms_already_installed?
61
+ File.exists? 'app/controllers/shoestrap/base_controller.rb'
62
+ end
34
63
 
35
- inject_into_file controller_path, " respond_to :html\n", after: /class Cms::.+Controller < #{base_controller}/
36
- inject_into_file controller_path, "\n actions :all, :except => [ :show ]\n", after: /class Cms::.+Controller < #{base_controller}/
64
+ def setup_base_controller
65
+ empty_directory 'app/controllers/shoestrap'
66
+ if kuhsaft_is_installed?
67
+ template 'base_controller_with_kuhsaft.rb', 'app/controllers/shoestrap/base_controller.rb'
68
+ else
69
+ template 'base_controller_without_kuhsaft.rb', 'app/controllers/shoestrap/base_controller.rb'
70
+ end
37
71
  end
38
72
 
39
- def create_shoestrap_basecontroller_if_kuhsaft_isnt_used
40
- copy_file 'base_controller.rb', 'app/controllers/shoestrap/base_controller.rb'
73
+ def setup_base_views
74
+ directory 'inherited_views', 'app/views/shoestrap'
41
75
  end
42
76
 
43
- private
77
+ def setup_navigation
78
+ if kuhsaft_is_installed?
79
+ nav_dir = 'app/views/kuhsaft/cms/admin'
80
+ empty_directory nav_dir
81
+ copy_file '_main_navigation.html.haml', "#{nav_dir}/_main_navigation.html.haml"
82
+ copy_file 'cms_navigation.rb', "config/cms_navigation.rb"
83
+ end
84
+ end
44
85
 
45
- def kuhsaft_is_used?
46
- !!defined?(Kuhsaft)
86
+ def setup_translation_file
87
+ empty_directory 'config/locales/de'
88
+ copy_file 'translations/shoestrap_base.yml', 'config/locales/de/shoestrap_base.yml'
47
89
  end
48
90
 
49
- def controller_path
50
- "app/controllers/#{resource_route_name.pluralize}_controller.rb"
91
+ def kuhsaft_is_installed?
92
+ @kuhsaft_is_installed ||= !!defined?(Kuhsaft)
51
93
  end
52
94
 
53
95
  def resource_route_name
@@ -58,8 +100,16 @@ module Shoestrap
58
100
  ARGV.first.downcase
59
101
  end
60
102
 
61
- def scaffold_controller_options
62
- "--no-routing-specs --no-view-specs --no-controller-specs --no-jbuilder"
103
+ def plural_name
104
+ model_name.pluralize
105
+ end
106
+
107
+ def controller_name
108
+ "cms/#{plural_name}"
109
+ end
110
+
111
+ def route_name
112
+ controller_name.gsub('/', '_')
63
113
  end
64
114
  end
65
115
  end
@@ -1,3 +1,3 @@
1
1
  module Shoestrap
2
- VERSION = "1.0.0.pre3"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -25,7 +25,6 @@ inject_into_file 'config/application.rb', :after => "Application < Rails::Applic
25
25
  # Customize generators
26
26
  config.generators do |g|
27
27
  g.stylesheets false
28
- g.form_builder :simple_form
29
28
  g.template_engine :haml
30
29
  g.test_framework :rspec
31
30
  g.javascripts false
@@ -39,7 +38,7 @@ end
39
38
  # Default Gems (others are added to gemfile by individual generators called after app generation)
40
39
  #
41
40
  gem 'therubyracer', platforms: :ruby
42
- gem 'simple_form', '3.0.0.rc'
41
+ gem 'simple_form', '3.0.0'
43
42
  gem 'haml'
44
43
  gem 'haml-rails'
45
44
  gem 'simple-navigation'
@@ -0,0 +1,4 @@
1
+ = link_to 'Kuhsaft CMS', kuhsaft.cms_root_path, :class => 'brand'
2
+ %p.navbar-text.pull-right
3
+ = link_to t('.logout'), '', :method => :delete
4
+ = render_navigation(:context => :cms)
@@ -0,0 +1,13 @@
1
+ class Shoestrap::BaseController < Kuhsaft::Cms::AdminController
2
+ def show
3
+ super do |format|
4
+ format.html { redirect_to collection_path }
5
+ end
6
+ end
7
+
8
+ private
9
+
10
+ def permitted_params
11
+ params.permit(resource_collection_name => collection.editable_attributes)
12
+ end
13
+ end
@@ -0,0 +1,15 @@
1
+ class Shoestrap::BaseController < ActionController::Base
2
+ inherit_resources
3
+
4
+ def show
5
+ super do |format|
6
+ format.html { redirect_to collection_path }
7
+ end
8
+ end
9
+
10
+ private
11
+
12
+ def permitted_params
13
+ params.permit(resource_collection_name => collection.editable_attributes)
14
+ end
15
+ end
@@ -0,0 +1,9 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Configures your navigation
3
+ SimpleNavigation::Configuration.run do |navigation|
4
+ navigation.items do |primary|
5
+ primary.item :pages, Kuhsaft::Page.model_name.human(:count => 2), kuhsaft.cms_pages_path, :highlights_on => %r(/cms$|/cms/pages)
6
+ primary.dom_class = 'nav'
7
+ end
8
+ navigation.selected_class = 'active'
9
+ end
@@ -0,0 +1,9 @@
1
+ = simple_form_for([:cms, resource]), wrapper: :bootstrap do |f|
2
+ = f.error_notification
3
+
4
+ .form-inputs
5
+ - resource.class.column_names.reject {|c| ['id', 'created_at', 'updated_at'].include? c }.each do |column_name|
6
+ = f.input column_name
7
+
8
+ .form-actions
9
+ = f.button :submit
@@ -0,0 +1,5 @@
1
+ %h1= t("cms.edit_title", singular_name: t("cms.#{resource_collection_name}.singular_name"))
2
+
3
+ = render 'form'
4
+
5
+ = link_to t('cms.back'), collection_path
@@ -0,0 +1,28 @@
1
+ %h1= t("cms.index_title", plural_name: t("cms.#{resource_collection_name}.plural_name"))
2
+
3
+ .row-fluid.actions
4
+ .pull-right.padded
5
+ = link_to new_resource_path, :class => 'btn btn-primary' do
6
+ %i.icon-plus-sign.icon-white
7
+ = t("cms.#{resource_collection_name}.new", plural_name: resource_collection_name, default: t('cms.default.new'))
8
+
9
+ %table.table.table-bordered.table-striped
10
+ %thead
11
+ %tr
12
+ - collection.index_attributes.each do |column_name|
13
+ %th= collection.human_attribute_name column_name
14
+ %th
15
+ %th
16
+
17
+ %tbody
18
+ - collection.each do |item|
19
+ %tr
20
+ - collection.index_attributes.each do |column_name|
21
+ %td= item.send(column_name)
22
+ %td= link_to t("cms.edit"), edit_resource_path(item)
23
+ %td
24
+ =link_to resource_path(item), method: :delete, data: { confirm: t('cms.are_you_sure') }, class: 'btn btn-small btn-danger' do
25
+ %i.icon-trash.icon-white
26
+ =t('cms.destroy')
27
+
28
+ %br
@@ -0,0 +1,5 @@
1
+ %h1= t("cms.new_title", singular_name: t("cms.#{resource_collection_name}.singular_name"))
2
+
3
+ = render 'form'
4
+
5
+ = link_to t('cms.back'), collection_path
@@ -0,0 +1,16 @@
1
+ de:
2
+ cms:
3
+ news_items:
4
+ singular_name: TRANSLATEME
5
+ plural_name: TRANSLATEME
6
+ navigation_title: TRANSLATEME
7
+
8
+ activerecord:
9
+ attributes:
10
+ news_item:
11
+ some_attr: TRANSLATE YOUR ATTRIBUTES
12
+
13
+ models:
14
+ news_item:
15
+ one: TRANSLATEME
16
+ other: TRANSLATEME
@@ -0,0 +1,11 @@
1
+ de:
2
+ cms:
3
+ are_you_sure: 'Sind Sie sicher?'
4
+ destroy: 'Löschen'
5
+ edit: 'Bearbeiten'
6
+ back: 'Zurück'
7
+ index_title: "%{plural_name} Verwalten"
8
+ edit_title: "%{singular_name} Bearbeiten"
9
+ new: "Neuer %{singular_name}"
10
+ default:
11
+ new: 'Neuer Eintrag'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shoestrap
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.pre3
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Felipe Kaufmann
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-18 00:00:00.000000000 Z
11
+ date: 2013-09-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -233,7 +233,16 @@ files:
233
233
  - templates/bdd_generator/dotrspec
234
234
  - templates/bdd_generator/fast_spec_helper.rb
235
235
  - templates/bdd_generator/spec_helper.rb
236
- - templates/cms_generator/base_controller.rb
236
+ - templates/cms_generator/_main_navigation.html.haml
237
+ - templates/cms_generator/base_controller_with_kuhsaft.rb
238
+ - templates/cms_generator/base_controller_without_kuhsaft.rb
239
+ - templates/cms_generator/cms_navigation.rb
240
+ - templates/cms_generator/inherited_views/base/_form.html.haml
241
+ - templates/cms_generator/inherited_views/base/edit.html.haml
242
+ - templates/cms_generator/inherited_views/base/index.html.haml
243
+ - templates/cms_generator/inherited_views/base/new.html.haml
244
+ - templates/cms_generator/translations/resource.yml
245
+ - templates/cms_generator/translations/shoestrap_base.yml
237
246
  - templates/coffee_files_generator/application.js.coffee
238
247
  - templates/foundation_generator/_mixin.css.sass
239
248
  - templates/foundation_generator/_settings.css.sass
@@ -269,9 +278,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
269
278
  version: '0'
270
279
  required_rubygems_version: !ruby/object:Gem::Requirement
271
280
  requirements:
272
- - - '>'
281
+ - - '>='
273
282
  - !ruby/object:Gem::Version
274
- version: 1.3.1
283
+ version: '0'
275
284
  requirements: []
276
285
  rubyforge_project:
277
286
  rubygems_version: 2.0.3
@@ -1,2 +0,0 @@
1
- class Shoestrap::BaseController < InheritedResources::Base
2
- end