module DesignStoryboard::Export
Constants
- REGEXP_RULE_FOR_FIND_IMAGE
- REGEXP_RULE_FOR_FIND_LINK
- REGEXP_RULE_FOR_FIND_LINK_AND_TITLE
Public Instance Methods
apply_html_template(title, html_syntax)
click to toggle source
# File lib/design_storyboard/export.rb, line 21 def apply_html_template(title, html_syntax) html = %Q( <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>#{title} by Design Storyboard</title> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <link rel="stylesheet" href="#{Setting[:stylesheet_path]}"> </head> <body> <div class="page-title"><h1>#{title}</h1></div> <div class="container">#{html_syntax}</div> <div class="footer"> <div class="copyright-info">Powered by <a target="_blank" href="https://github.com/guanting886/design-storyboard">Design Storyboard</a> 節省您作業時間的好工具 😎 </div> </div> </body> </html> ) end
create_css()
click to toggle source
# File lib/design_storyboard/export.rb, line 130 def create_css assets_dir_css_path = File.join(Setting[:assets_path], Setting[:stylesheet_dir_name], Setting[:stylesheet_file_name]) release_dir_css_path = File.join(Setting[:dump_dir_path], Setting[:stylesheet_dir_name], Setting[:stylesheet_file_name]) FileUtils.cp assets_dir_css_path, release_dir_css_path if not File.exist? release_dir_css_path end
generate_table(header_rows_syntax='', content_rows_syntax='')
click to toggle source
# File lib/design_storyboard/export.rb, line 82 def generate_table(header_rows_syntax='', content_rows_syntax='') html = %Q( <table class="storyboard" cellspacing="0" cellpadding="5"> #{header_rows_syntax} #{content_rows_syntax} </table> ) end
generate_table_cell(*args)
click to toggle source
# File lib/design_storyboard/export.rb, line 45 def generate_table_cell(*args) html = '<tr>' args.each_with_index do |value, index| value.gsub!(/\[(?<tag1>[^\]]+)\]/, '<span class="tag-1">[\k<tag1>]</span>') value.gsub!(/\「(?<tag2>[^\」]+)\」/, '<span class="tag-2">「\k<tag2>」</span>') value.gsub!(/\((?<tag3>[^\」]+)\)/, '<span class="tag-3">(\k<tag3>)</span>') value.gsub!(/\((?<tag3>[^\」]+)\)/, '<span class="tag-3">(\k<tag3>)</span>') value.gsub!(REGEXP_RULE_FOR_FIND_LINK_AND_TITLE, '<a href="\k<uri>" target="_blank">\k<title></a>') value.gsub!(REGEXP_RULE_FOR_FIND_LINK, '<a href="\k<uri>" target="_blank">\k<uri></a>') value.gsub!(REGEXP_RULE_FOR_FIND_IMAGE, '<img src="\k<uri>">') value.gsub!(/[\r\n]+/, '<br>') html << "<td class='col-#{index+1}'><div>#{value}</div></td>" end html << '</tr>' end
generate_table_header(*args)
click to toggle source
# File lib/design_storyboard/export.rb, line 70 def generate_table_header(*args) @storyboard_cols_count = args.length html = '<tr>' args.each_with_index do |value, index| html << "<th class='col-#{index+1}'>#{value}</th>" end html << '</tr>' end
generate_table_headline(title)
click to toggle source
# File lib/design_storyboard/export.rb, line 66 def generate_table_headline(title) "<tr class='headline'><td colspan='#{@storyboard_cols_count}'>#{title}</td></tr>" end
open_browser()
click to toggle source
# File lib/design_storyboard/export.rb, line 137 def open_browser `open "#{Setting[:dump_file_path]}"` end
output_storyboard(title, info_collection)
click to toggle source
# File lib/design_storyboard/export.rb, line 91 def output_storyboard(title, info_collection) start table_header_html = generate_table_header('Step', 'Description', 'Note') table_cells_html = "" info_collection.each do |info| if info.is_a? Hash table_cells_html << generate_table_cell(info[:step], info[:description], info[:note]) elsif info.is_a? String table_cells_html << generate_table_headline(info) else # ignore end end table_html = generate_table(table_header_html, table_cells_html) html_document = apply_html_template(title, table_html) save html_document end
save(content)
click to toggle source
# File lib/design_storyboard/export.rb, line 114 def save(content) start File.open(Setting[:dump_file_path], File::CREAT|File::TRUNC|File::RDWR, 0644) do |f| f.write content end done title 'Here you are' attention Setting[:dump_file_path] create_css if Setting[:auto_create_css] open_browser if Setting[:auto_open] end