8000 init · udacity/activeadmin_json_editor@90d4596 · GitHub
[go: up one dir, main page]

Skip to content

Commit 90d4596

Browse files
committed
init
0 parents  commit 90d4596

31 files changed

+7380
-0
lines changed

Gemfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
source 'https://rubygems.org'
2+
3+
# Specify your gem's dependencies in activeadmin_hstore_editor.gemspec
4+
gemspec

Gemfile.lock

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
PATH
2+
remote: .
3+
specs:
4+
activeadmin_hstore_editor (0.0.1)
5+
railties (>= 3.0, < 5.0)
6+
7+
GEM
8+
remote: https://rubygems.org/
9+
specs:
10+
actionpack (4.1.4)
11+
actionview (= 4.1.4)
12+
activesupport (= 4.1.4)
13+
rack (~> 1.5.2)
14+
rack-test (~> 0.6.2)
15+
actionview (4.1.4)
16+
activesupport (= 4.1.4)
17+
builder (~> 3.1)
18+
erubis (~> 2.7.0)
19+
activesupport (4.1.4)
20+
i18n (~> 0.6, >= 0.6.9)
21+
json (~> 1.7, >= 1.7.7)
22+
minitest (~> 5.1)
23+
thread_safe (~> 0.1)
24+
tzinfo (~> 1.1)
25+
builder (3.2.2)
26+
erubis (2.7.0)
27+
i18n (0.6.11)
28+
json (1.8.1)
29+
minitest (5.4.0)
30+
rack (1.5.2)
31+
rack-test (0.6.2)
32+
rack (>= 1.0)
33+
railties (4.1.4)
34+
actionpack (= 4.1.4)
35+
activesupport (= 4.1.4)
36+
rake (>= 0.8.7)
37+
thor (>= 0.18.1, < 2.0)
38+
rake (10.3.2)
39+
thor (0.19.1)
40+
thread_safe (0.3.4)
41+
tzinfo (1.2.1)
42+
thread_safe (~> 0.1)
43+
44+
PLATFORMS
45+
ruby
46+
47+
DEPENDENCIES
48+
activeadmin_hstore_editor!
49+
bundler (~> 1.5)

LICENSE.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Copyright (c) 2014 wild
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.

README.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# ActiveAdmin::HstoreEditor
2+
3+
"hstore_input" field type to active_admin that allow to edit Postgresql hstore values as json tree.
4+
Data shown by using jsoneditor.js from http://jsoneditoronline.org
5+
6+
## Installation
7+
8+
Add this line to your application's Gemfile:
9+
10+
gem 'activeadmin_hstore_editor'
11+
12+
And then execute:
13+
14+
$ bundle
15+
16+
Or install it yourself as:
17+
18+
$ gem install activeadmin_hstore_editor
19+
20+
## Usage
21+
22+
This Gem provides you formtastic input called :hstore to edit hstore data and parse form data for store it
23+
24+
25+
```ruby
26+
ActiveAdmin.register User do
27+
permit_params :settings
28+
29+
hstore_editor
30+
31+
# specify the type does not necessarily
32+
form do |f|
33+
f.inputs do
34+
f.input :settings, as: :hstore
35+
end
36+
37+
f.actions
38+
end
39+
end
40+
```
41+
42+
## Contributing
43+
44+
1. Fork it ( http://github.com/wild-ex/activeadmin_hstore_editor/fork )
45+
2. Create your feature branch (`git checkout -b my-new-feature`)
46+
3. Commit your changes (`git commit -am 'Add some feature'`)
47+
4. Push to the branch (`git push origin my-new-feature`)
48+
5. Create new Pull Request

Rakefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
require "bundler/gem_tasks"

activeadmin_hstore_editor.gemspec

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# coding: utf-8
2+
require File.expand_path('../lib/activeadmin/hstore_editor/version', __FILE__)
3+
4+
Gem::Specification.new do |spec|
5+
spec.name = "activeadmin_hstore_editor"
6+
spec.version = ActiveAdmin::HstoreEditor::VERSION
7+
spec.autho 10000 rs = ["wild"]
8+
spec.email = ["wild.exe@gmail.com"]
9+
spec.summary = %q{add "hstore_input" field type to active_admin that allow to edit Postgresql hstore values}
10+
spec.description = %q{"hstore_input" field allow to edit hstore value as json array with using jsoneditor.js from http://jsoneditoronline.org}
11+
spec.homepage = "https://github.com/wild-r/activeadmin_hstore_editor"
12+
spec.license = "MIT"
13+
14+
spec.files = `git ls-files -z`.split("\x0")
15+
# spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
16+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17+
spec.require_paths = ["lib"]
18+
19+
spec.required_rubygems_version = ">= 1.3.6"
20+
spec.add_development_dependency "bundler", "~> 1.5"
21+
spec.add_dependency "railties", ">= 3.0", "< 5.0"
22+
#spec.add_development_dependency "rake", "~> 0"
23+
#spec.add_dependency "active_admin", "~> 1.0.0"
24+
end
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//= require jsoneditor/jsoneditor.js
2+
//= require jsoneditor/asset/jsonlint/jsonlint.js
3+
4+
;(function(window, $) {
5+
$(function() {
6+
/* multipart/form-data*/
7+
$('form').attr('enctype', 'application/json');
8+
9+
$('div.jsoneditor-wrap').each(function(i,wrap){
10+
var container = $(wrap)[0];
11+
var textarea = $($(wrap).find('textarea'));
12+
var editor;
13+
var options = {
14+
mode: 'tree',
15+
change: function(ev){
16+
textarea.text(JSON.stringify(editor.get()));
17+
}
18+
};
19+
editor = new JSONEditor(container, options,JSON.parse(textarea.val()));
20+
});
21+
})
22+
})(window, jQuery)
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
*= require jsoneditor/jsoneditor
3+
*/
4+
5+
.jsoneditor-wrap textarea {
6+
display: none;
7+
}
8+
9+
.jsoneditor table {
10+
width: auto;
11+
margin-bottom: auto;
12+
}
13+
14+
15+
.jsoneditor {
16+
background-color: white;
17+
width: auto;
18+
height: 300px;
19+
border-color: rgb(201, 208, 214);
20+
border-radius: 3px;
21+
border-width: 1px;
22+
23+
}
24+
25+
.jsoneditor .menu {
26+
background-image: -webkit-linear-gradient(top, rgb(253, 253, 253), rgb(244, 244, 244));
27+
border-bottom-color: rgb(201, 208, 214);
28+
}
29+
30+
.jsoneditor .menu a {
31+
color: rgb(201, 208, 214);
32+
}
33+
34+
.jsoneditor .menu button {
35+
border-color: rgb(201, 208, 214);
36+
background-color: white;
37+
color: white;
38+
}
39+
40+
.jsoneditor .menu button:disabled {
41+
background-color: #f4f4f4;
42+
}
43+
44+
.jsoneditor .search .frame {
45+
border-color: rgb(201, 208, 214);
46+
}

app/inputs/hstore_input.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#-*- encoding: utf-8; tab-width: 2 -*-
2+
3+
class HstoreInput < Formtastic::Inputs::TextInput
4+
def to_html
5+
html = '<div class="jsoneditor-wrap">'
6+
Rails.logger.error '#' * 10
7+
Rails.logger.error method
8+
current_value = @object.public_send method
9+
html << builder.text_area(method, input_html_options.merge(
10+
value: (current_value.respond_to?(:to_json) ? current_value.to_json : '')))
11+
html << '</div>'
12+
html << '<div style="clear: both"></div>'
13+
input_wrapping do
14+
label_html << html.html_safe
15+
end
16+
end
17+
end

lib/activeadmin/hstore_editor.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#-*- encoding: utf-8; tab-width: 2 -*-
2+
require "activeadmin/hstore_editor/version"
3+
require "activeadmin/resource_dsl"
4+
5+
module ActiveAdmin
6+
module HstoreEditor
7+
class Engine < ::Rails::Engine
8+
end
9+
end
10+
end

0 commit comments

Comments
 (0)
0