godmin 0.9.6 → 0.9.7

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: 6c9bc1e136e1f026504ed65cd0199c7bed3b2ec4
4
- data.tar.gz: 36d462277c7c058a619c2fb29afd86f42de87574
3
+ metadata.gz: 3b2b9de0c881d61fc5e85818c2d335da6f291957
4
+ data.tar.gz: a6622de98d4b80f5713db91c2246a181034c8b91
5
5
  SHA512:
6
- metadata.gz: e50bc8557f5bb7d677e75f6cc5e67f39221813f42d2e30539c8bc0d0bc874f6a52fe477fd3b4f9a84a34e911b7dab896c7a53d66f9d1fc4cf01c6d687ebaf042
7
- data.tar.gz: 7185ab2665b695723c7422ee7007f6e11749ff9381ac5c51470342133dc220a2f482f29f3f7b885a2594964c12401db840481f3cac13359baf9aabcccd15671b
6
+ metadata.gz: 662aa94de5c99b574781a967cc6e8f4ef29223563028b26cb19c1b57c261a955e783b7c8a96e8115ac407bbc54e3b7d5be31eb31d494ddc4efc2a0641d6391f7
7
+ data.tar.gz: 26755fad1ee306f90dc5d3ca7be7f30b31757229a7efdda7018d97016c037dc762461f2218432486bbce6516f92bea5e529c1c3202829435ecaedf054bfd76b4
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ### 0.9.7 - 2015-01-07
4
+ Features
5
+ - Support for Rails 4.2
6
+ - New form system (https://github.com/varvet/godmin/pull/50)
7
+
3
8
  ### 0.9.6 - 2014-12-18
4
9
  Features
5
10
  - Bundled [datetimepicker](https://github.com/Eonasdan/bootstrap-datetimepicker/)
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2013 YOURNAME
1
+ Copyright 2013 Varvet
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -19,6 +19,7 @@ Godmin is an admin engine for Rails 4+.
19
19
  - [Redirecting](#redirecting)
20
20
  - [Pagination](#pagination)
21
21
  - [Views](#views)
22
+ - [Forms](#forms)
22
23
  - [Models](#models)
23
24
  - [Authentication](#authentication)
24
25
  - [Simple authentication](#simple-authentication)
@@ -368,12 +369,24 @@ It is easy to override view templates and partials in Godmin, both globally and
368
369
 
369
370
  If you wish to customize the content of a table column, you can place a partial under `app/views/{resource}/columns/{column_name}.html.erb`, e.g. `app/views/articles/columns/_title.html.erb`. The resource is available to the partial through the `resource` variable.
370
371
 
371
- Oftentimes, the default form provided by Godmin doesn't cut it. The `godmin/resource/_form.html.erb` partial is therefore one of the most common to override per resource.
372
+ Oftentimes, the default form provided by Godmin doesn't cut it. The `godmin/resource/_form.html.erb` partial is therefore one of the most common to override per resource. See below for more on form building.
372
373
 
373
374
  Likewise, the `godmin/shared/_navigation.html.erb` partial can be overridden to build a custom navigation bar.
374
375
 
375
376
  The full list of templates and partials that can be overridden [can be found here](https://github.com/varvet/godmin/tree/master/app/views/godmin)
376
377
 
378
+ ### Forms
379
+
380
+ Godmin comes with its own FormBuilder that automatically generates bootstrapped markup. It is based on the [Rails Bootstrap Forms](https://github.com/bootstrap-ruby/rails-bootstrap-forms) FormBuilder, and all its methods are directly available. In addition it has a few convenience methods that can be leveraged.
381
+
382
+ The `input` method will automatically detect the type of field from the database and generate an appropriate form field:
383
+
384
+ ```ruby
385
+ form_for @resource do |f|
386
+ f.input :attribute
387
+ end
388
+ ```
389
+
377
390
  ## Models
378
391
 
379
392
  ## Authentication
@@ -1,12 +1,10 @@
1
- <%= simple_form_for @resource, html: { role: "form" } do |f| %>
2
- <% attrs_for_form.each do |attr| %>
3
- <div class="form-group">
4
- <% if @resource_class.reflect_on_association(attr) %>
5
- <%= f.association attr, error: false, input_html: { class: "form-control", data: { behavior: "select-box" } } %>
6
- <% else %>
7
- <%= f.input attr, error: false, input_html: { class: "form-control" } %>
8
- <% end %>
9
- </div>
1
+ <%= form_for @resource do |f| %>
2
+ <% attrs_for_form.each do |attribute| %>
3
+ <% if f.object.class.reflect_on_association(attribute) %>
4
+ <%= f.association attribute %>
5
+ <% else %>
6
+ <%= f.input attribute %>
7
+ <% end %>
10
8
  <% end %>
11
- <%= f.button :submit, class: "btn btn-default" %>
9
+ <%= f.submit %>
12
10
  <% end %>
@@ -33,3 +33,6 @@ en:
33
33
  entries:
34
34
  zero: "No %{resource} found"
35
35
  other: "Showing %{count} out of %{total} %{resource}"
36
+ datetimepickers:
37
+ datepicker: ! "%m/%d/%Y"
38
+ datetimepicker: ! "%m/%d/%Y%l:%M %p"
@@ -33,3 +33,6 @@ sv:
33
33
  entries:
34
34
  zero: "Inga %{resource} funna"
35
35
  other: "Visar %{count} av %{total} %{resource}"
36
+ datetimepickers:
37
+ datepicker: ! "%Y-%m-%d"
38
+ datetimepicker: ! "%Y-%m-%d %H:%M"
data/godmin.gemspec CHANGED
@@ -21,12 +21,12 @@ Gem::Specification.new do |gem|
21
21
 
22
22
  gem.add_dependency "bcrypt", "~> 3.1.7"
23
23
  gem.add_dependency "bootstrap-sass", "~> 3.3.1.0"
24
+ gem.add_dependency "bootstrap_form", "~> 2.2.0"
24
25
  gem.add_dependency "coffee-rails", [">= 4.0", "< 4.2"]
25
26
  gem.add_dependency "momentjs-rails", ">= 2.8.1"
26
- gem.add_dependency "rails", [">= 4.0", "< 4.2"]
27
- gem.add_dependency "sass-rails", [">= 4.0", "< 4.2"]
27
+ gem.add_dependency "rails", "~> 4.0"
28
+ gem.add_dependency "sass-rails", ">= 4.0"
28
29
  gem.add_dependency "selectize-rails", "~> 0.11.2"
29
- gem.add_dependency "simple_form", "~> 3.0.0"
30
30
 
31
31
  gem.add_development_dependency "sqlite3"
32
32
  end
data/lib/godmin.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require "bootstrap-sass"
2
+ require "bootstrap_form"
2
3
  require "momentjs-rails"
3
4
  require "selectize-rails"
4
- require "simple_form"
5
5
  require "godmin/application"
6
6
  require "godmin/authentication"
7
7
  require "godmin/authorization"
@@ -2,17 +2,66 @@ module Godmin
2
2
  module Helpers
3
3
  module Forms
4
4
  def form_for(record, options = {}, &block)
5
- super(record, { builder: FormBuilders::FormBuilder }.merge(options), &block)
6
- end
7
-
8
- def simple_form_for(record, options = {}, &block)
9
- super(record, { builder: FormBuilders::SimpleFormBuilder }.merge(options), &block)
5
+ super(record, { builder: FormBuilders::FormBuilder, inline_errors: false }.merge(options), &block)
10
6
  end
11
7
  end
12
8
  end
13
9
 
14
10
  module FormBuilders
15
- class FormBuilder < ActionView::Helpers::FormBuilder; end
16
- class SimpleFormBuilder < SimpleForm::FormBuilder; end
11
+ class FormBuilder < BootstrapForm::FormBuilder
12
+ def input(attribute, options = {})
13
+ case attribute_type(attribute)
14
+ when :text
15
+ text_area(attribute, options)
16
+ when :boolean
17
+ check_box(attribute, options)
18
+ when :date
19
+ date_field(attribute, options)
20
+ when :datetime
21
+ datetime_field(attribute, options)
22
+ else
23
+ text_field(attribute, options)
24
+ end
25
+ end
26
+
27
+ def association(attribute, options = {})
28
+ case association_type(attribute)
29
+ when :belongs_to
30
+ select attribute, association_collection(attribute), {}, data: { behavior: "select-box" }
31
+ else
32
+ input(attribute, options)
33
+ end
34
+ end
35
+
36
+ def date_field(attribute, options = {})
37
+ text_field(attribute, value: datetime_value(attribute, :datepicker), data: { behavior: "datepicker" })
38
+ end
39
+
40
+ def datetime_field(attribute, options = {})
41
+ text_field(attribute, value: datetime_value(attribute, :datetimepicker), data: { behavior: "datetimepicker" })
42
+ end
43
+
44
+ private
45
+
46
+ def attribute_type(attribute)
47
+ @object.column_for_attribute(attribute).try(:type)
48
+ end
49
+
50
+ def association_type(attribute)
51
+ association_reflection(attribute).try(:macro)
52
+ end
53
+
54
+ def association_collection(attribute)
55
+ association_reflection(attribute).try(:klass).try(:all)
56
+ end
57
+
58
+ def association_reflection(attribute)
59
+ @object.class.reflect_on_association(attribute)
60
+ end
61
+
62
+ def datetime_value(attribute, format)
63
+ @object.send(attribute).try(:strftime, @template.translate_scoped("datetimepickers.#{format}"))
64
+ end
65
+ end
17
66
  end
18
67
  end
@@ -1,3 +1,3 @@
1
1
  module Godmin
2
- VERSION = "0.9.6"
2
+ VERSION = "0.9.7"
3
3
  end
@@ -31,6 +31,9 @@ Dummy::Application.configure do
31
31
  # ActionMailer::Base.deliveries array.
32
32
  config.action_mailer.delivery_method = :test
33
33
 
34
+ # Randomize the order test cases are executed.
35
+ config.active_support.test_order = :random
36
+
34
37
  # Print deprecation notices to the stderr.
35
38
  config.active_support.deprecation = :stderr
36
39
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: godmin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.6
4
+ version: 0.9.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jens Ljungblad
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2014-12-18 00:00:00.000000000 Z
13
+ date: 2015-01-07 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bcrypt
@@ -40,6 +40,20 @@ dependencies:
40
40
  - - "~>"
41
41
  - !ruby/object:Gem::Version
42
42
  version: 3.3.1.0
43
+ - !ruby/object:Gem::Dependency
44
+ name: bootstrap_form
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: 2.2.0
50
+ type: :runtime
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - "~>"
55
+ - !ruby/object:Gem::Version
56
+ version: 2.2.0
43
57
  - !ruby/object:Gem::Dependency
44
58
  name: coffee-rails
45
59
  requirement: !ruby/object:Gem::Requirement
@@ -78,22 +92,16 @@ dependencies:
78
92
  name: rails
79
93
  requirement: !ruby/object:Gem::Requirement
80
94
  requirements:
81
- - - ">="
95
+ - - "~>"
82
96
  - !ruby/object:Gem::Version
83
97
  version: '4.0'
84
- - - "<"
85
- - !ruby/object:Gem::Version
86
- version: '4.2'
87
98
  type: :runtime
88
99
  prerelease: false
89
100
  version_requirements: !ruby/object:Gem::Requirement
90
101
  requirements:
91
- - - ">="
102
+ - - "~>"
92
103
  - !ruby/object:Gem::Version
93
104
  version: '4.0'
94
- - - "<"
95
- - !ruby/object:Gem::Version
96
- version: '4.2'
97
105
  - !ruby/object:Gem::Dependency
98
106
  name: sass-rails
99
107
  requirement: !ruby/object:Gem::Requirement
@@ -101,9 +109,6 @@ dependencies:
101
109
  - - ">="
102
110
  - !ruby/object:Gem::Version
103
111
  version: '4.0'
104
- - - "<"
105
- - !ruby/object:Gem::Version
106
- version: '4.2'
107
112
  type: :runtime
108
113
  prerelease: false
109
114
  version_requirements: !ruby/object:Gem::Requirement
@@ -111,9 +116,6 @@ dependencies:
111
116
  - - ">="
112
117
  - !ruby/object:Gem::Version
113
118
  version: '4.0'
114
- - - "<"
115
- - !ruby/object:Gem::Version
116
- version: '4.2'
117
119
  - !ruby/object:Gem::Dependency
118
120
  name: selectize-rails
119
121
  requirement: !ruby/object:Gem::Requirement
@@ -128,20 +130,6 @@ dependencies:
128
130
  - - "~>"
129
131
  - !ruby/object:Gem::Version
130
132
  version: 0.11.2
131
- - !ruby/object:Gem::Dependency
132
- name: simple_form
133
- requirement: !ruby/object:Gem::Requirement
134
- requirements:
135
- - - "~>"
136
- - !ruby/object:Gem::Version
137
- version: 3.0.0
138
- type: :runtime
139
- prerelease: false
140
- version_requirements: !ruby/object:Gem::Requirement
141
- requirements:
142
- - - "~>"
143
- - !ruby/object:Gem::Version
144
- version: 3.0.0
145
133
  - !ruby/object:Gem::Dependency
146
134
  name: sqlite3
147
135
  requirement: !ruby/object:Gem::Requirement