administrate-field-jsontable 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +7 -0
- data/.rubocop.yml +96 -0
- data/Gemfile +9 -1
- data/Gemfile.lock +153 -118
- data/LICENSE.md +1 -1
- data/README.md +11 -23
- data/Rakefile +11 -0
- data/administrate-field-jsontable.gemspec +8 -6
- data/app/views/fields/jsontable/_index.html.erb +18 -0
- data/app/views/fields/jsontable/_json_table_field.html.erb +30 -0
- data/app/views/fields/jsontable/_show.html.erb +6 -33
- data/lib/administrate/field/jsontable.rb +2 -0
- data/spec/example_app/app/assets/config/manifest.js +2 -0
- data/spec/example_app/app/assets/javascripts/application.js +15 -0
- data/spec/example_app/app/assets/stylesheets/application.css +15 -0
- data/spec/example_app/app/controllers/application_controller.rb +7 -0
- data/spec/example_app/app/models/application_record.rb +5 -0
- data/spec/example_app/app/views/layouts/application.html.erb +31 -0
- data/spec/example_app/app/views/pages/.keep +0 -0
- data/spec/example_app/config.ru +6 -0
- data/spec/example_app/config/application.rb +39 -0
- data/spec/example_app/config/boot.rb +4 -0
- data/spec/example_app/config/database.yml +11 -0
- data/spec/example_app/config/environment.rb +7 -0
- data/spec/example_app/config/environments/development.rb +39 -0
- data/spec/example_app/config/environments/production.rb +78 -0
- data/spec/example_app/config/environments/staging.rb +3 -0
- data/spec/example_app/config/environments/test.rb +43 -0
- data/spec/example_app/config/initializers/assets.rb +13 -0
- data/spec/example_app/config/initializers/backtrace_silencers.rb +8 -0
- data/spec/example_app/config/initializers/cookies_serializer.rb +5 -0
- data/spec/example_app/config/initializers/disable_xml_params.rb +5 -0
- data/spec/example_app/config/initializers/errors.rb +20 -0
- data/spec/example_app/config/initializers/filter_parameter_logging.rb +6 -0
- data/spec/example_app/config/initializers/inflections.rb +18 -0
- data/spec/example_app/config/initializers/json_encoding.rb +3 -0
- data/spec/example_app/config/initializers/mime_types.rb +5 -0
- data/spec/example_app/config/initializers/session_store.rb +5 -0
- data/spec/example_app/config/initializers/wrap_parameters.rb +16 -0
- data/spec/example_app/config/routes.rb +4 -0
- data/spec/example_app/config/secrets.yml +15 -0
- data/spec/example_app/db/schema.rb +18 -0
- data/spec/example_app/db/seeds.rb +8 -0
- data/spec/example_app/public/robots.txt +5 -0
- data/spec/fixtures/jsontable/array_contains_hash.html +1 -0
- data/spec/fixtures/jsontable/hash_contains_array.html +31 -0
- data/spec/fixtures/jsontable/pure_hash.html +58 -0
- data/spec/lib/administrate/field/jsontable_index_spec.rb +95 -0
- data/spec/lib/administrate/field/jsontable_show_spec.rb +95 -0
- data/spec/lib/administrate/field/jsontable_spec.rb +16 -5
- data/spec/rails_helper.rb +6 -0
- data/spec/support/read_fixture.rb +7 -0
- metadata +93 -17
data/LICENSE.md
CHANGED
data/README.md
CHANGED
@@ -1,33 +1,21 @@
|
|
1
1
|
# Administrate::Field::Jsontable
|
2
2
|
|
3
|
-
A plugin to
|
3
|
+
A plugin to display the values of a JSON into a table. If the JSON has no data
|
4
|
+
of a field it will display a "-". This gem only displays 1 or 2 rows.
|
4
5
|
|
5
|
-
|
6
|
-
Although its structure may change,
|
7
|
-
it's designed to act as a template for other Administrate field plugins.
|
6
|
+
![JsonTable](https://user-images.githubusercontent.com/7603314/29417081-9fa39038-832d-11e7-9189-b1baaccd8ec6.png)
|
8
7
|
|
9
|
-
|
8
|
+
This repository is a field plugin for Administrate.
|
10
9
|
|
11
|
-
|
10
|
+
## Installation
|
12
11
|
|
13
|
-
|
12
|
+
Add to your gemfile `gem 'administrate-field-jsontable'`
|
14
13
|
|
15
|
-
|
16
|
-
If there's a namespace in the class name, that gets translated to a dash (`-`) in the gem name.
|
17
|
-
If the class name is CamelCased, that translates to an underscore (`_`) in the gem name.
|
18
|
-
|
19
|
-
Since all administrate field gems are under the namespace `Administrate::Field`,
|
20
|
-
every field gem name should start with the prefix `administrate-field-`.
|
21
|
-
|
22
|
-
Here are some examples (these don't correspond to actual gems):
|
14
|
+
[Administrate]: https://github.com/thoughtbot/administrate
|
23
15
|
|
24
|
-
|
25
|
-
|----------------------------|------------------------------|
|
26
|
-
| `administrate-field-enum` | `Administrate::Field::Enum` |
|
27
|
-
| `administrate-field-file_upload` | `Administrate::Field::FileUpload` |
|
28
|
-
| `administrate-field-geocoding-region` | `Administrate::Field::Geocoding::Region` |
|
29
|
-
| `administrate-field-geocoding-geo_json` | `Administrate::Field::Geocoding::GeoJson` |
|
16
|
+
## Contributing
|
30
17
|
|
31
|
-
|
18
|
+
Run `bundle exec rake db:setup` to set up example rails app on development environment
|
19
|
+
Run `bundle exec rspec` to run tests
|
20
|
+
Run `bundle exec rubocop` to linting tests
|
32
21
|
|
33
|
-
[Administrate]: https://github.com/thoughtbot/administrate
|
data/Rakefile
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'bundler/setup'
|
5
|
+
rescue LoadError
|
6
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
7
|
+
end
|
8
|
+
|
9
|
+
require File.expand_path('spec/example_app/config/application', __dir__)
|
10
|
+
|
11
|
+
Rails.application.load_tasks
|
@@ -1,11 +1,13 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
$LOAD_PATH.push File.expand_path('lib', __dir__)
|
2
4
|
|
3
5
|
Gem::Specification.new do |s|
|
4
6
|
s.name = 'administrate-field-jsontable'
|
5
|
-
s.version = '0.0
|
6
|
-
s.authors = ['
|
7
|
-
s.email = ['
|
8
|
-
s.homepage = 'https://github.com/
|
7
|
+
s.version = '0.1.0'
|
8
|
+
s.authors = ['Adrian Rangel', 'Enrique Barragan']
|
9
|
+
s.email = ['adrian@valiot.io', 'enrique@valiot.io']
|
10
|
+
s.homepage = 'https://github.com/Valiot/administrate-field-jsontable'
|
9
11
|
s.summary = 'JSON to table field plugin for Administrate'
|
10
12
|
s.description = s.summary
|
11
13
|
s.license = 'MIT'
|
@@ -15,5 +17,5 @@ Gem::Specification.new do |s|
|
|
15
17
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
18
|
|
17
19
|
s.add_dependency 'administrate'
|
18
|
-
s.add_dependency 'rails', '>= 4.2'
|
20
|
+
s.add_dependency 'rails', '>= 4.2'
|
19
21
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
<%#
|
2
|
+
# Enum Show Partial
|
3
|
+
|
4
|
+
This partial renders an enum attribute,
|
5
|
+
to be displayed on a resource's show page.
|
6
|
+
|
7
|
+
By default, the attribute is rendered as a text tag.
|
8
|
+
|
9
|
+
## Local variables:
|
10
|
+
|
11
|
+
- `field`:
|
12
|
+
An instance of [Administrate::Field::Enum][1].
|
13
|
+
A wrapper around the enum attributes pulled from the model.
|
14
|
+
|
15
|
+
%>
|
16
|
+
|
17
|
+
|
18
|
+
<%= render partial: '/fields/jsontable/json_table_field', locals: { data: field.data } %>
|
@@ -0,0 +1,30 @@
|
|
1
|
+
<%#
|
2
|
+
# Enum Show Partial
|
3
|
+
|
4
|
+
This partial renders an enum attribute,
|
5
|
+
to be displayed on a resource's show page.
|
6
|
+
|
7
|
+
By default, the attribute is rendered as a text tag.
|
8
|
+
|
9
|
+
## Local variables:
|
10
|
+
|
11
|
+
- `field`:
|
12
|
+
An instance of [Administrate::Field::Enum][1].
|
13
|
+
A wrapper around the enum attributes pulled from the model.
|
14
|
+
|
15
|
+
%>
|
16
|
+
|
17
|
+
<% if data.kind_of?(Hash) %>
|
18
|
+
<table>
|
19
|
+
<tbody>
|
20
|
+
<% data.each do |key, value| %>
|
21
|
+
<tr>
|
22
|
+
<td><%= key %></td>
|
23
|
+
<td><%= if value.blank? then "-" else render partial: '/fields/jsontable/json_table_field', locals: { data: value } end %></td>
|
24
|
+
</tr>
|
25
|
+
<% end %>
|
26
|
+
<tbody>
|
27
|
+
</table>
|
28
|
+
<% else %>
|
29
|
+
<%= if data.blank? then "-" else data end %>
|
30
|
+
<% end %>
|
@@ -1,7 +1,7 @@
|
|
1
1
|
<%#
|
2
|
-
#
|
2
|
+
# Enum Show Partial
|
3
3
|
|
4
|
-
This partial renders an
|
4
|
+
This partial renders an enum attribute,
|
5
5
|
to be displayed on a resource's show page.
|
6
6
|
|
7
7
|
By default, the attribute is rendered as a text tag.
|
@@ -9,37 +9,10 @@ By default, the attribute is rendered as a text tag.
|
|
9
9
|
## Local variables:
|
10
10
|
|
11
11
|
- `field`:
|
12
|
-
An instance of [Administrate::Field::
|
13
|
-
A wrapper around the
|
12
|
+
An instance of [Administrate::Field::Enum][1].
|
13
|
+
A wrapper around the enum attributes pulled from the model.
|
14
14
|
|
15
15
|
%>
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
<tr>
|
20
|
-
<% field.data.each do |k,v| %>
|
21
|
-
<th><%= k %></th>
|
22
|
-
<% end %>
|
23
|
-
</tr>
|
24
|
-
</thead>
|
25
|
-
<tbody>
|
26
|
-
<% if field.data.first[1].kind_of?(Array) %>
|
27
|
-
<tr>
|
28
|
-
<% field.data.each do |k,v| %>
|
29
|
-
<td><%= if v[0].blank? then "-" else v[0] end %></td>
|
30
|
-
<% end %>
|
31
|
-
</tr>
|
32
|
-
<tr>
|
33
|
-
<% field.data.each do |k,v| %>
|
34
|
-
<td><%= if v[1].blank? then "-" else v[1] end %></td>
|
35
|
-
<% end %>
|
36
|
-
</tr>
|
37
|
-
<% else %>
|
38
|
-
<tr>
|
39
|
-
<% field.data.each do |k,v| %>
|
40
|
-
<td><%= if v.blank? then "-" else v end %></td>
|
41
|
-
<% end %>
|
42
|
-
</tr>
|
43
|
-
<% end %>
|
44
|
-
</tbody>
|
45
|
-
</table>
|
17
|
+
|
18
|
+
<%= render partial: '/fields/jsontable/json_table_field', locals: { data: field.data } %>
|
@@ -0,0 +1,15 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// compiled file.
|
9
|
+
//
|
10
|
+
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
|
11
|
+
// about supported directives.
|
12
|
+
//
|
13
|
+
//= require jquery
|
14
|
+
//= require jquery_ujs
|
15
|
+
//= require_tree .
|
@@ -0,0 +1,15 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any styles
|
10
|
+
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
|
11
|
+
* file per style scope.
|
12
|
+
*
|
13
|
+
*= require_tree .
|
14
|
+
*= require_self
|
15
|
+
*/
|
@@ -0,0 +1,31 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta charset="utf-8" />
|
5
|
+
<meta name="ROBOTS" content="NOODP" />
|
6
|
+
<meta name="viewport" content="initial-scale=1" />
|
7
|
+
<%#
|
8
|
+
Configure default and controller-, and view-specific titles in
|
9
|
+
config/locales/en.yml. For more see:
|
10
|
+
https://github.com/calebthompson/title#usage
|
11
|
+
%>
|
12
|
+
<title><%= title %></title>
|
13
|
+
<%= stylesheet_link_tag "//fonts.googleapis.com/css?family=Lato:300,400,900", media: "all" %>
|
14
|
+
<%= stylesheet_link_tag :application, media: "all" %>
|
15
|
+
<%= csrf_meta_tags %>
|
16
|
+
</head>
|
17
|
+
|
18
|
+
<body class="<%= body_class %>">
|
19
|
+
<main class="main">
|
20
|
+
<%= render "navigation" -%>
|
21
|
+
|
22
|
+
<div class="content">
|
23
|
+
<%= render "flashes" -%>
|
24
|
+
|
25
|
+
<%= yield %>
|
26
|
+
|
27
|
+
<%= render "javascript" %>
|
28
|
+
</div>
|
29
|
+
</main>
|
30
|
+
</body>
|
31
|
+
</html>
|
File without changes
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require File.expand_path('boot', __dir__)
|
4
|
+
|
5
|
+
require 'active_model/railtie'
|
6
|
+
require 'active_record/railtie'
|
7
|
+
require 'active_job/railtie'
|
8
|
+
require 'action_controller/railtie'
|
9
|
+
require 'action_view/railtie'
|
10
|
+
require 'sprockets/railtie'
|
11
|
+
|
12
|
+
# Require the gems listed in Gemfile, including any gems
|
13
|
+
# you've limited to :test, :development, or :production.
|
14
|
+
Bundler.require(*Rails.groups)
|
15
|
+
|
16
|
+
module AdministrateJsontablePrototype
|
17
|
+
class Application < Rails::Application
|
18
|
+
config.i18n.enforce_available_locales = true
|
19
|
+
|
20
|
+
config.generators do |generate|
|
21
|
+
generate.helper false
|
22
|
+
generate.javascript_engine false
|
23
|
+
generate.request_specs false
|
24
|
+
generate.routing_specs false
|
25
|
+
generate.stylesheets false
|
26
|
+
generate.test_framework :rspec
|
27
|
+
generate.view_specs false
|
28
|
+
end
|
29
|
+
|
30
|
+
config.action_controller.action_on_unpermitted_parameters = :raise
|
31
|
+
|
32
|
+
if Rails::VERSION::MAJOR < 5
|
33
|
+
# Do not swallow errors in after_commit/after_rollback callbacks.
|
34
|
+
config.active_record.raise_in_transactional_callbacks = true
|
35
|
+
end
|
36
|
+
|
37
|
+
config.active_record.time_zone_aware_types = %i[datetime time] if Rails::VERSION::MAJOR >= 5
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
Rails.application.configure do
|
4
|
+
# Settings specified here will take precedence over those in config/application.rb.
|
5
|
+
|
6
|
+
# In the development environment your application's code is reloaded on
|
7
|
+
# every request. This slows down response time but is perfect for development
|
8
|
+
# since you don't have to restart the web server when you make code changes.
|
9
|
+
config.cache_classes = false
|
10
|
+
|
11
|
+
# Do not eager load code on boot.
|
12
|
+
config.eager_load = false
|
13
|
+
|
14
|
+
# Show full error reports and disable caching.
|
15
|
+
config.consider_all_requests_local = true
|
16
|
+
config.action_controller.perform_caching = false
|
17
|
+
config.cache_store = :null_store
|
18
|
+
|
19
|
+
# Print deprecation notices to the Rails logger.
|
20
|
+
config.active_support.deprecation = :log
|
21
|
+
|
22
|
+
# Raise an error on page load if there are pending migrations.
|
23
|
+
config.active_record.migration_error = :page_load
|
24
|
+
|
25
|
+
# Highlight code that triggered database queries in logs.
|
26
|
+
config.active_record.verbose_query_logs = true
|
27
|
+
|
28
|
+
# Debug mode disables concatenation and preprocessing of assets.
|
29
|
+
# This option may cause significant delays in view rendering with a large
|
30
|
+
# number of complex assets.
|
31
|
+
config.assets.debug = true
|
32
|
+
config.i18n.default_locale = :tr
|
33
|
+
|
34
|
+
# Suppress logger output for asset requests.
|
35
|
+
config.assets.quiet = true
|
36
|
+
|
37
|
+
# Raises error for missing translations.
|
38
|
+
config.action_view.raise_on_missing_translations = true
|
39
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
Rails.application.configure do
|
4
|
+
# Settings specified here will take precedence over those in config/application.rb.
|
5
|
+
|
6
|
+
# Code is not reloaded between requests.
|
7
|
+
config.cache_classes = true
|
8
|
+
|
9
|
+
# Eager load code on boot. This eager loads most of Rails and
|
10
|
+
# your application in memory, allowing both threaded web servers
|
11
|
+
# and those relying on copy on write to perform better.
|
12
|
+
# Rake tasks automatically ignore this option for performance.
|
13
|
+
config.eager_load = true
|
14
|
+
|
15
|
+
# Full error reports are disabled and caching is turned on.
|
16
|
+
config.consider_all_requests_local = false
|
17
|
+
config.action_controller.perform_caching = true
|
18
|
+
|
19
|
+
# Ensures that a master key has been made available in either
|
20
|
+
# ENV["RAILS_MASTER_KEY"] or in config/master.key. This key is used to
|
21
|
+
# decrypt credentials (and other encrypted files).
|
22
|
+
# config.require_master_key = true
|
23
|
+
|
24
|
+
# Disable serving static files from the `/public` folder by default since
|
25
|
+
# Apache or NGINX already handles this.
|
26
|
+
config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?
|
27
|
+
|
28
|
+
# Compress CSS using a preprocessor.
|
29
|
+
# config.assets.css_compressor = :sass
|
30
|
+
|
31
|
+
# Do not fallback to assets pipeline if a precompiled asset is missed.
|
32
|
+
config.assets.compile = false
|
33
|
+
|
34
|
+
# Enable serving of images, stylesheets, and JavaScripts from an asset server.
|
35
|
+
# config.action_controller.asset_host = 'http://assets.example.com'
|
36
|
+
|
37
|
+
# Specifies the header that your server uses for sending files.
|
38
|
+
# config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
|
39
|
+
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX
|
40
|
+
|
41
|
+
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
|
42
|
+
# config.force_ssl = true
|
43
|
+
|
44
|
+
# Use the lowest log level to ensure availability of diagnostic information
|
45
|
+
# when problems arise.
|
46
|
+
config.log_level = :debug
|
47
|
+
|
48
|
+
# Prepend all log lines with the following tags.
|
49
|
+
config.log_tags = [:request_id]
|
50
|
+
|
51
|
+
# Use a different cache store in production.
|
52
|
+
# config.cache_store = :mem_cache_store
|
53
|
+
|
54
|
+
# Use a real queuing backend for Active Job (and separate queues per
|
55
|
+
# environment).
|
56
|
+
# config.active_job.queue_adapter = :resque
|
57
|
+
# config.active_job.queue_name_prefix = "administrate_prototype_production"
|
58
|
+
|
59
|
+
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
|
60
|
+
# the I18n.default_locale when a translation cannot be found).
|
61
|
+
config.i18n.fallbacks = true
|
62
|
+
config.i18n.default_locale = :tr
|
63
|
+
|
64
|
+
# Send deprecation notices to registered listeners.
|
65
|
+
config.active_support.deprecation = :notify
|
66
|
+
|
67
|
+
# Use default logging formatter so that PID and timestamp are not suppressed.
|
68
|
+
config.log_formatter = ::Logger::Formatter.new
|
69
|
+
|
70
|
+
if ENV['RAILS_LOG_TO_STDOUT'].present?
|
71
|
+
logger = ActiveSupport::Logger.new(STDOUT)
|
72
|
+
logger.formatter = config.log_formatter
|
73
|
+
config.logger = ActiveSupport::TaggedLogging.new(logger)
|
74
|
+
end
|
75
|
+
|
76
|
+
# Do not dump schema after migrations.
|
77
|
+
config.active_record.dump_schema_after_migration = false
|
78
|
+
end
|