From a3231e9e1661484e7de4925696296c779d7715de Mon Sep 17 00:00:00 2001 From: Cecil Date: Fri, 16 Dec 2016 21:21:00 -0700 Subject: [PATCH] for #5, * rename ebook.rb to be ebook-builder.rb * add GUI support to (re)order the the sections (aka chapters) * add GUI support to (re)order the files in display order in a section * Many things could be better GUI wise - go for it. * It's TOC that should work well enough to get help_ebook.rb tested * useless crud in yaml exists - probably * does not auto parse the nav document and build the TOC automagically because that's not a priority. Remember - we still can't render anything with acceptable fidelity. --- ebook.rb => ebook-builder.rb | 54 ++++++++++++++++++++++++++++++++++-- 1 file changed, 51 insertions(+), 3 deletions(-) rename ebook.rb => ebook-builder.rb (78%) diff --git a/ebook.rb b/ebook-builder.rb similarity index 78% rename from ebook.rb rename to ebook-builder.rb index f3471de..5e58af2 100644 --- a/ebook.rb +++ b/ebook-builder.rb @@ -141,6 +141,9 @@ @panel.clear do el_v = [] el_t = [] + para "Order the sections starting with 1, 0 means delete." + para "Save will write to #{cfg['doc_home']}/.ebook/ebook.yaml" + para "Important: Save before you move to other options." flow do button "cancel" do Shoes.quit @@ -148,7 +151,12 @@ button "save" do cfg['toc']['section_order'] = [] # TODO: Magic occurs - + el_v.each_index do |i| + ord = el_v[i].text.to_i + if ord > 0 + cfg['toc']['section_order'][ord-1] = el_t[i].text + end + end File.open("#{cfg['doc_home']}/.ebook/ebook.yaml", 'w') do |f| YAML.dump(cfg, f) end @@ -159,8 +167,8 @@ flow do eln = edit_line width: 30 el_v << eln - t = cfg['sections'][pos][:title] - elt = edit_line text: t, width: 200 + t = cfg['sections'][pos][:dir] + elt = edit_line text: t, width: 200, state: "readonly" el_t << elt end end @@ -169,6 +177,46 @@ end button "order sections" do + @panel.clear do + para "Select section to view the documents. Order them from 1. 0 means delete" + para "Important: Save after modifing each section before selecting the next!" + el_v = [] + el_t = [] + sect = {} + flow do + button "Quit" do + Shoes.quit + end + button "Save" do + sect[:display_order] = [] + el_v.each_index do |i| + ord = el_v[i].text.to_i + if ord > 0 + sect[:display_order][ord-1] = el_t[i].text + end + end + File.open("#{cfg['doc_home']}/.ebook/ebook.yaml", 'w') do |f| + YAML.dump(cfg, f) + end + end + list_box items: cfg['toc']['section_order'] do |lb| + item = lb.text + @chapter.clear do + sect = cfg['sections'][item] + files = sect[:files] + files.each_index do |i| + flow do + eln = edit_line text: "#{i+1}", width: 30 + el_v << eln + elt = edit_line text: files[i], width: 200, state: "readonly" + el_t << elt + end + end + end + end + end + @chapter = stack + end end button "render" do