shoestrap 1.0.2 → 1.1.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: c090c4eecc46f877fcd70713bf67189db14d0336
4
- data.tar.gz: 8af9d3380f575421ee964a7398253ccb79492dac
3
+ metadata.gz: b5160f485c9d7e9e55efcb16dd0fb1d197fa9be3
4
+ data.tar.gz: 57c03550346f52fa0794c28bd105b21c6b00c4d6
5
5
  SHA512:
6
- metadata.gz: 8059259f412ed24aed9ba29e53ecda51dd230156505e2afff76005443d3a8b9f553f24865728b2d00879b755d4aca36b2c4685eef5a798bdf069d49b33290800
7
- data.tar.gz: fd24600c582956c778182cfcbc36dd6c3e0b7d7d472a6c3f7f327d9dad314eeb6c043e972cce0d9b6c45972845f25ab79e6e213203b46285807f1bb6da63f296
6
+ metadata.gz: c13e977d49958f335020cd0e5a37f5faf25e5e87ec8014bdc6f763c616ac0d2df9a610821b0ad300c840ba2d71b612263342af84802816223706e49127d9ea2d
7
+ data.tar.gz: 90f4bc4bbc510478a72a7a8742a4f99e60638f0fe80e50ba4bc814806e519bf775cd6899867ec036ffda1162e154d824b67ebe01f24987a4018d26be7ebc3cb4
@@ -1,5 +1,9 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 1.1.0 - 2013-10-07
4
+
5
+ - add nicer method of defining attributes that are shown in index/edit views
6
+
3
7
  ## 1.0.2 - 2013-10-02
4
8
 
5
9
  - Fix Kuhaft `content_for :head` block integration and document how to use it
@@ -29,20 +29,21 @@ module Shoestrap
29
29
 
30
30
  def add_model_and_migration
31
31
  generate 'model', model_name
32
- #TODO: this results in a very messed up indentation in the model. fix!
32
+ inject_into_file "app/models/#{model_name}.rb", before: 'class' do
33
+ "require 'shoestrap/cms_model'\n\n"
34
+ end
35
+
33
36
  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
- "
37
+ <<-eos.gsub(/^ {8}/, '').chomp
38
+ include Shoestrap::CMSModel
39
+
40
+ # TODO: Define what attributes are shown in the form and permitted by strong parameters
41
+ # editable_attributes :title, :body
42
+
43
+ # TODO: Define what attributes are shown in the index view
44
+ # index_attributes :id, :title
45
+
46
+ eos
46
47
  end
47
48
  end
48
49
 
@@ -58,7 +59,7 @@ module Shoestrap
58
59
  private
59
60
 
60
61
  def shoestrap_cms_already_installed?
61
- File.exists? 'app/controllers/shoestrap/base_controller.rb'
62
+ File.exists?('app/controllers/shoestrap/base_controller.rb') && File.exists?('config/cms_navigation.rb')
62
63
  end
63
64
 
64
65
  def setup_base_controller
@@ -1,4 +1,3 @@
1
- require 'pry'
2
1
  require 'rails/generators'
3
2
 
4
3
  module Shoestrap
@@ -0,0 +1,25 @@
1
+ module Shoestrap
2
+ module CMSModel
3
+ def self.included(base)
4
+ base.extend(ClassMethods)
5
+ end
6
+
7
+ module ClassMethods
8
+ def index_attributes(*attributes)
9
+ if attributes.empty?
10
+ instance_variable_get(:@shoestrap_index_attributes)
11
+ else
12
+ instance_variable_set(:@shoestrap_index_attributes, attributes)
13
+ end
14
+ end
15
+
16
+ def editable_attributes(*attributes)
17
+ if attributes.empty?
18
+ instance_variable_get(:@shoestrap_editable_attributes)
19
+ else
20
+ instance_variable_set(:@shoestrap_editable_attributes, attributes)
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -1,3 +1,3 @@
1
1
  module Shoestrap
2
- VERSION = "1.0.2"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -0,0 +1,29 @@
1
+ require_relative '../../lib/shoestrap/cms_model'
2
+ require_relative '../spec_helper'
3
+
4
+ module Shoestrap
5
+ describe CMSModel do
6
+
7
+ describe 'index_attributes class macro' do
8
+ let(:dummy) { class Dummy; include Shoestrap::CMSModel; end }
9
+
10
+ it 'is a class macro' do
11
+ expect{ dummy.class_eval { index_attributes :title, :created_at } }.not_to raise_error
12
+ end
13
+
14
+ it 'allows to define attribute names that should be shown in the index table' do
15
+ dummy.class_eval { index_attributes :title, :created_at }
16
+ expect(dummy.instance_variable_get('@shoestrap_index_attributes')).to eq [:title, :created_at]
17
+ end
18
+ end
19
+
20
+ describe 'index attributes class method' do
21
+ let(:dummy) { class Dummy; include Shoestrap::CMSModel; end }
22
+
23
+ it 'returns the attribute names defined with class macro' do
24
+ dummy.class_eval { index_attributes :title, :created_at }
25
+ expect(dummy.index_attributes).to eq [:title, :created_at]
26
+ end
27
+ end
28
+ end
29
+ end
@@ -1,8 +1,8 @@
1
- = simple_form_for([:cms, resource]), wrapper: :bootstrap do |f|
1
+ = simple_form_for([:cms, resource], wrapper: :bootstrap) do |f|
2
2
  = f.error_notification
3
3
 
4
4
  .form-inputs
5
- - resource.class.column_names.reject {|c| ['id', 'created_at', 'updated_at'].include? c }.each do |column_name|
5
+ - resource.class.editable_attributes.each do |column_name|
6
6
  = f.input column_name
7
7
 
8
8
  .form-actions
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.2
4
+ version: 1.1.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-10-02 00:00:00.000000000 Z
11
+ date: 2013-10-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -214,12 +214,14 @@ files:
214
214
  - lib/shoestrap.rb
215
215
  - lib/shoestrap/application_generator.rb
216
216
  - lib/shoestrap/cli.rb
217
+ - lib/shoestrap/cms_model.rb
217
218
  - lib/shoestrap/railtie.rb
218
219
  - lib/shoestrap/shell.rb
219
220
  - lib/shoestrap/version.rb
220
221
  - shoestrap.gemspec
221
222
  - spec/shoestrap/application_generator_spec.rb
222
223
  - spec/shoestrap/cli_spec.rb
224
+ - spec/shoestrap/cms_model.rb
223
225
  - spec/spec_helper.rb
224
226
  - templates/application_generator/_typekit.html.haml
225
227
  - templates/application_generator/application.html.haml
@@ -303,4 +305,5 @@ test_files:
303
305
  - features/shoestrap/generators/view_files_generator_spec.rb
304
306
  - spec/shoestrap/application_generator_spec.rb
305
307
  - spec/shoestrap/cli_spec.rb
308
+ - spec/shoestrap/cms_model.rb
306
309
  - spec/spec_helper.rb