xml_to_form 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +24 -0
- data/Rakefile +37 -0
- data/app/assets/javascripts/xml_to_form/application.js +13 -0
- data/app/assets/javascripts/xml_to_form/xml_handlers.js +2 -0
- data/app/assets/stylesheets/xml_to_form/application.css +15 -0
- data/app/assets/stylesheets/xml_to_form/xml_handlers.css +4 -0
- data/app/controllers/xml_to_form/application_controller.rb +4 -0
- data/app/controllers/xml_to_form/xml_handlers_controller.rb +41 -0
- data/app/helpers/xml_to_form/application_helper.rb +4 -0
- data/app/helpers/xml_to_form/xml_handlers_helper.rb +7 -0
- data/app/models/xml_to_form/xml_handler.rb +26 -0
- data/app/views/layouts/xml_to_form/application.html.erb +14 -0
- data/app/views/xml_to_form/xml_handlers/_parent_node_form.html.erb +28 -0
- data/app/views/xml_to_form/xml_handlers/upload_file.html.erb +4 -0
- data/app/views/xml_to_form/xml_handlers/xml_form.html.erb +12 -0
- data/config/routes.rb +6 -0
- data/db/migrate/20160411193812_create_xml_handlers.rb +7 -0
- data/lib/noko_hacks.rb +85 -0
- data/lib/tasks/xml_to_form_tasks.rake +4 -0
- data/lib/xml_to_form/engine.rb +5 -0
- data/lib/xml_to_form/version.rb +3 -0
- data/lib/xml_to_form.rb +4 -0
- data/test/controllers/xml_to_form/xml_handlers_controller_test.rb +13 -0
- data/test/dummy/README.rdoc +28 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/assets/javascripts/application.js +13 -0
- data/test/dummy/app/assets/stylesheets/application.css +15 -0
- data/test/dummy/app/controllers/application_controller.rb +5 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/bin/setup +29 -0
- data/test/dummy/config/application.rb +26 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +41 -0
- data/test/dummy/config/environments/production.rb +79 -0
- data/test/dummy/config/environments/test.rb +42 -0
- data/test/dummy/config/initializers/assets.rb +11 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +4 -0
- data/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +23 -0
- data/test/dummy/config/routes.rb +4 -0
- data/test/dummy/config/secrets.yml +22 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/db/migrate/20160411194809_create_xml_to_form_xml_handlers.rb +6 -0
- data/test/dummy/db/schema.rb +24 -0
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/development.log +4663 -0
- data/test/dummy/log/test.log +8 -0
- data/test/dummy/public/404.html +67 -0
- data/test/dummy/public/422.html +67 -0
- data/test/dummy/public/500.html +66 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/-U/-Uny5QP43mWDSg0U2feoR5NpJQf-FuJDaU9ZAHvQmbA.cache +0 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/-s/-s7l8i0L1hx7Q4m2w4PbiDPam4XkRh0qA9g4h21pMfE.cache +1 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/10/10qvVeoBLNusrUgVclnLRdC3FNsgH38Ept6uae-Fm80.cache +0 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/1C/1CRNW_RTSdEZnfoBaPVBe9tdfzLdCmcmmqSn8eQUR0M.cache +0 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/50/50FdRPZQOhdMg8LFJFxdmNWwQVJfMk143HPVc_2FaFc.cache +1 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/5L/5Lly_CA8DZvPhQV2jDQx-Y6P_y3Ygra9t5jfSlGhHDA.cache +2 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/5X/5XGHNnv3Fu1Ud5E94h7RAbORA65HNS82KhurTO48bXU.cache +1 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/5l/5lnf7KHinTj6vwjVXOlo7cvuKEtGZRcGreUI45llZJ4.cache +2 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/6f/6fg3jX96AM1zIFUGeCvUQ8ARxyDdl-BMR3ZF_Ml6VmE.cache +0 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/8o/8o4pevUm3uVIR-hpSAYO3ns95jNDw6Eb4kLGP_BjAAQ.cache +1 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/G2/G2DdvXkMWwPziIsU5U1YnbNcBMEoC9NRRS065_exELY.cache +1 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/HJ/HJdXBDK9ZSNm-rlB2UF1y5BYUtp-j9UknPMlvDv7ftA.cache +0 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/MM/MMwBbXGivpqDHjaPV5FFp_dqdk4C99D4rbZtkms94I0.cache +0 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/NK/NKI-IS4wRkGAWHzF4TcvWJRzYk4bOoa3MFJ4SBz5tP0.cache +0 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/OI/OI6uxGcnsKavdWTtwDAasU3wPx8QXhzBgV0X2n1KjMQ.cache +2 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/Q1/Q1ouXD5OyVQK2YTBt2LzMw48LzAyEJuUhPf2ost9Cxo.cache +3 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/Qi/QiIWC1NMKS6hLfXq-Tit0E7su-_zz22ZZjvss212vR0.cache +2 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/SD/SDziAeb8qUUyKXW_2L_voaKuKFkGwTcbETtAVHSFjDI.cache +1 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/S_/S_sevoAWKyppMRnqPeg-CBfLqeLnQ2GDhiFsqrgU6Ms.cache +0 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/UP/UPuvLNzlBeEC_H41MweL3yVLsK0v4pPqp_kOm4I0Bgg.cache +3 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/Xh/XhPb2DFWpdyJBOY_pn-RxffBbvytoRaDyJN-ipoW3qs.cache +1 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/Y0/Y07t50u-ukM4fQPi4vYn4KfbG6toEgX4VvJFv-lTgOA.cache +1 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/YE/YEyNwb78OHuOb0HMLTuJM4vBhgVZtpbwOYiITPELmr8.cache +2 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/_g/_gvUaWcxAvD2v4xJtPnlnmAE7JX_MtmYP7_8mZb27CE.cache +1 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/do/doVwefT8rhkDSgqE_ZX3CQyGBGrUslv38C7zAxb8m1M.cache +0 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/eZ/eZsGM75lCQjeANTlZMUlfsTu7n7skbKAaFDT-tcDIs4.cache +1 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/fH/fH0ADmvCXCZChumlbeeVkbiDLu9OrVOJgcNVwLlj0sU.cache +1 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/hZ/hZi1k6tpxxCGYxRe7zY74ItcOI8gZrREOpGuA8JSpGg.cache +2 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/j1/j1PapCxYmMcx3xX8cSm6JMdAVa0Io4jb2HjE0q8tMyM.cache +2 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/jT/jTdxw0bddolWW8KmM4BxLO8KxEGIOFn0iRODbdJPFSk.cache +1 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/jx/jxZ1dDhJoMAWKazHIaFUXERtFffeGB9OVWVLuYbFfI8.cache +2 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/l7/l7_Kv2jznYJaX_D4AZWIXi2Lypw3SQMXNmrOgLTREwg.cache +2 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/mA/mASRABYJRXDH4q-hIEG0Nptj6NqZJBU6e_7eilO6wBQ.cache +1 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/mt/mtXetL6U4rJoQvcROiP7XodKWzqvhb9ITvyGoOo0Sag.cache +1 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/oX/oX44gT1mT0fUkkvh3mzwLB12iRjBUfKLBfaM9Si8RHQ.cache +2 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/pE/pEhaat2KBd5SrT7szC_8R1_6hK17FTpvoRFkmCRSD3M.cache +2 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/pF/pFs51SvSCgO2duf0gMC9e_vI5x-ru06l9UCV1UcqWxg.cache +0 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/pc/pcEvDKreSVXFM-yyjRA7qhI1ez6tGKo2R4EK8HQPnSQ.cache +1 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/rN/rNmSSIA9hDQGOHevCwV7w6QOOmnRk2hutBe2ZYhwHT8.cache +1 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/rk/rknt4TU5zSvBWe4a1j3z5pnnbQutDG3lE_6RkeUwTt4.cache +1 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/uq/uqXdR_3CPhcgfLdo30Qd6wPRlwgFKh4APgjOldzM5Wg.cache +0 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/w2/w2kdjWh4olQ25caWvdJe_1Lr2lTu5-9qk0wwcMeoUUI.cache +1 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/xH/xH0iGd8xJ4xsC637Je3u2tkwDdMdPM7Tq1UZg2xMN5c.cache +1 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/yA/yAOU4n6GljMkYW-TMghoc2eTnVNGgLCikJP661gUCh0.cache +0 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/yR/yRQItO4cjRoKioEmsKjZu6BA-U9kPCq57L8w8P7sXLs.cache +0 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/yZ/yZC9AdVFXFgQAzVijoyjawV97GPbpePBBP92BPTfzBo.cache +1 -0
- data/test/dummy/updated.xml +88 -0
- data/test/fixtures/xml_to_form/xml_handlers.yml +11 -0
- data/test/integration/navigation_test.rb +8 -0
- data/test/models/xml_to_form/xml_handler_test.rb +9 -0
- data/test/test_helper.rb +21 -0
- data/test/xml_to_form_test.rb +7 -0
- metadata +311 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 020ace9572782e27c88ca55b9862fb7f08e583db
|
4
|
+
data.tar.gz: 539a2ae0a1b715c0e10540376fa784e2bdb3da0c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e574a23d63d7be454638d42fb8ce6e69d69b554ed22948b3891b992caf3b99484f17bf269059c4715f681d4269c5ee4dc94ce12ec00baa312d2808a1869daf83
|
7
|
+
data.tar.gz: 1f241df354ecb04a6e4e0e3e41cabafdef319f9548130c750cd12ef5e42feba417d0e822351b1e5c2a18057fc323584c99ec849932c1a2c71ef4fc510b07c027
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2016 nitanshu verma
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
= XmlTowForm
|
2
|
+
|
3
|
+
XmlToForm gem enables you to upload any xml file and it will convert it to nested Rails Form with the help of <fieldset> and <legend> tags, then you can update that file and you will get an <tt>updated.xml</tt> which will be the updated file for your xml in root of the application.
|
4
|
+
|
5
|
+
== Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
<tt>gem 'XmlToForm' </tt>
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
<tt>$ bundle</tt>
|
14
|
+
|
15
|
+
== Usage
|
16
|
+
|
17
|
+
To use this gem you just need to mount it in your route file *config/routes.rb*
|
18
|
+
|
19
|
+
<tt> mount XmlToForm::Engine => "/xml_to_form" </tt>
|
20
|
+
|
21
|
+
Then to go to the dashboard hit the url where you have mounted your gem:
|
22
|
+
|
23
|
+
then you will see a file upload button upload a xml file.
|
24
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'XmlToForm'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.rdoc')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
|
18
|
+
load 'rails/tasks/engine.rake'
|
19
|
+
|
20
|
+
|
21
|
+
load 'rails/tasks/statistics.rake'
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
Bundler::GemHelper.install_tasks
|
26
|
+
|
27
|
+
require 'rake/testtask'
|
28
|
+
|
29
|
+
Rake::TestTask.new(:test) do |t|
|
30
|
+
t.libs << 'lib'
|
31
|
+
t.libs << 'test'
|
32
|
+
t.pattern = 'test/**/*_test.rb'
|
33
|
+
t.verbose = false
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
task default: :test
|
@@ -0,0 +1,13 @@
|
|
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/rails/sprockets#sprockets-directives) for details
|
11
|
+
// about supported directives.
|
12
|
+
//
|
13
|
+
//= 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,41 @@
|
|
1
|
+
require_dependency "xml_to_form/application_controller"
|
2
|
+
require 'noko_hacks'
|
3
|
+
require_dependency 'xml_to_form/xml_handler.rb'
|
4
|
+
|
5
|
+
module XmlToForm
|
6
|
+
class XmlHandlersController < ApplicationController
|
7
|
+
include NokoHacks
|
8
|
+
before_filter :fetch_data, except: [:upload_file]
|
9
|
+
|
10
|
+
## @node_set is an array of each node with child and attributes which is representing the form in recursive way
|
11
|
+
## @attr_accessors is an hash where key is xml tag and their Base64 encoded path and value is there values
|
12
|
+
## @xml_obj is only the parsed object of nokogiri from xml
|
13
|
+
## @xml_data is the initialized object with their values which represents the form
|
14
|
+
def upload_file
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
def xml_form
|
19
|
+
@xml_data = XmlHandler.new(@attr_accessors)
|
20
|
+
end
|
21
|
+
|
22
|
+
def xml_update
|
23
|
+
@xml = XmlHandler.new(params[:xml_data])
|
24
|
+
params[:xml_handler].each do |key,value|
|
25
|
+
node = @xml_obj.at(decode_node_path(key))
|
26
|
+
update_xml(node, key, value)
|
27
|
+
if !node.content.empty? && !node.attributes.empty?
|
28
|
+
node.content = value
|
29
|
+
end
|
30
|
+
end
|
31
|
+
File.open('updated.xml', 'w') {|f| f.write(@xml_obj)}
|
32
|
+
redirect_to root_path
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
def fetch_data
|
37
|
+
params[:file]? @file= File.read(params[:file].tempfile) : @file = params[:file_content]
|
38
|
+
@node_set, @attr_accessors , @xml_obj= XmlHandler.noko_meta_data(@file)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'noko_hacks'
|
2
|
+
module XmlToForm
|
3
|
+
class XmlHandler < ActiveRecord::Base
|
4
|
+
include ActiveModel::Model
|
5
|
+
extend NokoHacks
|
6
|
+
extend ActiveModel::Callbacks
|
7
|
+
|
8
|
+
def after_initialize(some_hash)
|
9
|
+
some_hash.each do |key, value|
|
10
|
+
self.send("#{key}=", value) rescue nil
|
11
|
+
end if some_hash.is_a?(Hash)
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.noko_meta_data(file)
|
15
|
+
xml_obj = Nokogiri::XML(file).remove_namespaces! do |config|
|
16
|
+
config.default_xml.noblanks
|
17
|
+
end
|
18
|
+
xml_obj.children.remove_blank_node
|
19
|
+
xml_obj.children.iterate_child_nodes(_node_array= [], attr_accessor_hash ={})
|
20
|
+
attr_accessor_hash.each do |attr_key, attr_value|
|
21
|
+
attr_accessor attr_key.to_sym
|
22
|
+
end
|
23
|
+
return _node_array, attr_accessor_hash, xml_obj
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>XmlToForm</title>
|
5
|
+
<%= stylesheet_link_tag "xml_to_form/application", media: "all" %>
|
6
|
+
<%= javascript_include_tag "xml_to_form/application" %>
|
7
|
+
<%= csrf_meta_tags %>
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
|
11
|
+
<%= yield %>
|
12
|
+
|
13
|
+
</body>
|
14
|
+
</html>
|
@@ -0,0 +1,28 @@
|
|
1
|
+
<fieldset>
|
2
|
+
<% node_hash.each do |k,v|%>
|
3
|
+
<% if k != :child_node%>
|
4
|
+
<legend><%= k.split('_').first %></legend>
|
5
|
+
<% if v.is_a?(String) %>
|
6
|
+
<%= f.label k.split('_').first %>
|
7
|
+
<%= f.text_field k %>
|
8
|
+
<% else %>
|
9
|
+
<% v.each do |k1,v1|%>
|
10
|
+
<%= f.label k1.split('_').first %>
|
11
|
+
<%= f.text_field k1 %>
|
12
|
+
<% end %>
|
13
|
+
<% end %>
|
14
|
+
<% else %>
|
15
|
+
<%if v.is_a?(Array)%>
|
16
|
+
<% v.each do |n|%>
|
17
|
+
<%== iterate_node(n, f) %>
|
18
|
+
<% end %>
|
19
|
+
<%else%>
|
20
|
+
<%= iterate_node(v, f) %>
|
21
|
+
<% end %>
|
22
|
+
<% end %>
|
23
|
+
<% end %>
|
24
|
+
</fieldset>
|
25
|
+
|
26
|
+
|
27
|
+
|
28
|
+
|
@@ -0,0 +1,12 @@
|
|
1
|
+
<h2> XmlToRailsForm </h2>
|
2
|
+
<%= form_for @xml_data, url: xml_update_path, method: :post do |f| %>
|
3
|
+
<% @node_set.each do |set| %>
|
4
|
+
<% if set.key?(:child_node) %>
|
5
|
+
<%= iterate_node(set, f) %>
|
6
|
+
<% else%>
|
7
|
+
<%= render partial: 'xml_to_form/xml_handlers/parent_node_form', locals: {node_hash: set, f: f} %>
|
8
|
+
<% end %>
|
9
|
+
<% end %>
|
10
|
+
<%= hidden_field_tag :file_content, @file%>
|
11
|
+
<%= submit_tag 'Update xml' %>
|
12
|
+
<% end %>
|
data/config/routes.rb
ADDED
data/lib/noko_hacks.rb
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
module NokoHacks
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
Nokogiri::XML::NodeSet.send :include, NokoHacks
|
4
|
+
Nokogiri::XML::Text.send :include, NokoHacks
|
5
|
+
Nokogiri::XML::Element.send :include, NokoHacks
|
6
|
+
|
7
|
+
def remove_blank_node
|
8
|
+
self.children.each do |node|
|
9
|
+
if node.blank?
|
10
|
+
node.remove
|
11
|
+
end
|
12
|
+
if node.children
|
13
|
+
node.remove_blank_node
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def update_xml_attributes(node, key, value)
|
19
|
+
node.attributes.each do |k, v|
|
20
|
+
if k == get_node_attribute_name(key)
|
21
|
+
v.value = value
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def update_xml(node, key, value)
|
27
|
+
case [node.content.empty?, node.attributes.empty?]
|
28
|
+
when [false, true] then node.content = value
|
29
|
+
|
30
|
+
when [false, false] then node.content = value && update_xml_attributes(node, key, value)
|
31
|
+
|
32
|
+
when [true, false] then update_xml_attributes(node, key, value)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def decode_node_path(node)
|
37
|
+
Base64.decode64(node.split('_').last)
|
38
|
+
end
|
39
|
+
|
40
|
+
def get_node_attribute_name(key)
|
41
|
+
(_split_key = key.split('_')).size > 2 ? _split_key.take(_split_key.size - 1).join('-').sub('@','') : _split_key.first.sub('@','')
|
42
|
+
end
|
43
|
+
|
44
|
+
def iterate_child_nodes(node_array, attr_accessor_hash)
|
45
|
+
self.children.each do |node|
|
46
|
+
build_ds(node, node_array, attr_accessor_hash)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def encode_node_path(node)
|
51
|
+
('_' + Base64.urlsafe_encode64((Nokogiri::CSS.xpath_for node.css_path).first)).gsub('=','')
|
52
|
+
end
|
53
|
+
|
54
|
+
def build_ds(node, node_array, attr_accessor_hash)
|
55
|
+
case [node.attributes.empty? , node.content.empty? ,node.children.empty?]
|
56
|
+
|
57
|
+
when [false, true, true] then node_array.push({(node.name + encode_node_path(node)).gsub('-','_') => node.attributes.transform_keys{|key| (key + encode_node_path(node)).gsub('-','_')} }) && node.attributes.each {|key,value|
|
58
|
+
attr_accessor_hash.merge!((key + encode_node_path(node)).gsub('-','_') => value.value)}
|
59
|
+
|
60
|
+
when [true, false, false] then node_array.push({(node.name + encode_node_path(node)).gsub('-','_') => node.content, :child_node => node.child_node_ds(attr_accessor_hash) }) && attr_accessor_hash.merge!((node.name + encode_node_path(node)).gsub('-','_') => node.content)
|
61
|
+
|
62
|
+
when [false, true, false] then node_array.push({(node.name + encode_node_path(node)).gsub('-','_')=> node.attributes.transform_keys{|key| (key + encode_node_path(node)).gsub('-','_')}, :child_node => node.child_node_ds(attr_accessor_hash) }) && node.attributes.each {|key,value| attr_accessor_hash.merge!((key + encode_node_path(node)).gsub('-','_') => value.value)}
|
63
|
+
|
64
|
+
when [false, false, false] then node_array.push({(node.name + encode_node_path(node)).gsub('-','_') => (node.attributes.transform_keys{|key| (key + encode_node_path(node)).gsub('-','_')}).merge!((node.name + encode_node_path(node)).gsub('-','_') => node.content) }) && node.attributes.each {|key,value| attr_accessor_hash.merge!((key + encode_node_path(node)).gsub('-','_') => value.value)} && attr_accessor_hash.merge!((node.name + encode_node_path(node)).gsub('-','_') => node.content)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def child_node_ds(attr_accessor_hash)
|
69
|
+
_temp=[]
|
70
|
+
self.children.each do |node|
|
71
|
+
case [node.attributes.empty? , node.content.empty? ,node.children.empty?]
|
72
|
+
|
73
|
+
when [false, true, true] then _temp.push({(node.name + encode_node_path(node)).gsub('-','_') => node.attributes.transform_keys{|key| (key + encode_node_path(node)).gsub('-','_')}}) && node.attributes.each {|key,value| attr_accessor_hash.merge!((key + encode_node_path(node)).gsub('-','_') => value.value)}
|
74
|
+
|
75
|
+
when [true, false, false] then _temp.push({(node.parent.name + encode_node_path(node)).gsub('-','_') => node.content, :child_node => node.child_node_ds(attr_accessor_hash) }) && attr_accessor_hash.merge!((node.parent.name + encode_node_path(node)).gsub('-','_') => node.content)
|
76
|
+
|
77
|
+
when [false, true, false] then _temp.push({(node.name + encode_node_path(node)).gsub('-','_') => node.attributes.transform_keys{|key| (key + encode_node_path(node)).gsub('-','_')}, :child_node => node.child_node_ds(attr_accessor_hash)})&& node.attributes.each {|key,value| attr_accessor_hash.merge!((key + encode_node_path(node)).gsub('-','_') => value.value)}
|
78
|
+
|
79
|
+
when [false, false, false] then node_array.push({(node.name + encode_node_path(node)).gsub('-','_') => (node.attributes.transform_keys{|key| (key + encode_node_path(node)).gsub('-','_')}).merge!((node.name + encode_node_path(node)).gsub('-','_') => node.content)}) && node.attributes.each {|key,value| attr_accessor_hash.merge!((key + encode_node_path(node)).gsub('-','_') => value.value)} && attr_accessor_hash.merge!((node.name + encode_node_path(node)).gsub('-','_') => node.content)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
return _temp
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
data/lib/xml_to_form.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
== README
|
2
|
+
|
3
|
+
This README would normally document whatever steps are necessary to get the
|
4
|
+
application up and running.
|
5
|
+
|
6
|
+
Things you may want to cover:
|
7
|
+
|
8
|
+
* Ruby version
|
9
|
+
|
10
|
+
* System dependencies
|
11
|
+
|
12
|
+
* Configuration
|
13
|
+
|
14
|
+
* Database creation
|
15
|
+
|
16
|
+
* Database initialization
|
17
|
+
|
18
|
+
* How to run the test suite
|
19
|
+
|
20
|
+
* Services (job queues, cache servers, search engines, etc.)
|
21
|
+
|
22
|
+
* Deployment instructions
|
23
|
+
|
24
|
+
* ...
|
25
|
+
|
26
|
+
|
27
|
+
Please feel free to use a different markup language if you do not plan to run
|
28
|
+
<tt>rake doc:app</tt>.
|
data/test/dummy/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
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/rails/sprockets#sprockets-directives) for details
|
11
|
+
// about supported directives.
|
12
|
+
//
|
13
|
+
//= 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,14 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>Dummy</title>
|
5
|
+
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
|
6
|
+
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
|
7
|
+
<%= csrf_meta_tags %>
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
|
11
|
+
<%= yield %>
|
12
|
+
|
13
|
+
</body>
|
14
|
+
</html>
|
data/test/dummy/bin/rake
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'pathname'
|
3
|
+
|
4
|
+
# path to your application root.
|
5
|
+
APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
|
6
|
+
|
7
|
+
Dir.chdir APP_ROOT do
|
8
|
+
# This script is a starting point to setup your application.
|
9
|
+
# Add necessary setup steps to this file:
|
10
|
+
|
11
|
+
puts "== Installing dependencies =="
|
12
|
+
system "gem install bundler --conservative"
|
13
|
+
system "bundle check || bundle install"
|
14
|
+
|
15
|
+
# puts "\n== Copying sample files =="
|
16
|
+
# unless File.exist?("config/database.yml")
|
17
|
+
# system "cp config/database.yml.sample config/database.yml"
|
18
|
+
# end
|
19
|
+
|
20
|
+
puts "\n== Preparing database =="
|
21
|
+
system "bin/rake db:setup"
|
22
|
+
|
23
|
+
puts "\n== Removing old logs and tempfiles =="
|
24
|
+
system "rm -f log/*"
|
25
|
+
system "rm -rf tmp/cache"
|
26
|
+
|
27
|
+
puts "\n== Restarting application server =="
|
28
|
+
system "touch tmp/restart.txt"
|
29
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require File.expand_path('../boot', __FILE__)
|
2
|
+
|
3
|
+
require 'rails/all'
|
4
|
+
|
5
|
+
Bundler.require(*Rails.groups)
|
6
|
+
require "xml_to_form"
|
7
|
+
|
8
|
+
module Dummy
|
9
|
+
class Application < Rails::Application
|
10
|
+
# Settings in config/environments/* take precedence over those specified here.
|
11
|
+
# Application configuration should go into files in config/initializers
|
12
|
+
# -- all .rb files in that directory are automatically loaded.
|
13
|
+
|
14
|
+
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
|
15
|
+
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
|
16
|
+
# config.time_zone = 'Central Time (US & Canada)'
|
17
|
+
|
18
|
+
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
|
19
|
+
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
|
20
|
+
# config.i18n.default_locale = :de
|
21
|
+
|
22
|
+
# Do not swallow errors in after_commit/after_rollback callbacks.
|
23
|
+
config.active_record.raise_in_transactional_callbacks = true
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# SQLite version 3.x
|
2
|
+
# gem install sqlite3
|
3
|
+
#
|
4
|
+
# Ensure the SQLite 3 gem is defined in your Gemfile
|
5
|
+
# gem 'sqlite3'
|
6
|
+
#
|
7
|
+
default: &default
|
8
|
+
adapter: sqlite3
|
9
|
+
pool: 5
|
10
|
+
timeout: 5000
|
11
|
+
|
12
|
+
development:
|
13
|
+
<<: *default
|
14
|
+
database: db/development.sqlite3
|
15
|
+
|
16
|
+
# Warning: The database defined as "test" will be erased and
|
17
|
+
# re-generated from your development database when you run "rake".
|
18
|
+
# Do not set this db to the same as development or production.
|
19
|
+
test:
|
20
|
+
<<: *default
|
21
|
+
database: db/test.sqlite3
|
22
|
+
|
23
|
+
production:
|
24
|
+
<<: *default
|
25
|
+
database: db/production.sqlite3
|