json_input_bootstrap_rails 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9564cb6dcca12cc51b43c0592c3517d763198417
4
+ data.tar.gz: ab880c7d0c4d0f5c8726ef209de236097a079001
5
+ SHA512:
6
+ metadata.gz: 2dd828dbb38ac9cc3d53ee33212f1123f1913a78f1036b17ad86986b7238cf6f16bfc524b1fd83eb3a2997a0d048786c66f167c33a5817b6b02b7846b192e1e5
7
+ data.tar.gz: 177b29300690807b31fd19092437b6ed147a38e560c60bd5d0332b94e9c0e8282bc78fd5045645121879c565de96ff1c52a25ed648ef7eac6d2548533045c93b
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in json_input_bootstrap_rails.gemspec
4
+ gemspec
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,66 @@
1
+ $(document).ready(function() {
2
+
3
+ if ($('.json-input-bootstrap-rails').length > 0) {
4
+ $("body").append('<div id="json-input-modal" class="modal fade" aria-labelledby="JsonInputModal" role="dialog"><div class="modal-dialog modal-lg"><div id="json-input-modal-content" class="modal-content"><div class="modal-header"><button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button><h4 id="json-title" class="modal-title">JSON Input</h4></div><form id="json-form"><div id="json-rows" class="modal-body"><div class="row json-header-row"><label id="json-header-key" class="control-label col-xs-5">key</label><label class="control-label col-xs-1">:</label><label id="json-header-value" class="control-label col-xs-5">value</label></div></div><div class="modal-footer"><div class="row"><div class="col-xs-11"></div><div class="btn-area col-xs-1"><button id="add-row" type="button" class="btn btn-success">+</button></div></div></div></form></div></div></div>');
5
+
6
+ var modal = $("#json-input-modal");
7
+ var json_form = $("#json-form");
8
+ var json_rows = $("#json-rows");
9
+
10
+ var new_row = '<div class="row json-row"><div class="form-group"><div class="key-field col-xs-5"><input class="form-control"></div><div class="colon-field col-xs-1"><span>:</span></div><div class="value-field col-xs-5"><input class="form-control"></div><div class="delete-area btn-area col-xs-1"><button class="delete-button btn btn-danger" type="button">x</button></div></div></div>';
11
+
12
+ $(document).on('click', ".json-input-bootstrap-rails", function(e) {
13
+ json_form.attr("data", this.id);
14
+ var text_area = $(e.target);
15
+ var current_text = "";
16
+ var keyLabel = text_area.attr('data-key-label');
17
+ if (typeof keyLabel !== typeof undefined && keyLabel !== false) {
18
+ $('#json-header-key').text(keyLabel);
19
+ }
20
+ var valueLabel = text_area.attr('data-value-label');
21
+ if (typeof valueLabel !== typeof undefined && valueLabel !== false){
22
+ $('#json-header-value').text(valueLabel);
23
+ }
24
+ var title = text_area.attr('data-title');
25
+ if (typeof title !== typeof undefined && title !== false) {
26
+ $('#json-title').text(title);
27
+ } else {
28
+ $('#json-title').text(text_area.attr('name'));
29
+ }
30
+
31
+ if (this.value == "") {
32
+ $(".json-row").remove();
33
+ json_rows.append(new_row);
34
+ } else {
35
+ current_text = JSON.parse(this.value);
36
+ $(".json-row").remove();
37
+ $.each(current_text, function(key, val){
38
+ json_rows.append('<div class="row json-row"><div class="form-group"><div class="key-field col-xs-5"><input class="key-data form-control" value="' + key + '"></div><div class="colon-holder col-xs-1"><span>:</span></div><div class="value-field col-xs-5"><input class="value-data form-control" value="' + val + '"></div><div class="delete-area btn-area col-xs-1"><button class="delete-button btn btn-danger" type="button">x</button></div></div></div>');
39
+ })
40
+ json_rows.append(new_row);
41
+ }
42
+ modal.modal('show');
43
+ })
44
+
45
+ $(document).on('click', '#json-input-modal #add-row', function(){
46
+ $("#json-rows").append(new_row);
47
+ });
48
+
49
+ $(document).on('click', '#json-input-modal .delete-button', function() {
50
+ this.parentElement.parentElement.remove();
51
+ });
52
+
53
+ $(document).on('hidden.bs.modal', '#json-input-modal', function () {
54
+ var values = [];
55
+ var pairs = {};
56
+ $("#json-form input").each(function(index, data){ values.push($(this).val()) });
57
+ values = values.filter(function(n){ return n != "" });
58
+ for (var i=0; i < values.length; i = i+2) {
59
+ pairs[values[i]] = values[i+1];
60
+ }
61
+ var json = JSON.stringify(pairs);
62
+ $('[id='+ json_form.attr("data") +']').val(json);
63
+ modal.modal('hide');
64
+ })
65
+ }
66
+ });
@@ -0,0 +1,11 @@
1
+ #json-input-modal label, #json-input-modal .colon-field {
2
+ text-align: center;
3
+ }
4
+
5
+ #json-input-modal .json-row {
6
+ margin-bottom: 20px;
7
+ }
8
+
9
+ #json-input-modal .btn-area button {
10
+ width: 100%;
11
+ }
@@ -0,0 +1,27 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <title>json_input_bootstrap_rails</title>
6
+ <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
7
+ <link rel="stylesheet" href="./assets/stylesheets/json_input_bootstrap_rails.css">
8
+ </head>
9
+ <body>
10
+ <h2>Sample JSON Payload</h2>
11
+ <br>
12
+ <div class="container">
13
+ <div class="row">
14
+ <div id="payload-params">
15
+ <label class="control-label">Text Area 1</label>
16
+ <textarea id="text-area-1" class="json-input-bootstrap-rails form-control"></textarea>
17
+ <br>
18
+ <label class="control-label">Text Area 2</label>
19
+ <textarea id="text-area-2" class="json-input-bootstrap-rails form-control"></textarea>
20
+ </div>
21
+ </div>
22
+ </div>
23
+ </body>
24
+ <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
25
+ <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
26
+ <script src="./assets/javascripts/json_input_bootstrap_rails.js"></script>
27
+ </html>
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "json_input_bootstrap_rails"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,35 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'json_input_bootstrap_rails/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "json_input_bootstrap_rails"
8
+ spec.version = JsonInputBootstrapRails::VERSION
9
+ spec.authors = ["Dave Wexler"]
10
+ spec.email = ["dave@xapix.io", "oliver@xapix.io"]
11
+ spec.license = 'MIT'
12
+ spec.summary = %q{A gem that takes form entries in key-value form and converts to a JSON string.}
13
+ spec.description = %q{A gem that will pop up a modal with a form when you click on a textarea in which you want a stringified JSON object. Simply fill in the form's keys and values and click save, and it will populate the corresponding textarea with a stringified JSON object. Ideal for quick preparation of JSON payload params for POST requests.}
14
+ spec.homepage = "https://github.com/xapix-io/json-input-bootstrap-rails"
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ if spec.respond_to?(:metadata)
19
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
20
+ else
21
+ raise "RubyGems 2.0 or newer is required to protect against " \
22
+ "public gem pushes."
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
26
+ f.match(%r{^(test|spec|features)/})
27
+ end
28
+ spec.bindir = "exe"
29
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ spec.add_development_dependency "bundler", "~> 1.13"
33
+ spec.add_development_dependency "rake", "~> 10.0"
34
+ spec.add_development_dependency "rspec", "~> 3.0"
35
+ end
@@ -0,0 +1,6 @@
1
+ require "json_input_bootstrap_rails/version"
2
+
3
+ module JsonInputBootstrapRails
4
+ class Engine < Rails::Engine
5
+ end
6
+ end
@@ -0,0 +1,3 @@
1
+ module JsonInputBootstrapRails
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,72 @@
1
+ # json_input_bootstrap_rails 0.1.0
2
+
3
+ ## Installation
4
+
5
+ Add this line to your application's Gemfile:
6
+
7
+ ```ruby
8
+ gem 'json_input_bootstrap_rails'
9
+ ```
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install json_input_bootstrap_rails
18
+
19
+ ## Usage
20
+
21
+ ## JSON-Helper 0.1.0
22
+
23
+ ### What it does
24
+
25
+ This gem will add Javascript and CSS to a rails project to let JSONified text get made for you simply by entering in key-value fields in a pop-up form within a modal. No more having to write out all those squigly-brackets, quotation marks, and colons; this will do it for you.
26
+
27
+ The functionality is very basic right now, as this is really just meant as a handy shortcut if you need, for example, payload params in a POST request to be quickly converted to JSON.
28
+
29
+ ### Contents
30
+
31
+ There are four files in this package, including this README.
32
+
33
+ The others are:
34
+
35
+ #### sample.html
36
+ This file has a sample html file which includes two text areas with the proper class for the javascript/css to work. Things to note in this file are that:
37
+
38
+ 1. When the page loads, a custom modal is appended to the end of the body section. It's unlikely, but if your IDs/classes match the names of stuff in this modal, it'll stop working.
39
+ 2. Each text area has an ID attribute. This is required so that the script knows where to put your stringified JSON when you click save. It'll add the final output JSON to the textarea with the ID in which you clicked to open the modal. The ID can be anything you like--there is no required convention for this part--it just needs to be there.
40
+ 3. Each text area that you want to trigger the script for needs to have a class of "json-input-bootstrap-rails".
41
+
42
+ #### json_input_bootstrap_rails.css
43
+ This file has the CSS to style elements of the modal. Feel free to edit the style as you like, just be careful about renaming the pre-given non-bootstrap classes, as they might mess with the Javascript if you change them.
44
+
45
+ Also, there are some Twitter Bootstrap classes included too, so if you're using that you've got extra built-in styling shortcuts. These are discardable/changeable if you like.
46
+
47
+ #### json_input_bootstrap_rails.js
48
+ This is where all the javascript lives, including functions to append the modal upon document ready and opening it when you click in a textarea you want JSONified, adding and deleting rows from the form, and the conversion upon hitting the save button.
49
+
50
+ ## Don't change these classes!
51
+
52
+ These are the classes and IDs you need to make the Javascript (as currently written) work:
53
+
54
+ 1. Textareas: must have an ID (of anything you want to name it) and a class of "json-input-bootstrap-rails"
55
+ 2. Modal: must have an ID of "json-input-modal"
56
+ 3. Button to add a row in the form: ID of "add-row"
57
+ 4. Delete a row button (looks like an 'X'): class of "delete-button"
58
+ 5. Cancel button (just closes/hides the modal): ID of "cancel-button"
59
+ 6. Save button: ID of "save-button"
60
+ 7. The form within the modal content: ID of "json-form"
61
+
62
+ That's it I think. Enjoy your auto-JSONified text!
63
+
64
+ ## Development
65
+
66
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
67
+
68
+ 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).
69
+
70
+ ## Contributing
71
+
72
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/json_input_bootstrap_rails.
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: json_input_bootstrap_rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Dave Wexler
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-01-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.13'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.13'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: A gem that will pop up a modal with a form when you click on a textarea
56
+ in which you want a stringified JSON object. Simply fill in the form's keys and
57
+ values and click save, and it will populate the corresponding textarea with a stringified
58
+ JSON object. Ideal for quick preparation of JSON payload params for POST requests.
59
+ email:
60
+ - dave@xapix.io
61
+ - oliver@xapix.io
62
+ executables: []
63
+ extensions: []
64
+ extra_rdoc_files: []
65
+ files:
66
+ - Gemfile
67
+ - Rakefile
68
+ - app/assets/javascripts/json_input_bootstrap_rails.js
69
+ - app/assets/stylesheets/json_input_bootstrap_rails.css
70
+ - app/sample.html
71
+ - bin/console
72
+ - bin/setup
73
+ - json_input_bootstrap_rails.gemspec
74
+ - lib/json_input_bootstrap_rails.rb
75
+ - lib/json_input_bootstrap_rails/version.rb
76
+ - readme.md
77
+ homepage: https://github.com/xapix-io/json-input-bootstrap-rails
78
+ licenses:
79
+ - MIT
80
+ metadata:
81
+ allowed_push_host: https://rubygems.org
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubyforge_project:
98
+ rubygems_version: 2.4.5.1
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: A gem that takes form entries in key-value form and converts to a JSON string.
102
+ test_files: []