Kouhei Sutou
null+****@clear*****
Mon Jul 10 10:58:58 JST 2017
Kouhei Sutou 2017-07-10 10:58:58 +0900 (Mon, 10 Jul 2017) New Revision: 1dea51bcc8139de8b654e3c2da2625435d0a5b01 https://github.com/ranguba/chupa-text-http-server/commit/1dea51bcc8139de8b654e3c2da2625435d0a5b01 Message: Support URI Modified files: app/assets/stylesheets/application.scss app/controllers/extractions_controller.rb app/models/extraction.rb app/views/extractions/_form.html.erb Modified: app/assets/stylesheets/application.scss (+4 -0) =================================================================== --- app/assets/stylesheets/application.scss 2017-07-05 17:35:01 +0900 (d41722e) +++ app/assets/stylesheets/application.scss 2017-07-10 10:58:58 +0900 (2b6a960) @@ -20,6 +20,10 @@ form { input[type=file] { @extend .form-control-file; } + + input[type=text] { + @extend .form-control; + } } .actions { Modified: app/controllers/extractions_controller.rb (+4 -2) =================================================================== --- app/controllers/extractions_controller.rb 2017-07-05 17:35:01 +0900 (780831a) +++ app/controllers/extractions_controller.rb 2017-07-10 10:58:58 +0900 (7e428e3) @@ -14,7 +14,7 @@ class ExtractionsController < ApplicationController format.html { render :create } format.json { render json: @extraction.extract } else - format.html { render :new } + format.html { render :show } format.json { render json: @extraction.errors, status: :unprocessable_entity } end end @@ -23,6 +23,8 @@ class ExtractionsController < ApplicationController private # Never trust parameters from the scary internet, only allow the white list through. def extraction_params - params.permit(:input) + params + .except(:format, :utf8, :authenticity_token, :commit) + .permit(:data, :uri) end end Modified: app/models/extraction.rb (+14 -4) =================================================================== --- app/models/extraction.rb 2017-07-05 17:35:01 +0900 (4c9ca12) +++ app/models/extraction.rb 2017-07-10 10:58:58 +0900 (503fdce) @@ -1,8 +1,10 @@ class Extraction include ActiveModel::Model - attr_accessor :input - validates :input, presence: true + attr_accessor :data + attr_accessor :uri + + validates :data, presence: true, if: ->(record) {record.uri.blank?} def persisted? false @@ -19,8 +21,16 @@ class Extraction configuration_loader.load(Rails.root + "config" + "chupa-text.rb") extractor.apply_configuration(configuration) - data = ChupaText::VirtualFileData.new(Pathname(@input.original_filename), - @input.to_io) + if @data + data_uri = @uri + data_uri = nil if data_uri.blank? + if data_uri.nil? and****@data*****_filename + data_uri = Pathname(@data.original_filename) + end + data = ChupaText::VirtualFileData.new(data_uri, @data.to_io) + else + data = ChupaText::InputData.new(@uri) + end formatter = ChupaText::Formatters::Hash.new formatter.format_start(data) extractor.extract(data) do |extracted| Modified: app/views/extractions/_form.html.erb (+7 -2) =================================================================== --- app/views/extractions/_form.html.erb 2017-07-05 17:35:01 +0900 (42886d4) +++ app/views/extractions/_form.html.erb 2017-07-10 10:58:58 +0900 (68bcbd5) @@ -12,8 +12,13 @@ <% end %> <div class="field"> - <%= form.label :input %> - <%= form.file_field :input, id: :extraction_input, name: :input %> + <%= form.label :data %> + <%= form.file_field :data, id: :extraction_data, name: :data %> + </div> + + <div class="field"> + <%= form.label :uri, "URI (optional)" %> + <%= form.text_field :uri, id: :extraction_uri, name: :uri %> </div> <div class="actions"> -------------- next part -------------- HTML����������������������������... Télécharger