Sha256: b95c7b2c55cde68619bcbb64b31a07a104759694139a4c24aa4189c1375a25ef

Contents?: true

Size: 1.4 KB

Versions: 3

Compression:

Stored size: 1.4 KB

Contents

require_dependency "xml_to_form/application_controller"
require 'noko_hacks'
require_dependency 'xml_to_form/xml_handler.rb'

module XmlToForm
  class XmlHandlersController < ApplicationController
    include NokoHacks
    before_action :fetch_data, except: [:upload_file]

    ## @node_set is an array of each node with child and attributes which is representing the form in recursive way
    ## @attr_accessors is an hash where key is xml tag and their Base64 encoded path and value is there values
    ## @xml_obj is only the parsed object of nokogiri from xml
    ## @xml_data is the initialized object with their values which represents the form

    def upload_file
    end

    def xml_form
      @xml_data = XmlHandler.new(@attr_accessors)
    end

    def xml_update
      @xml = XmlHandler.new(params[:xml_data])
      params[:xml_handler].each do |key, value|
        node = @xml_obj.at(decode_node_path(key))
        update_xml(node, key, value)
        if !node.content.empty? && !node.attributes.empty?
          node.content = value
        end
      end
      File.open('public/updated.xml', 'w') { |f| f.write(@xml_obj) }
      send_file(File.join(Rails.root, 'public', 'updated.xml'))
    end

    private
    def fetch_data
      params[:file] ? @file= File.read(params[:file].tempfile) : @file = params[:file_content]
      @node_set, @attr_accessors, @xml_obj= XmlHandler.noko_meta_data(@file)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
xml_to_form-0.0.4 app/controllers/xml_to_form/xml_handlers_controller.rb
xml_to_form-0.0.3 app/controllers/xml_to_form/xml_handlers_controller.rb
xml_to_form-0.0.2 app/controllers/xml_to_form/xml_handlers_controller.rb