abracadabra 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0313990291cc523dfc6808622a86e8c7eccd38e2
4
+ data.tar.gz: 20e68d186cbddebed1443543d45603c2dae9b924
5
+ SHA512:
6
+ metadata.gz: 9e388c41997ce8dc45c4398b694b829db9249c51e4536e7c8973e3fe2a73ec75bae4163f54a26b7992df15ede1bc09638bdb28b2ede43e99e04a76f3b94a970b
7
+ data.tar.gz: fbdf1360e53ed87c8c028b3814996d5b2a9e5b0abc15a0e2d36a8ea05b96b2080ec3255f5f0d5de793dcdabb2c9c0d986160b855a9cc06086d47304183ae6362
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 abracadabra.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Trevor Hinesley
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,70 @@
1
+ # Abracadabra
2
+
3
+ A lightweight gem for swapping out text with a fully-compliant Rails form in one click.
4
+
5
+ Much of the concepts and html mark-up were taken from the awesome [x-editable](http://vitalets.github.io/x-editable/) plugin and the Rails version of this, [x-editable-rails](https://github.com/werein/x-editable-rails). However, this was written from the ground up and uses fully Rails-compliant forms without hacking into x-editable's core files, or overriding them.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'abracadabra'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install abracadabra
20
+
21
+ ## Usage
22
+
23
+ In your `application.css`, AFTER Bootstrap (currently only supports Bootstrap), include the css file:
24
+
25
+ ```css
26
+ *= require abracadabra
27
+ ```
28
+
29
+ In your `application.js`, AFTER Jquery (required), include the javascript file:
30
+
31
+ ```js
32
+ //= require abracadabra
33
+ ```
34
+
35
+ ## Helpers
36
+
37
+ The bread and butter of abracadabra is its helper, `click_to_edit`. Its pretty much as readable as it gets:
38
+
39
+ ```ruby
40
+ <%= click_to_edit @user, path: user_path(@user), attribute: :name %>
41
+ ```
42
+
43
+ When a user clicks the link generated by this helper, a form with a text field input will replace the link. It's fully Rails compliant, and looks identical to a `form_for` with `remote: true`. Currently, it only responds to javascript, but other datatypes will be supported soon. Here's what it looks like:
44
+
45
+ [Video of abracadabra in action!](http://recordit.co/cpwdWIyEN4)
46
+
47
+ The first parameter is the object to be edited, and the only other required parameters are `path` and `attribute`. `path` specifies where the form will be submitted, and `attribute` specifies the column being updated.
48
+
49
+ It accepts the following optional hash keys (more will be added soon):
50
+
51
+ ```ruby
52
+ class: "my-class"
53
+ # A class to be added to the text input of the form.
54
+
55
+ value: "blah"
56
+ # An alternate value, other than what object.attribute would return.
57
+
58
+ method: "patch"
59
+ # HTTP REST method to use. Use anything but "get".
60
+ ```
61
+
62
+ ## Future & Contributing
63
+
64
+ I would love anyone to add date pickers and other alternate field types to this. It would be nice to respond to more than just javascript as well (very simple to implement). Any other ideas, feel free to contribute!
65
+
66
+ 1. Fork it ( http://github.com/<my-github-username>/abracadabra/fork )
67
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
68
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
69
+ 4. Push to the branch (`git push origin my-new-feature`)
70
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'abracadabra/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "abracadabra"
8
+ spec.version = Abracadabra::Rails::VERSION
9
+ spec.authors = ["Trevor Hinesley"]
10
+ spec.email = ["trevor.hinesley@gmail.com"]
11
+ spec.summary = %q{A lightweight gem for swapping out text with a fully-compliant Rails form in one click using JQuery.}
12
+ spec.description = %q{Abracadabra: #{spec.summary}}
13
+ spec.homepage = "https://github.com/TrevorHinesley/abracadabra"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "rails", ">= 3.0.0"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.5"
24
+ spec.add_development_dependency "rake"
25
+ end
@@ -0,0 +1,43 @@
1
+ $(function() {
2
+ $("body").on("ajax:success", ".abracadabra-form", function(e) {
3
+ $(e.target).find(".abracadabra-cancel").click();
4
+ })
5
+
6
+ $("body").on("click", ".abracadabra-cancel", function() {
7
+ container = $(this).closest(".abracadabra-container");
8
+ value = $(this).parents(".abracadabra-buttons").siblings().find("input").val();
9
+ container.siblings(".abracadabra").text(value).show();
10
+ $(this).closest(".abracadabra-container").remove();
11
+ });
12
+
13
+ $("body").on("keydown", ".abracadabra-input input", function(e) {
14
+ if (e.which == 9)
15
+ {
16
+ e.preventDefault();
17
+ $(this.form).submit();
18
+ }
19
+ });
20
+
21
+ $(".abracadabra").on("click", function() {
22
+ link = $(this);
23
+ link.hide();
24
+ path = link.data("path");
25
+ attribute = link.data("attribute");
26
+ form_method = link.data("method");
27
+ instance_class = link.data("class");
28
+ input_value = link.text();
29
+ input_id = instance_class + "_" + attribute;
30
+ input_name = instance_class + "[" + attribute + "]";
31
+
32
+ buttons = "<button type='submit' class='btn btn-primary abracadabra-submit'><i class='fa fa-check'></i></button><button type='button' class='btn abracadabra-cancel'><i class='fa fa-times'></i></button>";
33
+ open_form_tag = "<form accept-charset='UTF-8' action='" + path + "' data-remote='true' class='form-inline abracadabra-form' method='post'>";
34
+ hidden_method_tags = "<div style='display:none;'><input name='utf8' type='hidden' value='&#10003;'><input name='_method' type='hidden' value='" + form_method + "'></div>";
35
+ input = "<input type='text' class='form-control' id='" + input_id + "' name='" + input_name + "' value='" + input_value + "'>";
36
+
37
+ html = "<span class='abracadabra-container abracadabra-inline'>" + open_form_tag + hidden_method_tags;
38
+ html += "<div class='control-group'><div><div class='abracadabra-input'>" + input + "</div>";
39
+ html += "<div class='abracadabra-buttons'>" + buttons + "</div></div></form></span>";
40
+
41
+ link.after(html);
42
+ });
43
+ });
@@ -0,0 +1,21 @@
1
+ .abracadabra {
2
+ border-bottom: 1px dashed;
3
+ color: #428bca;
4
+ }
5
+
6
+ .abracadabra:hover {
7
+ text-decoration: none;
8
+ color: darken(#428bca, 10%);
9
+ }
10
+
11
+ .abracadabra-container { display: block; }
12
+
13
+ .abracadabra-container > form > .control-group > div > .abracadabra-input {
14
+ width: 60%;
15
+ display: inline-block;
16
+ }
17
+
18
+ .abracadabra-container > form > .control-group > div > .abracadabra-buttons {
19
+ width: 40%;
20
+ display: inline-block;
21
+ }
@@ -0,0 +1,13 @@
1
+ module Abracadabra
2
+ module Rails
3
+ module ViewHelper
4
+ def click_to_edit(instance, options)
5
+ instance_class = instance.class.to_s.underscore
6
+ link_class = "#{options[:class]} abracadabra".strip
7
+ value = options[:value] || instance.send(options[:attribute])
8
+ method = options[:method] || "patch"
9
+ "<a href='javascript:void(0)' class='#{link_class}' data-path='#{options[:path]}' data-method='#{method}' data-attribute='#{options[:attribute]}' data-class='#{instance_class}'>#{value}</a>".html_safe
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,6 @@
1
+ module Abracadabra
2
+ module Rails
3
+ class Engine < ::Rails::Engine
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ module Abracadabra
2
+ module Rails
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
@@ -0,0 +1,2 @@
1
+ require "abracadabra/version"
2
+ require "abracadabra/engine" if defined?(::Rails)
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: abracadabra
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Trevor Hinesley
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-03-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 3.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 3.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.5'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: 'Abracadabra: #{spec.summary}'
56
+ email:
57
+ - trevor.hinesley@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - abracadabra.gemspec
68
+ - app/assets/javascripts/abracadabra.js
69
+ - app/assets/stylesheets/abracadabra.css
70
+ - app/helpers/abracadabra/rails/view_helper.rb
71
+ - lib/abracadabra.rb
72
+ - lib/abracadabra/engine.rb
73
+ - lib/abracadabra/version.rb
74
+ homepage: https://github.com/TrevorHinesley/abracadabra
75
+ licenses:
76
+ - MIT
77
+ metadata: {}
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubyforge_project:
94
+ rubygems_version: 2.2.2
95
+ signing_key:
96
+ specification_version: 4
97
+ summary: A lightweight gem for swapping out text with a fully-compliant Rails form
98
+ in one click using JQuery.
99
+ test_files: []