settr 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -62,7 +62,7 @@ class Settr::SettingsController < Settr::ApplicationController
62
62
  end
63
63
 
64
64
  def settings
65
- @settings = Settr.all
65
+ @settings = Settr.alterable
66
66
 
67
67
  if request.post?
68
68
  params[:settr].each do |k, v|
@@ -10,5 +10,10 @@ class Settr
10
10
  options.update(html_options)
11
11
  link_to(body, url, options)
12
12
  end
13
+
14
+ def hash_depth(hash)
15
+ hashes = hash.values.select{|h| h.is_a?(Hash)}
16
+ hashes.present? ? hashes.map{|h| hash_depth(h)}.max + 1 : 1
17
+ end
13
18
  end
14
19
  end
@@ -1,6 +1,8 @@
1
1
  # encoding: utf-8
2
2
  class SettrSetting < ActiveRecord::Base
3
3
 
4
+ scope :alterable, where('alterable = ?', true)
5
+
4
6
  def val
5
7
  case typ
6
8
  when 'boolean'
@@ -25,14 +25,14 @@
25
25
  <option value="<%= option %>" <%= 'selected' if object.value == option %> ><%= t("settr.#{object.key}.#{option}") %></option>
26
26
  <% end %>
27
27
  </select>
28
- <% end %>
28
+ <% end %>
29
29
  </div>
30
30
  <% end %>
31
31
  <% else %>
32
32
  <%= content_tag "h#{level}" do %>
33
33
  <%= t("settr.#{key}._title") %>
34
34
  <% end if level > 0 %>
35
- <% object.sort_by{|k, v| k}.each do |k, v| %>
35
+ <% object.sort_by{|x, y| "#{y.is_a?(Hash) ? hash_depth(y) : 0} #{x}"}.each do |k, v| %>
36
36
  <%= render :partial => 'setting', :locals => {:object => v, :level => level + 1, :key => "#{key}.#{k}"} %>
37
37
  <% end %>
38
38
  <div class="horizontal_line grey"></div>
@@ -9,9 +9,8 @@ class Settr
9
9
  copy_file 'settr.rb', 'config/initializers/settr.rb'
10
10
  end
11
11
 
12
- def copy_and_run_migration
12
+ def copy_migration
13
13
  run 'rake settr_engine:install:migrations'
14
- run 'rake db:migrate'
15
14
  end
16
15
  end
17
16
  end
@@ -20,7 +20,7 @@ class Settr
20
20
  cattr_accessor :form_class
21
21
  @@form_class
22
22
 
23
- #links
23
+ # links
24
24
  cattr_accessor :link_class
25
25
  @@link_class
26
26
 
@@ -67,17 +67,19 @@ class Settr
67
67
  end
68
68
  end
69
69
 
70
- def self.all
71
- SettrSetting.all.inject({}) do |h, s|
72
- kk = s.key.split(".")
73
- hh = h
74
- kk.each_with_index do |k, i|
75
- hh[k] ||= (i == kk.count-1 ? s : {})
76
- hh = hh[k]
70
+ [:all, :alterable].each do |method|
71
+ self.define_singleton_method(method) do
72
+ SettrSetting.send(method).inject({}) do |h, s|
73
+ kk = s.key.split(".")
74
+ hh = h
75
+ kk.each_with_index do |k, i|
76
+ hh[k] ||= (i == kk.count-1 ? s : {})
77
+ hh = hh[k]
78
+ end
79
+ h
77
80
  end
78
- h
79
81
  end
80
- end
82
+ end
81
83
  end
82
84
 
83
85
  require 'settr/version'
@@ -1,3 +1,3 @@
1
1
  class Settr
2
- VERSION = "0.1.1"
3
- end
2
+ VERSION = "0.1.2"
3
+ end
@@ -16,8 +16,8 @@ Gem::Specification.new do |s|
16
16
  s.files = `git ls-files`.split("\n")
17
17
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
18
 
19
- s.add_dependency 'rails', '~> 3.1'
20
- s.add_dependency 'jquery-rails'
21
- s.add_dependency 'sass-rails'
22
- s.add_dependency 'simple_form', '~> 1.5'
19
+ s.add_dependency 'rails', '> 3.1'
20
+ s.add_dependency 'jquery-rails', '> 1.0'
21
+ s.add_dependency 'sass-rails', '> 3.1'
22
+ s.add_dependency 'simple_form', '> 1.5'
23
23
  end
@@ -0,0 +1,8 @@
1
+ Settr.setup do |config|
2
+ config.resources = true
3
+ config.header_tag = 'h1'
4
+ config.header_class = 'my_header_class'
5
+ config.table_class = 'my_table_class'
6
+ config.link_class = 'my_link_class'
7
+ config.form_class = 'my_form_class'
8
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: settr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,52 +9,52 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-17 00:00:00.000000000 Z
12
+ date: 2012-01-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &70253602696460 !ruby/object:Gem::Requirement
16
+ requirement: &70363482946140 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
- - - ~>
19
+ - - ! '>'
20
20
  - !ruby/object:Gem::Version
21
21
  version: '3.1'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70253602696460
24
+ version_requirements: *70363482946140
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: jquery-rails
27
- requirement: &70253602695480 !ruby/object:Gem::Requirement
27
+ requirement: &70363482945640 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
- - - ! '>='
30
+ - - ! '>'
31
31
  - !ruby/object:Gem::Version
32
- version: '0'
32
+ version: '1.0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70253602695480
35
+ version_requirements: *70363482945640
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: sass-rails
38
- requirement: &70253602693540 !ruby/object:Gem::Requirement
38
+ requirement: &70363482945180 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
- - - ! '>='
41
+ - - ! '>'
42
42
  - !ruby/object:Gem::Version
43
- version: '0'
43
+ version: '3.1'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70253602693540
46
+ version_requirements: *70363482945180
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: simple_form
49
- requirement: &70253602704940 !ruby/object:Gem::Requirement
49
+ requirement: &70363482944700 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
- - - ~>
52
+ - - ! '>'
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.5'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *70253602704940
57
+ version_requirements: *70363482944700
58
58
  description: Settr is a hierarchical key-value based storage for configuration settings
59
59
  in Rails apps
60
60
  email:
@@ -118,6 +118,7 @@ files:
118
118
  - test/dummy/config/initializers/mime_types.rb
119
119
  - test/dummy/config/initializers/secret_token.rb
120
120
  - test/dummy/config/initializers/session_store.rb
121
+ - test/dummy/config/initializers/settr.rb
121
122
  - test/dummy/config/initializers/wrap_parameters.rb
122
123
  - test/dummy/config/locales/de.yml
123
124
  - test/dummy/config/locales/en.yml
@@ -162,7 +163,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
162
163
  version: '0'
163
164
  requirements: []
164
165
  rubyforge_project: settr
165
- rubygems_version: 1.8.15
166
+ rubygems_version: 1.8.10
166
167
  signing_key:
167
168
  specification_version: 3
168
169
  summary: hierarchical key-value based storage for configuration settings in Rails
@@ -193,6 +194,7 @@ test_files:
193
194
  - test/dummy/config/initializers/mime_types.rb
194
195
  - test/dummy/config/initializers/secret_token.rb
195
196
  - test/dummy/config/initializers/session_store.rb
197
+ - test/dummy/config/initializers/settr.rb
196
198
  - test/dummy/config/initializers/wrap_parameters.rb
197
199
  - test/dummy/config/locales/de.yml
198
200
  - test/dummy/config/locales/en.yml