Kouhei Sutou
null+****@clear*****
Mon Jul 10 11:35:53 JST 2017
Kouhei Sutou 2017-07-10 11:35:53 +0900 (Mon, 10 Jul 2017) New Revision: 19ce0db6bf6addcb133c11ca3aea8e7ae6e384ad https://github.com/ranguba/chupa-text-http-server/commit/19ce0db6bf6addcb133c11ca3aea8e7ae6e384ad Message: Support formatting result Added files: app/views/extractions/_extracted.html.erb Modified files: app/assets/stylesheets/application.scss app/controllers/extractions_controller.rb app/helpers/extractions_helper.rb app/views/extractions/create.html.erb Modified: app/assets/stylesheets/application.scss (+23 -0) =================================================================== --- app/assets/stylesheets/application.scss 2017-07-10 10:58:58 +0900 (2b6a960) +++ app/assets/stylesheets/application.scss 2017-07-10 11:35:53 +0900 (b13e09b) @@ -35,3 +35,26 @@ form { } } } + +table { + @extend .table; + @extend .table-bordered; + @extend .table-striped; + @extend .table-hover; + @extend .table-responsive; +} + +section.text { + img { + float: left; + margin-right: 10px; + } + + pre { + white-space: pre-wrap; + } + + table { + clear: both; + } +} Modified: app/controllers/extractions_controller.rb (+2 -1) =================================================================== --- app/controllers/extractions_controller.rb 2017-07-10 10:58:58 +0900 (7e428e3) +++ app/controllers/extractions_controller.rb 2017-07-10 11:35:53 +0900 (4e015b0) @@ -11,8 +11,9 @@ class ExtractionsController < ApplicationController respond_to do |format| if****@extra*****? + @extracted =****@extra***** format.html { render :create } - format.json { render json: @extraction.extract } + format.json { render json: @extract } else format.html { render :show } format.json { render json: @extraction.errors, status: :unprocessable_entity } Modified: app/helpers/extractions_helper.rb (+17 -0) =================================================================== --- app/helpers/extractions_helper.rb 2017-07-10 10:58:58 +0900 (b35fbf5) +++ app/helpers/extractions_helper.rb 2017-07-10 11:35:53 +0900 (c9524e3) @@ -1,2 +1,19 @@ module ExtractionsHelper + def format_screenshot(screenshot) + return "" if screenshot.nil? + + data = screenshot["data"] + mime_type = screenshot["mime-type"] + encoding = screenshot["encoding"] + src = "data:#{mime_type}" + if encoding + src << ";#{encoding}" + src << "," + src << data + else + src << ";base64," + src << [data].pack("m*") + end + tag.img(src: src) + end end Added: app/views/extractions/_extracted.html.erb (+30 -0) 100644 =================================================================== --- /dev/null +++ app/views/extractions/_extracted.html.erb 2017-07-10 11:35:53 +0900 (6053273) @@ -0,0 +1,30 @@ +<section class="metadata"> + <h2>Metadata</h2> + <table> + <% @extracted.each do |key, value| -%> + <% next if key == "texts" -%> + <tr> + <th scope="row"><%= key %></th> + <td><%= value %></td> + </tr> + <% end -%> + </table> +</section> + +<% (@extracted["texts"] || []).each_with_index do |text, i| -%> + <section class="text"> + <h2>Text #<%= i + 1 %></h2> + <%= format_screenshot(text["screenshot"]) %> + <pre><%= text["body"] %></pre> + <table> + <% text.each do |key, value| -%> + <% next if key == "body" -%> + <% next if key == "screenshot" -%> + <tr> + <th scope="row"><%= key %></th> + <td><%= value %></td> + </tr> + <% end -%> + </table> + </section> +<% end -%> Modified: app/views/extractions/create.html.erb (+1 -1) =================================================================== --- app/views/extractions/create.html.erb 2017-07-10 10:58:58 +0900 (479c644) +++ app/views/extractions/create.html.erb 2017-07-10 11:35:53 +0900 (584d52b) @@ -2,4 +2,4 @@ <%= render 'form', extraction: @extraction %> -<pre><code><%= JSON.pretty_generate(@extraction.extract) %></code></pre> +<%= render 'extracted', extracted: @extracted %> -------------- next part -------------- HTML����������������������������... Download