dynaspan 0.1.1 → 0.1.2.beta1

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: 594c27faf04b8c51de65d4f8e6101d0062b9b863
4
- data.tar.gz: 6e5a1b2b1a091dc17f1e86a0d98af328caa8eb42
3
+ metadata.gz: bd231d2af63a1f712b0d8d1f69bc3039b1cdda40
4
+ data.tar.gz: e444a9c8374f08f0a61eeb927c83daf6138ca4c7
5
5
  SHA512:
6
- metadata.gz: 616eadcaff9b70872a1776a62f0879a3696e1609c6bbf045ed57370a279f89711dfad0979e7a52d371ebeee0c1185f79f1f31b2c105b82ac1a29ed1cf7e471b4
7
- data.tar.gz: d663df0da430cab97a4c0b280276db167349eef59b252ab5cb4d42e9680d0b1f6109b03742e34de49f37e0417be7a5fd3fb0f14e05810068a148fb4f5b05d867
6
+ metadata.gz: 5e187c11964538324ffb48e1abce8a45ac140dfb05c6a2e9fab3924dcb784047979b97957052052a633a0133b4543b50a38e781f1d5414118c2363a7dcee6252
7
+ data.tar.gz: ca711610f0de1fb36aeeb3fc845bdcef796ca73a6677c1032d7fda89222327419ddb899c28b172a2398cdebaed54c460286da45aca80a05343cde1b0bd07c745
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (C) 2014 by Daniel P. Clark
3
+ Copyright (C) 2014-2015 by Daniel P. Clark
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,5 +1,6 @@
1
1
  ##Dynaspan
2
2
  [![Gem Version](https://badge.fury.io/rb/dynaspan.svg)](http://badge.fury.io/rb/dynaspan)
3
+ [![Code Climate](https://codeclimate.com/github/danielpclark/dynaspan/badges/gpa.svg)](https://codeclimate.com/github/danielpclark/dynaspan)
3
4
  #####[JSFiddle Demo](http://jsfiddle.net/680v09y8/)
4
5
 
5
6
  Dynaspan is an AJAX tool for Rails to update one field of any object without interfering with your website experience. The user will see the web page as normal text. Where ever you've placed a Dynaspan field people can click on the text and it transforms into text entry. As soon as the person moves away from that entry it sends the update to the server.
@@ -8,39 +9,73 @@ Dynaspan also accepts updating an attribute for a nested object, but only 1 leve
8
9
 
9
10
  ###Installation
10
11
 
11
- - [ ] Add `gem 'dynaspan'` to your Gemfile.
12
- - [ ] Run `bundle`.
13
- - [ ] Next add `include Dynaspan::ApplicationHelper` inside your **ApplicationHelper** module.
14
- - [ ] Add `//= require dynaspan/dynaspan` to your **application.js** file.
15
- - [ ] And it's installed!
12
+ - [ ] Add `gem 'dynaspan'` to your Gemfile
13
+ - [ ] Run `bundle`
14
+ - [ ] Next add `include Dynaspan::ApplicationHelper` inside your **ApplicationHelper** module
15
+ - [ ] Add `//= require dynaspan/dynaspan` to your **application.js** file
16
16
 
17
- ###Usage
17
+ And it's installed!
18
18
 
19
- Example #1:
19
+ ###Usage
20
20
 
21
- dynaspan_text_field(@article, comment, :note, '[edit]')
22
-
23
- Example #2:
21
+ Simple example:
22
+ ```ruby
23
+ dynaspan_text_field(user, :name)
24
+ ```
25
+ And that's it. As long as you have a User object with a name field, this will update through
26
+ the UserController's update method. **user** is an User Object instance eg: `user = User.first`.
24
27
 
25
- dynaspan_text_field(profile, profile.websites, :url, '[edit]',
26
- {
27
- hidden_fields: {page_name: 'page2'},
28
- callback_on_update: "alert('Awesome!');"
29
- }
30
- )
28
+ ---
31
29
 
30
+ Polymorphic/Nested Example #1:
31
+ ```ruby
32
+ dynaspan_text_field(@article, comment, :note, '[edit]')
33
+ ```
34
+ Polymorphic/Nested Example #2:
35
+ ```ruby
36
+ dynaspan_text_field(profile, profile.websites, :url, '[edit]',
37
+ {
38
+ hidden_fields: {page_name: 'page2'},
39
+ callback_on_update: "alert('Awesome!');"
40
+ }
41
+ )
42
+ ```
32
43
  This will show the value of note in the comment object as plain text. It can be clicked on to instantly become a text field input. And once unselected the `@article` object will update with its nested attribute object `comment` and its new value in the `note` attribute.
33
44
 
34
45
  You can use either `dynaspan_text_field` or `dynaspan_text_area` in any of your views. There are two mandatory parameters. The first is a the main Object model instance you will be updating. And the other mandatory field is the symbol of the attribute to update. There are two optional fields. The first is the nested attribute object which will have its field updated. And the last is the optional text for `[edit]`-ing (clicking on to edit which is useful for blank fields).
46
+ ```ruby
47
+ dynaspan_text_field(Object,OptionalNestedObject,SymField,OptionalEditText,OptionalOptionsHash)
48
+ dynaspan_text_area(Object,OptionalNestedObject,SymField,OptionalEditText,OptionalOptionsHash)
49
+ ```
50
+ The order is important. And yes it does NOT change even if you just do:
51
+ ```ruby
52
+ dynaspan_text_field(Object,SymField)
53
+ ```
54
+ It is unconventional but the order remains the same despite the optional fields.
35
55
 
36
- dynaspan_text_field(Object,OptionalNestedObject,SymField,OptionalEditText,OptionalOptionsHash)
37
- dynaspan_text_area(Object,OptionalNestedObject,SymField,OptionalEditText,OptionalOptionsHash)
56
+ ###Parameters
38
57
 
39
- The order is important. And yes it does NOT change even if you just do:
58
+ The **first** parameter will always be the Object that will have its update method called. It must be an instance of the Object.
59
+ For example current_user being an instance of User.
40
60
 
41
- dynaspan_text_field(Object,SymField)
61
+ The **second** parameter can be a symbol of the field you want to update on the main Object from the first parameter.
62
+
63
+ The **second** field can also be a has_one or has_many subset of the first argument moving the symbol to modify to the **third** argument.
64
+ For example **dynaspan_text_field(author, author.stories, :title)**. This works as a nested attribute so it includes Polymorphic Objects.
65
+
66
+ The last two parameters can be edit text, and then additional options (in that order). Both are optional. The edit text
67
+ is a way to be able to click somewhere to open up the input to initially enter text.
68
+
69
+ The options Hash currently has three options.
70
+
71
+ - **:hidden_fields** will put in as many hidden fields as you include in a Hash with key->value matching to name->value
72
+ - **:callback_on_update** is a no frills callback. It runs whatever command you give it whenever Dynaspan submits an update
73
+ to the server
74
+ - **:callback_with_values** will allow you to put a JavaScript command you want called on update and include as many parameters
75
+ as you'd like. It will dynamically append a last parameter which is a Hash of two values. The first is the CSS selector id
76
+ of the Dynaspan block that just performed the action, the second value is the actual text that was entered. The keys in this
77
+ Hash are **ds_selector** and **ds_input**
42
78
 
43
- It is unconventional but the order remains the same despite the optional fields.
44
79
 
45
80
  ###How it updates
46
81
 
@@ -81,18 +116,18 @@ calling parents with selectors. Example usage:
81
116
 
82
117
  Added a JavaScript callback that will **append** a Hash/Dictionary of the updated Dynaspan Object to the end of your
83
118
  functions parameters. The method is named **callback_with_values**.
84
-
85
- {
86
- callback_with_values: "console.log();"
87
- }
88
-
119
+ ```ruby
120
+ {
121
+ callback_with_values: "console.log();"
122
+ }
123
+ ```
89
124
  This will be called everytime the Dynaspan field submits and it will **inject** the following result **as the last parameter**:
90
-
91
- {
92
- ds_selector: "dyna_span_unique_label<#>",
93
- ds_input: "the entered text from the input field"
94
- }
95
-
125
+ ```ruby
126
+ {
127
+ ds_selector: "dyna_span_unique_label<#>",
128
+ ds_input: "the entered text from the input field"
129
+ }
130
+ ```
96
131
  ####Version 0.1.0
97
132
 
98
133
  Added the same hidden_fields from version 0.0.8 to support non-nested Objects. You can use them now on anything.
@@ -101,23 +136,23 @@ Added the same hidden_fields from version 0.0.8 to support non-nested Objects.
101
136
 
102
137
  JavaScript callback option now available. Whenever the Dynaspan field is submitted you can have Dynaspan call
103
138
  your own JavaScript method.
104
-
105
- {
106
- callback_on_update: "someMethod('some-relative-instance-value');"
107
- }
108
-
139
+ ```ruby
140
+ {
141
+ callback_on_update: "someMethod('some-relative-instance-value');"
142
+ }
143
+ ```
109
144
  ####Version 0.0.8
110
145
 
111
146
  You can now provide an option hash as a last parameter. Current
112
147
  valid options only include:
113
-
114
- {
115
- hidden_fields: { label: "value" }
116
- }
117
-
148
+ ```ruby
149
+ {
150
+ hidden_fields: { label: "value" }
151
+ }
152
+ ```
118
153
  You can add as many hidden fields to your Dynaspan objects as you'd like.
119
154
 
120
- >NOTE: In this version hidden fields only apply for nested attributes.
155
+ >NOTE: In this version hidden fields only applies to nested attributes.
121
156
 
122
157
  Also the id parameter will only be passed to the server if it exists. (No more empty
123
158
  string for id.) This allows you to create "new" polymorphic child objects with Dynaspan.
@@ -126,7 +161,7 @@ string for id.) This allows you to create "new" polymorphic child objects with
126
161
 
127
162
  The MIT License (MIT)
128
163
 
129
- Copyright (C) 2014 by Daniel P. Clark
164
+ Copyright (C) 2014-2015 by Daniel P. Clark
130
165
 
131
166
  Permission is hereby granted, free of charge, to any person obtaining a copy
132
167
  of this software and associated documentation files (the "Software"), to deal
@@ -28,21 +28,28 @@ module Dynaspan
28
28
  raise 'You did not provide a symbol for the form field.'
29
29
  end
30
30
  edit_text = nil unless edit_text.is_a? String
31
- options = (parameters[-1].is_a?(Hash) ? parameters[-1] : {})
31
+ options = ActiveSupport::HashWithIndifferentAccess.new(parameters[-1].is_a?(Hash) ? parameters[-1] : {})
32
32
  options.default = nil
33
+ options[:form_for] = ActiveSupport::HashWithIndifferentAccess.new(options[:form_for])
34
+ options[:form_for].reverse_merge!(
35
+ method: :patch,
36
+ remote: true,
37
+ authenticity_token: true
38
+ )
33
39
  render(
34
40
  partial: "dynaspan/dynaspan_text_#{kind}",
35
41
  locals: {
36
42
  master_ds_object: master_ds_object,
37
43
  attr_object: attr_object,
38
44
  attrib: attrib,
39
- unique_ref_id: dynaspan_counter,
45
+ unique_ref_id: options.fetch(:unique_id) { dynaspan_counter },
40
46
  dyna_span_edit_text: edit_text,
41
47
  hidden_fields: options[:hidden_fields],
42
48
  ds_callback_on_update: options[:callback_on_update],
43
- ds_callback_with_values: options[:callback_with_values]
49
+ ds_callback_with_values: options[:callback_with_values],
50
+ form_for_options: options[:form_for]
44
51
  }
45
52
  )
46
53
  end
47
54
  end
48
- end
55
+ end
@@ -2,7 +2,7 @@
2
2
  <div id="dyna_span_block<%= unique_ref_id %>" <%= "data-ds-callback-on-update=\"#{ds_callback_on_update}\" " if ds_callback_on_update.present? %> <%= "data-ds-callback-with-values=\"#{ds_callback_with_values}\" " if ds_callback_with_values.present? %>class='dyna-span<%= ' ds-content-present' if (attr_object.try(attrib).present? || master_ds_object.try(attrib).present?) %>'>
3
3
  <%= hidden_field_tag "last_dyna_span_val_#{unique_ref_id}", attr_object.try(attrib) || master_ds_object.try(attrib), id: "last_dyna_span_val_#{unique_ref_id}" %>
4
4
  <div id="<%= "dyna_span_div#{unique_ref_id}" %>" style="display:none;">
5
- <%= form_for(master_ds_object, method: :patch, remote: true, authenticity_token: true) do |f| %>
5
+ <%= form_for(master_ds_object, **form_for_options.symbolize_keys) do |f| %>
6
6
  <% if master_ds_object.nested_attributes_options.keys.any? {|i| i.to_s.=~(/#{attr_object.class.try(:model_name).try(:i18n_key).to_s}/) || i.to_s.=~(/#{attr_object.class.try(:table_name)}/) } and !attr_object.nil? %>
7
7
  <%= f.fields_for master_ds_object.nested_attributes_options.keys.select {|i| i.to_s.=~(/#{attr_object.class.model_name.i18n_key.to_s}/) || i.to_s.=~(/#{attr_object.class.table_name}/) }.first, attr_object do |a|%>
8
8
  <%= a.hidden_field(:id, value: attr_object.id) if attr_object.id.present? %>
@@ -21,4 +21,4 @@
21
21
  </div>
22
22
  <%= content_tag 'span', attr_object.try(attrib) || master_ds_object.try(attrib), id: "dyna_span_span#{unique_ref_id}", onclick: "$().dynaspan.upShow('#{unique_ref_id}');", class: 'dyna-span dyna-span-text', style: 'display:block;' %>
23
23
  <%= content_tag('div', dyna_span_edit_text, class: 'dyna-span-edit-text pull-right', onclick: "$().dynaspan.upShow('#{unique_ref_id}');", style: 'cursor:pointer;') %>
24
- </div>
24
+ </div>
@@ -2,7 +2,7 @@
2
2
  <div id="dyna_span_block<%= unique_ref_id %>" <%= "data-ds-callback-on-update=\"#{ds_callback_on_update}\" " if ds_callback_on_update.present? %> <%= "data-ds-callback-with-values=\"#{ds_callback_with_values}\" " if ds_callback_with_values.present? %>class='dyna-span<%= ' ds-content-present' if (attr_object.try(attrib).present? || master_ds_object.try(attrib).present?) %>'>
3
3
  <%= hidden_field_tag "last_dyna_span_val_#{unique_ref_id}", attr_object.try(attrib) || master_ds_object.try(attrib), id: "last_dyna_span_val_#{unique_ref_id}" %>
4
4
  <div id="<%= "dyna_span_div#{unique_ref_id}" %>" style="display:none;">
5
- <%= form_for(master_ds_object, method: :patch, remote: true, authenticity_token: true) do |f| %>
5
+ <%= form_for(master_ds_object, **form_for_options.symbolize_keys) do |f| %>
6
6
  <% if master_ds_object.nested_attributes_options.keys.any? {|i| i.to_s.=~(/#{attr_object.class.try(:model_name).try(:i18n_key).to_s}/) || i.to_s.=~(/#{attr_object.class.try(:table_name)}/) } and !attr_object.nil? %>
7
7
  <%= f.fields_for master_ds_object.nested_attributes_options.keys.select {|i| i.to_s.=~(/#{attr_object.class.model_name.i18n_key.to_s}/) || i.to_s.=~(/#{attr_object.class.table_name}/) }.first, attr_object do |a|%>
8
8
  <%= a.hidden_field(:id, value: attr_object.id) if attr_object.id.present? %>
@@ -21,4 +21,4 @@
21
21
  </div>
22
22
  <%= content_tag 'span', attr_object.try(attrib) || master_ds_object.try(attrib), id: "dyna_span_span#{unique_ref_id}", onclick: "$().dynaspan.upShow('#{unique_ref_id}');", class: 'dyna-span dyna-span-text', style: 'display:block;' %>
23
23
  <%= content_tag('div', dyna_span_edit_text, class: 'dyna-span-edit-text pull-right', onclick: "$().dynaspan.upShow('#{unique_ref_id}');", style: 'cursor:pointer;') %>
24
- </div>
24
+ </div>
data/dynaspan.gemspec CHANGED
@@ -13,6 +13,8 @@ Gem::Specification.new do |gem|
13
13
  gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
14
  gem.name = 'dynaspan'
15
15
  gem.require_paths = ['lib']
16
- gem.required_ruby_version = '~> 2.0'
16
+ gem.required_ruby_version = '>= 2.0'
17
17
  gem.version = Dynaspan::VERSION
18
+ gem.requirements << "jQuery"
19
+ gem.requirements << "Rails"
18
20
  end
@@ -1,3 +1,3 @@
1
1
  module Dynaspan
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2.beta1'
3
3
  end
data/lib/dynaspan.rb CHANGED
@@ -1,12 +1,32 @@
1
1
  require 'dynaspan/version'
2
2
 
3
+
3
4
  module Dynaspan
4
- case ::Rails.version.to_s
5
- when /^4/
6
- require 'dynaspan/engine'
7
- when /^3\.[12]/
8
- require 'dynaspan/engine3'
9
- when /^3\.[0]/
10
- require 'dynaspan/railtie'
5
+ ASSETS = %W(dynaspan/*.js dynaspan/*.css dynaspan/*.png dynaspan/*.gif dynaspan/*.html dynaspan/*.md)
6
+ INITIALIZER = "initializer 'dynaspan.assets.precompile', group: :all do |app| app.config.assets.precompile += Dynaspan::ASSETS; end"
7
+
8
+ class Engine < ::Rails::Engine
9
+ isolate_namespace Dynaspan
10
+
11
+ eval Dynaspan::INITIALIZER
12
+
13
+ initializer 'dynaspan.action_controller' do |app|
14
+ ActiveSupport.on_load :action_controller do
15
+ helper Dynaspan::ApplicationHelper
16
+ end
17
+ end
18
+
19
+ if ::Rails.version.to_s =~ /^4/
20
+ rake_tasks do
21
+ load "dynaspan/tasks.rake"
22
+ end
23
+ end
24
+ end
25
+
26
+ if ::Rails.version.to_s =~ /^3\.[0]/
27
+ class Railtie < ::Rails::Railtie
28
+ eval Dynaspan::INITIALIZER
29
+ end
11
30
  end
12
31
  end
32
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dynaspan
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2.beta1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel P. Clark
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-31 00:00:00.000000000 Z
11
+ date: 2015-05-28 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: In place text editing with AJAX substituting text to input field.
14
14
  email:
@@ -30,9 +30,6 @@ files:
30
30
  - lib/assets/javascripts/dynaspan-jquery.js
31
31
  - lib/assets/javascripts/dynaspan/basepath.js.erb
32
32
  - lib/dynaspan.rb
33
- - lib/dynaspan/engine.rb
34
- - lib/dynaspan/engine3.rb
35
- - lib/dynaspan/railtie.rb
36
33
  - lib/dynaspan/tasks.rake
37
34
  - lib/dynaspan/version.rb
38
35
  - vendor/assets/javascripts/dynaspan/dynaspan.js
@@ -46,17 +43,19 @@ require_paths:
46
43
  - lib
47
44
  required_ruby_version: !ruby/object:Gem::Requirement
48
45
  requirements:
49
- - - "~>"
46
+ - - ">="
50
47
  - !ruby/object:Gem::Version
51
48
  version: '2.0'
52
49
  required_rubygems_version: !ruby/object:Gem::Requirement
53
50
  requirements:
54
- - - ">="
51
+ - - ">"
55
52
  - !ruby/object:Gem::Version
56
- version: '0'
57
- requirements: []
53
+ version: 1.3.1
54
+ requirements:
55
+ - jQuery
56
+ - Rails
58
57
  rubyforge_project:
59
- rubygems_version: 2.4.5
58
+ rubygems_version: 2.4.6
60
59
  signing_key:
61
60
  specification_version: 4
62
61
  summary: Text to AJAX editing in place.
@@ -1,26 +0,0 @@
1
- module Dynaspan
2
- class Engine < ::Rails::Engine
3
- isolate_namespace Dynaspan
4
-
5
- initializer 'dynaspan.assets.precompile', group: :all do |app|
6
- app.config.assets.precompile += %W(
7
- dynaspan/*.js
8
- dynaspan/*.css
9
- dynaspan/*.png
10
- dynaspan/*.gif
11
- dynaspan/*.html
12
- dynaspan/*.md
13
- )
14
- end
15
-
16
- initializer 'dynaspan.action_controller' do |app|
17
- ActiveSupport.on_load :action_controller do
18
- helper Dynaspan::ApplicationHelper
19
- end
20
- end
21
-
22
- rake_tasks do
23
- load "dynaspan/tasks.rake"
24
- end
25
- end
26
- end
@@ -1,23 +0,0 @@
1
- module Dynaspan
2
- class Engine < ::Rails::Engine
3
- isolate_namespace Dynaspan
4
-
5
- initializer 'dynaspan.assets.precompile', group: :all do |app|
6
- app.config.assets.precompile += %W(
7
- dynaspan/*.js
8
- dynaspan/*.css
9
- dynaspan/*.png
10
- dynaspan/*.gif
11
- dynaspan/*.html
12
- dynaspan/*.md
13
- )
14
- end
15
-
16
- initializer 'dynaspan.action_controller' do |app|
17
- ActiveSupport.on_load :action_controller do
18
- helper Dynaspan::ApplicationHelper
19
- end
20
- end
21
-
22
- end
23
- end
@@ -1,14 +0,0 @@
1
- module Dynaspan
2
- class Railtie < ::Rails::Railtie
3
- initializer 'dynaspan.assets.precompile', group: :all do |app|
4
- app.config.assets.precompile += %W(
5
- dynaspan/*.js
6
- dynaspan/*.css
7
- dynaspan/*.png
8
- dynaspan/*.gif
9
- dynaspan/*.html
10
- dynaspan/*.md
11
- )
12
- end
13
- end
14
- end