golden-setting 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +198 -0
  6. data/Rakefile +1 -0
  7. data/app/assets/javascripts/golden/setting/settings.js.coffee +8 -0
  8. data/app/assets/stylesheets/golden/setting/settings.css.sass +0 -0
  9. data/app/controllers/golden/setting/settings_controller.rb +65 -0
  10. data/app/helpers/golden/setting/settings_helper.rb +52 -0
  11. data/app/models/concerns/golden/setting/resourced.rb +48 -0
  12. data/app/views/golden/setting/settings/_batch_form.html.erb +24 -0
  13. data/app/views/golden/setting/settings/_form.html.erb +25 -0
  14. data/app/views/golden/setting/settings/_setting.html.erb +18 -0
  15. data/app/views/golden/setting/settings/_table.html.erb +34 -0
  16. data/app/views/golden/setting/settings/edit.html.erb +30 -0
  17. data/app/views/golden/setting/settings/index.html.erb +33 -0
  18. data/app/views/golden/setting/settings/list.html.erb +19 -0
  19. data/app/views/golden/setting/settings/new.html.erb +27 -0
  20. data/app/views/golden/setting/settings/show.html.erb +24 -0
  21. data/config/locales/settings.en.yml +52 -0
  22. data/config/locales/settings.zh-TW.yml +52 -0
  23. data/config/routes.rb +8 -0
  24. data/golden-setting.gemspec +28 -0
  25. data/lib/generators/golden/setting/USAGE +18 -0
  26. data/lib/generators/golden/setting/install_generator.rb +86 -0
  27. data/lib/generators/golden/setting/templates/create_golden_settings.rb +17 -0
  28. data/lib/generators/golden/setting/templates/golden_setting.rb +36 -0
  29. data/lib/generators/golden/setting/templates/setting.rb +3 -0
  30. data/lib/generators/golden/setting/templates/settings.en.yml +15 -0
  31. data/lib/generators/golden/setting/templates/settings.zh-TW.yml +15 -0
  32. data/lib/golden/setting/action.rb +58 -0
  33. data/lib/golden/setting/base.rb +47 -0
  34. data/lib/golden/setting/cache.rb +55 -0
  35. data/lib/golden/setting/engine.rb +16 -0
  36. data/lib/golden/setting/error.rb +38 -0
  37. data/lib/golden/setting/form_option.rb +69 -0
  38. data/lib/golden/setting/group.rb +17 -0
  39. data/lib/golden/setting/name.rb +30 -0
  40. data/lib/golden/setting/resource.rb +44 -0
  41. data/lib/golden/setting/value.rb +67 -0
  42. data/lib/golden/setting/version.rb +5 -0
  43. data/lib/golden/setting.rb +54 -0
  44. data/spec/base_spec.rb +125 -0
  45. data/spec/cache_spec.rb +40 -0
  46. data/spec/resource_spec.rb +72 -0
  47. data/spec/spec_helper.rb +32 -0
  48. data/spec/support/models.rb +15 -0
  49. data/spec/support/schema.rb +26 -0
  50. metadata +194 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 73d045fd6c1c360eea89881dc9dd6ade617f1f79
4
+ data.tar.gz: 2b7c5cae33d3d537ec1cc25074ebfa3ff048cd0d
5
+ SHA512:
6
+ metadata.gz: c086262dfc0d1d86c98a64f239c0890f7a7ee1d2dad4941e99550114bb527e0fdf6f31bc02133e61d528fbdd738ad6eb3a6d30ebafd542447128e278c95c2fdd
7
+ data.tar.gz: 7e4aa48952e29c8fdd73926e8173e56c604fa1d8bca831248a2e63355ae52127d1602032fb61fca41929732247edc09b4de58a586d22a9c80e8614503e3d8386
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in golden-setting.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Tse-Ching Ho
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,198 @@
1
+ # Golden Setting
2
+
3
+ The `golden-setting` persists settings in database and keeps alive in cache.
4
+
5
+ A web interface is provied to let users can update easily.
6
+
7
+ ## Requirement
8
+
9
+ For Rails 4 project, `Gemfile` should have
10
+
11
+ ```ruby
12
+ gem 'protected_attributes'
13
+ gem 'devise', '~> 3.0.0.rc'
14
+ gem 'cancan'
15
+ gem 'simple_form', '~> 3.0.0.rc'
16
+ gem 'anjlab-bootstrap-rails', require: 'bootstrap-rails'
17
+ gem 'will_paginate'
18
+ gem 'rails-theme-helper'
19
+ ```
20
+
21
+ For Rails 3 project, `Gemfile` should have
22
+
23
+ ```ruby
24
+ gem 'devise', '>= 2.0', '< 3.0'
25
+ gem 'cancan'
26
+ gem 'simple_form', '>= 2.0', '< 3.0'
27
+ gem 'anjlab-bootstrap-rails', require: 'bootstrap-rails'
28
+ gem 'will_paginate'
29
+ gem 'rails-theme-helper'
30
+ ```
31
+
32
+ Please make sure these gems are installed and configured properly.
33
+
34
+ ## Installation
35
+
36
+ Add `golden-setting` to your application's Gemfile.
37
+
38
+ ```ruby
39
+ gem 'golden-setting'
40
+ ```
41
+
42
+ Then bundle gems, generate settings and migrate database.
43
+
44
+ ```ruby
45
+ $ bundle
46
+ $ rails generate golden:setting:install setting
47
+ $ rake db:migrate
48
+ ```
49
+
50
+ Remember add setting abilities for `cancan`.
51
+
52
+ ```
53
+ can :index, Setting
54
+ can :batch_update, Setting
55
+ ```
56
+
57
+ ## Configuration
58
+
59
+ You will need to add these basic configures of `golden-setting` for your needs.
60
+
61
+ * `groups` for grouping settings with a name
62
+ # `default_group` for saving settings with a group
63
+ * `default_tab` for a group of settings shown in tab views
64
+
65
+ Edit `config/initializers/golden_setting.rb` for more detail.
66
+
67
+ ## Usage
68
+
69
+ ### Create/Read/Update/Destroy settings
70
+
71
+ You can add setting with named group.
72
+
73
+ ```ruby
74
+ Setting.add 'google', 'google_analytics_token', 12345
75
+ Setting.add 'api', 'golden_api_credentials', { username: 'tsechingho', password: 'secret' }
76
+ Setting.add 'theme', 'theme_color', 'golden', :select, "%w(golden white)"
77
+ ```
78
+
79
+ or add setting with blank group.
80
+
81
+ ```ruby
82
+ Setting.google_analytics_token = 12345
83
+ Setting.golden_api_credentials = { username: 'tsechingho', password: 'secret' }
84
+ Setting.theme_color = 'golden'
85
+ ```
86
+
87
+ Read settings (group regardless).
88
+
89
+ ```ruby
90
+ Setting.google_analytics_token
91
+ Setting.golden_api_credentials
92
+ Setting.theme_color
93
+ ```
94
+
95
+ Update settings (group regardless).
96
+
97
+ ```ruby
98
+ Setting.google_analytics_token = 'abced'
99
+ Setting.merge!(:golden_api_credentials, password: 'topsecret')
100
+ Setting.theme_color = 'white'
101
+ ```
102
+
103
+ Destroy settings.
104
+
105
+ ```ruby
106
+ Setting.destroy :google_analytics_token
107
+ Setting.destroy :golden_api_credentials
108
+ Setting.destroy :theme_color
109
+ ```
110
+
111
+ ### List settings
112
+
113
+ You can add setting with complex name with `[]=` method, and retrieve with `[]` method.
114
+
115
+ And list settings as key-value pair with/without name prefix.
116
+
117
+ ```ruby
118
+ Setting['preferences.color'] = :blue
119
+ Setting['preferences.size'] = :large
120
+ Setting['license.key'] = 'ABC-DEF'
121
+ Setting['license.key']
122
+ Setting.list
123
+ Setting.list('preferences.')
124
+ ```
125
+
126
+ ### Default settings
127
+
128
+ You can add virtaul settings for your application by setting defaults.
129
+
130
+ Add `config/initializers/golden_setting_defaults.rb`.
131
+
132
+ ```ruby
133
+ YourApp::Application.config.after_initialize do
134
+ Setting.defaults[:administrator] = 'tsechingho'
135
+ end
136
+ ```
137
+
138
+ These virtaul settings were not saved in database.
139
+
140
+ ```ruby
141
+ Setting.named('administrator').count # => 0
142
+ Setting.administrator # => 'tsechingho'
143
+ ```
144
+
145
+ You can also save default settings in database after initializing your application.
146
+
147
+ ```ruby
148
+ YourApp::Application.config.after_initialize do
149
+ Setting.save_default :manager, 'tsechingho'
150
+ end
151
+ ```
152
+
153
+ These default settings were saved in database with default group.
154
+
155
+ ```ruby
156
+ Setting.named('manager').count # => 1
157
+ Setting.object('manager').group # => 'site'
158
+ Setting.manager # => 'tsechingho'
159
+ ```
160
+
161
+ ### Resourced settings
162
+
163
+ Settings may be bound to any existing ActiveRecord object.
164
+
165
+ ```ruby
166
+ class User < ActiveRecord::Base
167
+ include Golden::Setting::Resourced
168
+ end
169
+ ```
170
+
171
+ Then you can set or get settings.
172
+
173
+ ```ruby
174
+ user = User.first
175
+ user.settings.theme_color = 'golden'
176
+ user.settings.theme_color # => 'golden'
177
+ user.settings.list # => { "theme_color" => 'golden' }
178
+ ```
179
+
180
+ You can find users having or not having some settings by (experimental) scopes.
181
+
182
+ ```ruby
183
+ User.with_settings.to_a.size # => 1
184
+ User.with_settings_for('theme_color').count # => 1
185
+ User.without_settings.count
186
+ ```
187
+
188
+ ## Contributing
189
+
190
+ 1. Fork it
191
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
192
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
193
+ 4. Push to the branch (`git push origin my-new-feature`)
194
+ 5. Create new Pull Request
195
+
196
+ ## License
197
+
198
+ MIT
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,8 @@
1
+ $ ->
2
+ $('.settings')
3
+ .on 'change', '#setting_field_type', ->
4
+ switch $(this).val()
5
+ when 'string', 'boolean'
6
+ $('.setting_field_values').hide()
7
+ else
8
+ $('.setting_field_values').show()
@@ -0,0 +1,65 @@
1
+ class Golden::Setting::SettingsController < ApplicationController
2
+ before_filter :authenticate_session!
3
+ before_filter :load_setting_class, only: [:index, :create, :list]
4
+ before_filter :new_setting, only: [:create]
5
+ load_and_authorize_resource :setting, class: Golden::Setting.setting_class, parent: false
6
+
7
+ respond_to :html
8
+
9
+ def index
10
+ @default_tab = Golden::Setting.default_tab
11
+ respond_with @settings
12
+ end
13
+
14
+ def show
15
+ respond_with @setting
16
+ end
17
+
18
+ def new
19
+ respond_with @setting
20
+ end
21
+
22
+ def edit
23
+ end
24
+
25
+ def create
26
+ @setting.save
27
+ respond_with @setting, location: setting_path(@setting)
28
+ end
29
+
30
+ def update
31
+ value = params[:setting].delete :value
32
+ @setting.value = value
33
+ @setting.update_attributes params[:setting]
34
+ respond_with @setting, location: setting_path(@setting)
35
+ end
36
+
37
+ def destroy
38
+ @setting.destroy
39
+ respond_with @setting, location: settings_path
40
+ end
41
+
42
+ def list
43
+ @settings = @settings.paginate page: params[:page]
44
+ respond_with @settings
45
+ end
46
+
47
+ def batch_update
48
+ params[:setting].each do |setting, value|
49
+ @setting_class.send "#{setting}=", value
50
+ end
51
+ redirect_to action: :index
52
+ end
53
+
54
+ protected
55
+
56
+ def load_setting_class
57
+ @setting_class = Golden::Setting.setting_class.constantize
58
+ end
59
+
60
+ def new_setting
61
+ value = params[:setting].delete :value
62
+ @setting = @setting_class.new params[:setting]
63
+ @setting.value = value
64
+ end
65
+ end
@@ -0,0 +1,52 @@
1
+ module Golden
2
+ module Setting
3
+ module SettingsHelper
4
+ def setting_selectable? field_type
5
+ !%w{string boolean}.include? field_type
6
+ end
7
+
8
+ def setting_field_types
9
+ Golden::Setting.field_types.map do |key, value|
10
+ next if key.nil? or value.nil?
11
+ [I18n.t(key, scope: 'golden.setting.field_types'), value.to_sym]
12
+ end
13
+ end
14
+
15
+ def setting_field_values collection
16
+ return unless collection.present?
17
+ return collection unless collection.respond_to? :id
18
+ options_from_collection_for_select(collection, :id, :to_s, object.value)
19
+ end
20
+
21
+ def setting_groups
22
+ Golden::Setting.groups.map do |key, value|
23
+ next if key.nil? or value.nil?
24
+ [I18n.t(key, scope: 'golden.setting.groups'), value.to_s]
25
+ end
26
+ end
27
+
28
+ def setting_name name
29
+ I18n.t(name, scope: 'golden.setting.names')
30
+ end
31
+
32
+ def settings_nav_tab name, default
33
+ text = I18n.t(name, scope: 'golden.setting.groups')
34
+ nav_tab text, "settings-#{name}", "settings-#{default}"
35
+ end
36
+
37
+ def settings_tab_pane name, default, &block
38
+ tab_pane "settings-#{name}", "settings-#{default}", &block
39
+ end
40
+
41
+ def skip_setting_group? group
42
+ method = Golden::Setting.skip_groups_method
43
+ skiped = (method and respond_to?(method) and send(method, group))
44
+ group.blank? or skiped
45
+ end
46
+
47
+ def skip_setting? setting
48
+ Golden::Setting.skip_settings.include? setting
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,48 @@
1
+ module Golden
2
+ module Setting
3
+ module Resourced
4
+ extend ActiveSupport::Concern
5
+ include do
6
+ end
7
+
8
+ module ClassMethods
9
+ def with_settings
10
+ select("DISTINCT #{self.table_name}.*").
11
+ joins("JOIN `#{settings_table}` ON (#{join_settings_on})")
12
+ end
13
+
14
+ def with_settings_for name
15
+ joins("JOIN `#{settings_table}` ON (#{join_settings_on})").
16
+ where("`#{settings_table}`.name = ?", name)
17
+ end
18
+
19
+ def without_settings
20
+ joins("LEFT JOIN `#{settings_table}` ON (#{join_settings_on})").
21
+ where("`#{settings_table}`.id IS NULL")
22
+ end
23
+
24
+ def without_settings_for name
25
+ without_settings.
26
+ where("`#{settings_table}`.name = ?", name)
27
+ end
28
+
29
+ private
30
+
31
+ def settings_table
32
+ Golden::Setting::Base.table_name
33
+ end
34
+
35
+ def join_settings_on
36
+ [
37
+ "`#{settings_table}`.resource_type = '#{self.base_class.name}'",
38
+ "`#{settings_table}`.resource_id = `#{self.table_name}`.#{self.primary_key}"
39
+ ].join(' AND ')
40
+ end
41
+ end
42
+
43
+ def settings
44
+ Golden::Setting::Resource.bind(self)
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,24 @@
1
+ <%= simple_form_for setting_class,
2
+ as: :setting,
3
+ url: batch_update_settings_path,
4
+ method: :put,
5
+ html: { class: 'form-horizontal' } do |f| %>
6
+
7
+ <%= f.error_notification %>
8
+
9
+ <% settings.each do |setting| %>
10
+ <% next if skip_setting? setting.name %>
11
+ <div class="form-inputs">
12
+ <%= f.input setting.name,
13
+ as: setting.field_type,
14
+ collection: setting_field_values(setting.field_values),
15
+ label: setting_name(setting.name),
16
+ include_blank: false,
17
+ input_html: { value: setting.value } %>
18
+ </div>
19
+ <% end %>
20
+
21
+ <div class="form-actions">
22
+ <%= submit_button f, t('.submit') %>
23
+ </div>
24
+ <% end %>
@@ -0,0 +1,25 @@
1
+ <div class="form-inputs">
2
+ <%= f.input :field_type,
3
+ as: :select,
4
+ collection: setting_field_types,
5
+ include_blank: false,
6
+ required: true %>
7
+ <%= f.input :field_values,
8
+ as: :text,
9
+ required: true,
10
+ wrapper_html: {
11
+ class: setting_selectable?(f.object.field_type) ? '' : 'hide'
12
+ } %>
13
+ <%= f.input :group,
14
+ as: :select,
15
+ collection: setting_groups,
16
+ include_blank: false %>
17
+ <%= f.input :name %>
18
+ <%= f.input :value,
19
+ as: f.object.field_type,
20
+ collection: setting_field_values(f.object.field_values),
21
+ include_blank: false,
22
+ input_html: {
23
+ value: f.object.value
24
+ } %>
25
+ </div>
@@ -0,0 +1,18 @@
1
+ <section>
2
+ <p>
3
+ <b><%= setting.class.human_attribute_name :group %>:</b>
4
+ <%= t(setting.group, scope: 'settings.groups') %>
5
+ </p>
6
+ <p>
7
+ <b><%= setting.class.human_attribute_name :name %>:</b>
8
+ <%= setting.name %>
9
+ </p>
10
+ <p>
11
+ <b><%= setting.class.human_attribute_name :value %>:</b>
12
+ <%= setting.value %>
13
+ </p>
14
+ <p>
15
+ <b><%= setting.class.human_attribute_name :form_options %>:</b>
16
+ <%= setting.form_options %>
17
+ </p>
18
+ </section>
@@ -0,0 +1,34 @@
1
+ <table class="table table-striped table-bordered">
2
+ <thead>
3
+ <tr>
4
+ <th><%= setting_class.human_attribute_name :group %></th>
5
+ <th><%= setting_class.human_attribute_name :name %></th>
6
+ <th><%= setting_class.human_attribute_name :value %></th>
7
+ <th><%= setting_class.human_attribute_name :form_options %></th>
8
+ <th><%= t('helpers.actions') %></th>
9
+ </tr>
10
+ </thead>
11
+ <tbody>
12
+ <% settings.each do |setting| %>
13
+ <tr>
14
+ <td><%= setting.group %></td>
15
+ <td><%= setting.name %></td>
16
+ <td><%= setting.value %></td>
17
+ <td><%= setting.form_options %></td>
18
+ <td class="action">
19
+ <%= render_btn_group do |btn|
20
+ if can? :show, setting
21
+ btn << link_to_show(setting_path(setting))
22
+ end
23
+ if can? :edit, setting
24
+ btn << link_to_edit(edit_setting_path(setting))
25
+ end
26
+ if can? :destroy, setting
27
+ btn << link_to_destroy(setting_path(setting))
28
+ end
29
+ end %>
30
+ </td>
31
+ </tr>
32
+ <% end %>
33
+ </tbody>
34
+ </table>
@@ -0,0 +1,30 @@
1
+ <article>
2
+ <header>
3
+ <h1><%= t('.title') %></h1>
4
+ </header>
5
+
6
+ <%= render_list class: 'nav nav-tabs' do |li|
7
+ if can? :index, @setting.class
8
+ li << [link_to(t('helpers.index'), settings_path), { class: 'pull-right' }]
9
+ end
10
+ if can? :list, @setting.class
11
+ li << [link_to(t('.list'), list_settings_path), { class: 'pull-right' }]
12
+ end
13
+ if can? :show, @setting
14
+ li << [link_to(t('helpers.show'), setting_path(@setting)), { class: 'pull-right' }]
15
+ end
16
+ end %>
17
+
18
+ <div>
19
+ <%= simple_form_for @setting, as: :setting, url: setting_path(@setting) do |f| %>
20
+ <%= f.error_notification %>
21
+ <%= render 'form', f: f %>
22
+ <div class="form-actions">
23
+ <%= submit_button f %>
24
+ </div>
25
+ <% end %>
26
+ </div>
27
+
28
+ <footer>
29
+ </footer>
30
+ </article>
@@ -0,0 +1,33 @@
1
+ <article>
2
+ <header>
3
+ <h1><%= t('.title') %></h1>
4
+ </header>
5
+
6
+ <%= render_list class: 'nav nav-tabs' do |li|
7
+ if can? :new, @setting_class
8
+ li << [link_to(t('helpers.new'), new_setting_path), { class: 'pull-right' }]
9
+ end
10
+ if can? :list, @setting_class
11
+ li << [link_to(t('.list'), list_settings_path), { class: 'pull-right' }]
12
+ end
13
+ Golden::Setting.groups.each do |key, value|
14
+ next if skip_setting_group? key
15
+ li << settings_nav_tab(key, @default_tab)
16
+ end
17
+ end %>
18
+
19
+ <div class="tab-content">
20
+ <% Golden::Setting.groups.each do |key, value| %>
21
+ <% next if skip_setting_group? key %>
22
+ <%= settings_tab_pane key, @default_tab do %>
23
+ <%= render 'batch_form',
24
+ settings: @setting_class.without_resource.grouped(key),
25
+ setting_class: @setting_class
26
+ %>
27
+ <% end %>
28
+ <% end %>
29
+ </div>
30
+
31
+ <footer>
32
+ </footer>
33
+ </article>
@@ -0,0 +1,19 @@
1
+ <article>
2
+ <header>
3
+ <h1><%= t('.title') %></h1>
4
+ </header>
5
+
6
+ <%= render_list class: 'nav nav-tabs' do |li|
7
+ if can? :index, @setting_class
8
+ li << [link_to(t('.index'), settings_path), { class: 'pull-right' }]
9
+ end
10
+ end %>
11
+
12
+ <div>
13
+ <%= render 'table', settings: @settings, setting_class: @setting_class %>
14
+ <%= render 'application/pagination', collection: @settings %>
15
+ </div>
16
+
17
+ <footer>
18
+ </footer>
19
+ </article>
@@ -0,0 +1,27 @@
1
+ <article>
2
+ <header>
3
+ <h1><%= t('.title') %></h1>
4
+ </header>
5
+
6
+ <%= render_list class: 'nav nav-tabs' do |li|
7
+ if can? :index, @setting.class
8
+ li << [link_to(t('helpers.index'), settings_path), { class: 'pull-right' }]
9
+ end
10
+ if can? :list, @setting.class
11
+ li << [link_to(t('.list'), list_settings_path), { class: 'pull-right' }]
12
+ end
13
+ end %>
14
+
15
+ <div>
16
+ <%= simple_form_for @setting, as: :setting, url: settings_path do |f| %>
17
+ <%= f.error_notification %>
18
+ <%= render 'form', f: f %>
19
+ <div class="form-actions">
20
+ <%= submit_button f %>
21
+ </div>
22
+ <% end %>
23
+ </div>
24
+
25
+ <footer>
26
+ </footer>
27
+ </article>
@@ -0,0 +1,24 @@
1
+ <article>
2
+ <header>
3
+ <h1><%= t('.title', name: @setting.name) %></h1>
4
+ </header>
5
+
6
+ <%= render_list class: 'nav nav-tabs' do |li|
7
+ if can? :index, @setting.class
8
+ li << [link_to(t('helpers.index'), settings_path), { class: 'pull-right' }]
9
+ end
10
+ if can? :list, @setting.class
11
+ li << [link_to(t('.list'), list_settings_path), { class: 'pull-right' }]
12
+ end
13
+ if can? :edit, @setting
14
+ li << [link_to(t('helpers.edit'), edit_setting_path(@setting)), { class: 'pull-right' }]
15
+ end
16
+ end %>
17
+
18
+ <div>
19
+ <%= render 'setting', setting: @setting %>
20
+ </div>
21
+
22
+ <footer>
23
+ </footer>
24
+ </article>