x-editable-rails 1.5.0 → 1.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 658565005fa676f034fc99c545ba7e60158b983b
4
- data.tar.gz: 67c484363471f28a725164ffbdbb8476ac9268d2
3
+ metadata.gz: f211902f307559fafdeb55542265063b6aed1b74
4
+ data.tar.gz: b01c23c18a006cd2079bf562621df7774830942c
5
5
  SHA512:
6
- metadata.gz: fb098d43de97de7c8a9b71495a79f8d7ace85d76792f0476a55381da194491e25d74bf6ae4236de79948b15ca65aa907616bb3fa00e23b38416947ccb3ca1a73
7
- data.tar.gz: f40ec85577f7b1d4cb6ce0d36123918a1b77c4e4f7a56d1394bbb5d17a7356e028bf377da90513cd40e5768425c83d9a47876ae9426b358f443b38352622fa1f
6
+ metadata.gz: 9fe4a918b0d2e3da58d6105c8646f757780855011bd347c814d3b7b073abb6d6e40b77d52dc7dde206fb7d3d61b1d792b28ddc9521605ceeac297c4e8fd90842
7
+ data.tar.gz: da69e8902b82d4f9fe578e02a9bb2f2e8b17598a346168b198cd2dc57f8cac572406bdf90436a6f15290c490bbd9f2b547943fc35000b46f661fa2aa8d4c21fa
data/README.md CHANGED
@@ -84,12 +84,16 @@ A `span` element is rendered with `data-*` attributes used by `x-editable`.
84
84
  %h1= editable @model, :name
85
85
  ```
86
86
 
87
- The helper method automatically adds these `data-*` attributes used by [x-editable](http://vitalets.github.io/x-editable/docs.html).
87
+ You can customize the tag name and title attribute:
88
+
89
+ * **tag** - `span` by default.
90
+ * **title** - The model and attribute name are used to create a capitalized title
91
+
92
+ The `editable` helper method automatically adds these `data-*` attributes used by [x-editable](http://vitalets.github.io/x-editable/docs.html).
88
93
 
89
94
  * **url** - Uses the `polymorphic_path(model)` helper method.
90
95
  * **source** - Only populated if the value is a boolean to convert `true` or `false` to "Yes" and "No".
91
96
  * **value** - Uses `model.name`. If `model.name` were a boolean value or if a `source` is specified, the `source` text would be displayed rather than the raw value. (Presumably the value is an ID and the source would have the text associated with that value.)
92
- * **title** - The model and attribute name are used to create a capitalized title
93
97
  * **placeholder** - Uses the `title` value by default
94
98
 
95
99
  ```ruby
@@ -157,7 +161,7 @@ This example uses the `MailingList` class and its attributes.
157
161
  The attribute value can be a string, which is used as the `title` and `placeholder`.
158
162
  If you want to specify other options, create a hash of options.
159
163
 
160
- Save your YAML file in: `config/x-editable.yml`. Here is an example [example](config/x-editable.yml).
164
+ Install configuration file like this: `rails g x_editable_rails:install`, this step is not necessary
161
165
 
162
166
  ```yaml
163
167
  class_options:
@@ -192,6 +196,18 @@ editable model, :name # type: "text", title: "Mailing list name"
192
196
  editable model, :enabled # type: "select", title: "Enabled", source: [ "Active", "Disabled" ]
193
197
  ```
194
198
 
199
+ ### Examples
200
+
201
+ Gem also contains demo application with integrated x-editable
202
+
203
+ ```
204
+ cd test/dummy
205
+ rake db:migrate
206
+ rake db:seed
207
+ rails g x_editable_rails:install # optional, it generate config example
208
+ rails s
209
+ ```
210
+
195
211
  ## Contributing
196
212
 
197
213
  1. Fork it
@@ -0,0 +1,12 @@
1
+ module XEditableRails
2
+ module Generators
3
+ class InstallGenerator < Rails::Generators::Base
4
+ source_root File.expand_path('../templates', __FILE__)
5
+
6
+ desc 'Copy example of x-editable config'
7
+ def copy_x_editable_yml
8
+ template 'x-editable.yml', 'config/x-editable.yml'
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,19 @@
1
+ # More informations you can find here: https://github.com/werein/x-editable-rails
2
+ class_options:
3
+ MailingList:
4
+ name: Mailing list name
5
+ enabled:
6
+ type: select
7
+ source:
8
+ - Active
9
+ - Disabled
10
+ reply_email:
11
+ type: email
12
+ title: Reply-to email
13
+ User:
14
+ email:
15
+ type: email
16
+ password:
17
+ type: password
18
+ mailing_lists:
19
+ type: select
@@ -17,20 +17,14 @@ module X
17
17
  end
18
18
 
19
19
  def options
20
- default_options.deep_merge custom_options
21
- end
22
-
23
- def default_options
24
- @defaults ||= begin
25
- options = load_yaml_file File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "config", "x-editable.yml"))
26
- format_class_options! options
27
- end
28
- end
29
-
30
- def custom_options
31
- @custom_options ||= begin
32
- options = load_yaml_file ::Rails.root.join("config", "x-editable.yml")
33
- format_class_options! options
20
+ config_fn = ::Rails.root.join("config", "x-editable.yml")
21
+ if File.file?(config_fn)
22
+ @options ||= begin
23
+ options = load_yaml_file config_fn
24
+ format_class_options! options
25
+ end
26
+ else
27
+ @options = {}
34
28
  end
35
29
  end
36
30
 
@@ -1,7 +1,7 @@
1
1
  module X
2
2
  module Editable
3
3
  module Rails
4
- VERSION = "1.5.0"
4
+ VERSION = "1.5.1"
5
5
  end
6
6
  end
7
7
  end
@@ -1,40 +1,55 @@
1
1
  jQuery ($) ->
2
2
  EditableForm = $.fn.editableform.Constructor
3
3
  EditableForm.prototype.saveWithUrlHook = (value) ->
4
- originalUrl = @options.url
5
- model = @options.model
6
- nestedName = @options.nested
7
- nestedId = @options.nid
8
- nestedLocale = @options.locale
4
+ originalUrl = @options.url
5
+ model = @options.model
6
+ nestedName = @options.nested
7
+ nestedId = @options.nid
8
+ nestedLocale = @options.locale
9
+
9
10
  @options.url = (params) =>
10
11
  if typeof originalUrl == 'function'
11
12
  originalUrl.call(@options.scope, params)
12
13
  else if originalUrl? && @options.send != 'never'
13
14
  myName = params.name
15
+
14
16
  if typeof params.value == 'string'
15
17
  myValue = params.value.replace(/(\r\n|\n|\r)/gm,"<br/>")
16
18
  else
17
19
  myValue = params.value
20
+
21
+ # if there are no values in a list, add a blank value so Rails knows all values were removed
22
+ if Object.prototype.toString.call(params.value) == '[object Array]' && params.value.length == 0
23
+ params.value.push("")
24
+
18
25
  obj = {}
26
+
19
27
  if nestedName
20
- nested = {}
21
- nested[myName] = myValue
22
- nested['id'] = nestedId
28
+ nested = {}
29
+ nested[myName] = myValue
30
+ nested['id'] = nestedId
31
+
23
32
  if nestedLocale
24
33
  nested['locale'] = nestedLocale
34
+
25
35
  obj[nestedName + '_attributes'] = nested
26
36
  else
27
37
  obj[myName] = myValue
38
+
28
39
  params[model] = obj
40
+
29
41
  delete params.name
30
42
  delete params.value
31
43
  delete params.pk
44
+
32
45
  $.ajax($.extend({
33
- url : originalUrl
34
- data : params
35
- type : 'PUT'
46
+ url: originalUrl
47
+ data: params
48
+ type: 'PUT'
36
49
  dataType: 'json'
37
50
  }, @options.ajaxOptions))
51
+
38
52
  @saveWithoutUrlHook(value)
53
+
39
54
  EditableForm.prototype.saveWithoutUrlHook = EditableForm.prototype.save
40
55
  EditableForm.prototype.save = EditableForm.prototype.saveWithUrlHook
metadata CHANGED
@@ -1,37 +1,37 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: x-editable-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 1.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jiri Kolarik
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-02 00:00:00.000000000 Z
11
+ date: 2013-11-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: bundler
14
+ name: railties
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - '>='
18
18
  - !ruby/object:Gem::Version
19
- version: '1.3'
20
- type: :development
19
+ version: '0'
20
+ type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - '>='
25
25
  - !ruby/object:Gem::Version
26
- version: '1.3'
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: rake
28
+ name: cancan
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - '>='
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
- type: :development
34
+ type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
@@ -39,27 +39,27 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: railties
42
+ name: rails
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ~>
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :runtime
47
+ version: '4.0'
48
+ type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ~>
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: '4.0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: cancan
56
+ name: sqlite3
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - '>='
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
- type: :runtime
62
+ type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
@@ -73,6 +73,8 @@ executables: []
73
73
  extensions: []
74
74
  extra_rdoc_files: []
75
75
  files:
76
+ - lib/generators/x_editable_rails/install_generator.rb
77
+ - lib/generators/x_editable_rails/templates/x-editable.yml
76
78
  - lib/x-editable-rails/configuration.rb
77
79
  - lib/x-editable-rails/version.rb
78
80
  - lib/x-editable-rails/view_helpers.rb
@@ -110,6 +112,7 @@ post_install_message:
110
112
  rdoc_options: []
111
113
  require_paths:
112
114
  - lib
115
+ - vendor
113
116
  required_ruby_version: !ruby/object:Gem::Requirement
114
117
  requirements:
115
118
  - - '>='
@@ -127,4 +130,3 @@ signing_key:
127
130
  specification_version: 4
128
131
  summary: X-editable for Rails
129
132
  test_files: []
130
- has_rdoc: