editable 0.0.0 → 0.1.0

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: b3d10ffb7bd0eb36c98ac8c19c2753747d1eec99
4
- data.tar.gz: a64b7a0d7397b82bbdcff7e28ee2c00fc069d866
3
+ metadata.gz: 95c60a9ef6c324b8ae134754a2b648726c774623
4
+ data.tar.gz: 41f86e7439280ebc7dca993be6840cc926c9ed35
5
5
  SHA512:
6
- metadata.gz: d740a4967ddea950498d7e531e7e59bb95542093d5a5e1767cdc9372d8d37b343e01c56996ee3f53548f8a2bedaadcb59349719eed5bdd6f60447a88a2f17268
7
- data.tar.gz: c08f8bbad9408acaf6fde834b79c71c603c2745f5fff0d345d9981246a5b6957dfe0073b54e9c74c3c2a4d420c8942577d7472b992f9593a98dfc0880f69b492
6
+ metadata.gz: e2b4b18cf90e94e54c02e3864d28b366803145af7821f27e4f16939890ded1fdad77c4c9c22aae79c5354679e0b859f0a7f16414e368ef2956c614049c3db280
7
+ data.tar.gz: 198323accddf666cdffc7c028346ca02a377ea25f139f3bed224e74fb50003e27a14e86fdf28b43d3e698d717088dd7fbcef772e8aba6c35788403859dc45a8c
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 D F
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # editable-rails
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/testgem`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'testgem'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install testgem
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/testgem.
data/lib/editabe.rb ADDED
@@ -0,0 +1,44 @@
1
+ require "editable/version"
2
+
3
+ module Editable
4
+ module Rails
5
+ class Engine < ::Rails::Engine
6
+ end
7
+ end
8
+
9
+ module EditableHelper
10
+ def editable(
11
+ object,
12
+ method,
13
+ display: :name,
14
+ display_with: nil,
15
+ tag: :span,
16
+ trigger: :auto,
17
+ label: :name
18
+ )
19
+
20
+ value = object.send(method)
21
+ model = object.class.model_name.singular
22
+ id = object.send object.class.primary_key
23
+ url = url_for(object)
24
+ identifier = "#{method}_#{model}_#{id}"
25
+ datatype = object.class.columns_hash[method.to_s].type
26
+ display_value = display_with ? send(display_with, value) : value
27
+
28
+ "<#{tag.to_s} class=\"editable\"\
29
+ data-editable=\"#{identifier}\"\
30
+ data-editable-model=\"#{model}\"\
31
+ data-editable-id=\"#{id}\"\
32
+ data-editable-method=\"#{method}\"\
33
+ data-editable-datatype=\"#{datatype}\"\
34
+ data-editable-value=\"#{value}\"\
35
+ data-editable-url=\"#{url}\"\
36
+ data-editable-display-with=\"#{display_with}\">
37
+ #{display_value}
38
+ </#{tag.to_s}>
39
+ ".html_safe
40
+ end
41
+ end
42
+ end
43
+
44
+ ActiveSupport.on_load( :action_view ){ include Editable::EditableHelper }
@@ -0,0 +1,3 @@
1
+ module Editable
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,78 @@
1
+ $.fn.editable = function() {
2
+ var old_value = "";
3
+
4
+ $(this).attr("contenteditable", "");
5
+ $(this).addClass("editing");
6
+
7
+ // dropdown?
8
+ if ($(this).data("editable-datatype") === "single") {
9
+ $(this).editable_association();
10
+ }
11
+
12
+ this.focus(function() {
13
+ if (!$(this).data("editable-editing")) {
14
+ // mark active
15
+ $(this).data("editable-editing", true);
16
+
17
+ // insert raw input if display_with
18
+ if ($(this).data("editable-display-with")) {
19
+ old_value = $(this).html();
20
+ $(this).html($(this).data("editable-value"));
21
+ }
22
+ }
23
+
24
+ }).blur(function() {
25
+
26
+ if ($(this).data("editable-datatype") === "single") {
27
+ return;
28
+ }
29
+ // set not-editing
30
+ $(this).data("editable-editing", false);
31
+
32
+ // collect info
33
+ var url = $(this).data("editable-url");
34
+ var model = $(this).data("editable-model");
35
+ var id = $(this).data("editable-id");
36
+ var method = $(this).data("editable-method");
37
+ var value = $(this).html().trim();
38
+ var dataType = $(this).data("editable-datatype");
39
+ var display_with = $(this).data("editable-display-with");
40
+
41
+ if (validate_editable(value, dataType)) {
42
+ $(this).attr("data-editable-invalid", false);
43
+ } else {
44
+ $(this).attr("data-editable-invalid", true);
45
+ return;
46
+ }
47
+
48
+ // send
49
+ $.ajax({
50
+ type: "PATCH",
51
+ url: url,
52
+ context: this,
53
+ contentType: "application/json; charset=utf-8",
54
+ data: '{"'+model+'":{"'+method+'":"'+value+'"},"id":"'+id+'"}',
55
+ dataType: 'json',
56
+ }).done(function(data) {
57
+ // set vars
58
+ $("[data-editable="+$(this).data("editable")+"]").html(data.value);
59
+ $("[data-editable="+$(this).data("editable")+"]").data("editable-value", value);
60
+ });
61
+ });
62
+
63
+ function validate_editable(value, dataType) {
64
+ if (dataType == "decimal") {
65
+ return jQuery.isNumeric(value);
66
+ } else {
67
+ return true;
68
+ }
69
+ }
70
+
71
+ function stripHTML(dirtyString) {
72
+ var container = document.createElement('div');
73
+ container.innerHTML = dirtyString;
74
+ return container.textContent || container.innerText;
75
+ }
76
+
77
+ return this;
78
+ }
metadata CHANGED
@@ -1,25 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: editable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
- - CroneKorkN
7
+ - ckn
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-12 00:00:00.000000000 Z
11
+ date: 2017-06-20 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: Makes activerecord-objects editable via frontend.
14
- email: gem@freibrief.net
13
+ description: desc.
14
+ email:
15
+ - ckn@freibrief.net
15
16
  executables: []
16
17
  extensions: []
17
18
  extra_rdoc_files: []
18
19
  files:
19
- - lib/editable.rb
20
- homepage: http://rubygems.org/gems/hola
21
- licenses:
22
- - MIT
20
+ - LICENSE
21
+ - README.md
22
+ - lib/editabe.rb
23
+ - lib/editable/version.rb
24
+ - vendor/assets/javascripts/editable.js
25
+ homepage: https://sublimity.de
26
+ licenses: []
23
27
  metadata: {}
24
28
  post_install_message:
25
29
  rdoc_options: []
@@ -40,5 +44,5 @@ rubyforge_project:
40
44
  rubygems_version: 2.5.2
41
45
  signing_key:
42
46
  specification_version: 4
43
- summary: editable activerecord-attributes
47
+ summary: summary
44
48
  test_files: []
data/lib/editable.rb DELETED
@@ -1,6 +0,0 @@
1
- class Hola
2
- def self.hi
3
- puts "ckn"
4
- end
5
- end
6
-