diff --git a/ebook-builder.rb b/ebook-builder.rb index 01630b5..fab4ecd 100644 --- a/ebook-builder.rb +++ b/ebook-builder.rb @@ -2,6 +2,7 @@ require 'yaml' Shoes.app :width => 800 do yaml_fl = ARGV[1] + puts "yaml file #{yaml_fl}" cfg = {} if yaml_fl cfg = YAML.load_file(yaml_fl) @@ -171,7 +172,7 @@ end # Process the toc/menu documents if available and github nested - if cfg['toc']['root'] && cfg['nested'] == true + if cfg['toc']['root'] # && cfg['nested'] == true @menu_list = [] Dir.chdir(cfg['doc_home']) do |p| f = "#{p}/#{cfg['toc']['root']}" @@ -218,7 +219,8 @@ @err_box.append("Done - You can save if you want\n") end else - puts "no toc to deal with" + # TODO: we need to do better perhaps set section_order + puts "no toc to deal with, faking it" end end end diff --git a/help_picky.rb b/help_picky.rb index b3ad750..e5c3830 100644 --- a/help_picky.rb +++ b/help_picky.rb @@ -251,8 +251,9 @@ def load_docs path @sections[k] = hsh [k, hsh] end - $DEBUGF.flush if $DEBUG + #$DEBUGF.flush if $DEBUG @search.finish! + puts @docs.inspect @docs end diff --git a/kd-render.rb b/kd-render.rb index dd0e89b..1c073eb 100644 --- a/kd-render.rb +++ b/kd-render.rb @@ -1,6 +1,7 @@ # https://github.com/Shoes3/shoes3/wiki # http://www.w3schools.com/tags/tag_li.asp # http://stackoverflow.com/questions/4900167/override-module-method-from-another-module +# cjc : This has to populate the cfg sections and add to the picky db require("rouge") require("kramdown") @@ -24,7 +25,7 @@ class ShoesFormatter < Formatter def initialize(options) @inline_theme = options.fetch(:inline_theme, nil) @inline_theme = Theme.find(@inline_theme).new if @inline_theme.is_a? String - puts @inline_theme.render + #puts @inline_theme.render end def stream(tokens, &b) @@ -42,9 +43,14 @@ module Converter class Shoes < Base ##include ShoesRouge def initialize(root, options) - super + @cfg = options[:cfg] + if @cfg + puts "have cfg in" + end + @chapter = options[:chapter] ## options[:syntax_highlighter] = "rouge" #puts options + super end DISPATCHER = Hash.new {|h,k| h[k] = "convert_#{k}"} @@ -114,11 +120,11 @@ def convert_a(el) # TODO: syntax highlight not working (no errors - just doesn't return anything) def convert_codespan(el) - puts el + #puts el ##puts highlight_code(el.value, el.attr['class'], :span) ##h = ::Kramdown::Converter.syntax_highlighter(@options[:syntax_highlighter]) ##puts h.call(self, el.value, el.attr['class'], :span) - puts syntax_highlighter(self, el.value, el.attr['class'], :span) + #puts syntax_highlighter(self, el.value, el.attr['class'], :span) end def convert_codeblock(el) @@ -131,11 +137,18 @@ def convert_strong(el) end def convert_img(el) - puts el.attr['src'] - #%[image "#{el.attr['src']}"] # crashes shoes + #puts el.attr['src'] url = el.attr['src'] ext = File.extname(url); - %[para "IMAGE_HERE: #{el.attr['alt']}#{ext}"] + #%[para "IMAGE_HERE: #{@cfg['doc_home']}/#{el.attr['alt']}#{ext}"] + lcl = @cfg['sections'][@chapter]['images'][url] + if lcl + #puts "found local image #{lcl}" + %[image "#{@cfg['doc_home']}/.ebook/images/#{lcl}"] + else + puts "Bad Boy! sucking images from #{url}" + %[image "{#url}"] + end end def convert_typographic_sym(el) diff --git a/kramdown001.rb b/kramdown001.rb index 28a72e2..f3cd878 100644 --- a/kramdown001.rb +++ b/kramdown001.rb @@ -145,6 +145,6 @@ def rendering(e) Shoes.app { doc = Kramdown::Document.new(File.read("fts-md/manual-en.txt"), { :syntax_highlighter => "rouge", :syntax_highlighter_opts => { css_class: false, line_numbers: false, inline_theme: "github" } }).to_shoes - info doc.inspect + #info doc.inspect rendering(doc) } diff --git a/show_ebook.rb b/show_ebook.rb index 7b1ba32..004f5cd 100644 --- a/show_ebook.rb +++ b/show_ebook.rb @@ -3,74 +3,86 @@ # script or the by the ebook-builder. Beware the path names. module Shoes::Ebook require 'kd-render' - def render_section - if cfg['nested'] - cfg['sections'].each do |section, section_hash| - section_hash[:files].each do |fl| - #puts "render document #{fl}" - #para "document #{fl}" - docpath = File.join(cfg['doc_home'], section_hash[:dir], fl) - puts "deep render #{docpath}" - render_doc = Kramdown::Document.new(File.read(docpath), - { :syntax_highlighter => "rouge", - :syntax_highlighter_opts => { css_class: false, line_numbers: false, inline_theme: "github" }, - input: cfg['input_format'] - } - ).to_shoes - rendering(render_doc) + require 'search_picky' + def render_file (cfg, sect_nm, dir, file) + render_doc = Kramdown::Document.new(File.read(File.join(dir, file)), + { :syntax_highlighter => "rouge", + :syntax_highlighter_opts => { css_class: false, line_numbers: false, inline_theme: "github" }, + input: cfg['input_format'], + cfg: cfg, chapter: sect_nm, input: cfg['input_format'] + } + ).to_shoes + rendering(render_doc) + end + + # this will get confusing very quickly. Not that the manual made much sense. + # calls picky to create the indices + # + def load_docs(cfg) + puts "load_docs nested? #{cfg['nested']}" + # need a structure to hold the generated Shoes code + @search = Search.new + @sections, @methods, @mindex = {}, {}, {} + cfg['link_hash'] = {} + cfg['code_struct'] = [] # array of hashes + if cfg['nested'] # what's difference between 'display_order' and :display_order ? + cfg['toc']['section_order'].each_index do |si| + sect_name = cfg['toc']['section_order'][si] + puts "going into #{sect_name}" + sect_intro = cfg['toc']['files'][si] + # do we want to parse this and display it? I think yes but not until + # we can test many other things that can invalidate the whole project + sect = cfg['sections'][sect_name] # this is a hash + sect['display_order'].each do |fl| + puts "render #{cfg['doc_home']}/#{cfg[sect]}/#{fl}" + #render_file(cfg, "#{cfg['doc_home']}/#{cfg[sect]}", fl) end end else - # flat dir of md - cfg['sections'].each do |section, section_hash| - section_hash[:files].each do |fl| - #puts "render document #{fl}" - #para "document #{fl}" - docpath = File.join(cfg['doc_home'], fl) - puts "flat render #{docpath}" - render_doc = Kramdown::Document.new(File.read(docpath), - { :syntax_highlighter => "rouge", - :syntax_highlighter_opts => { css_class: false, line_numbers: false, inline_theme: "github" }, - input: cfg['input_format'], gfm_quirks: ['hard_wrap'], - } - ).to_shoes - rendering(render_doc) + # not a nested github mess + # parse the root doc. + top_c = render_file(cfg, cfg['toc']['section_order'][0], cfg['doc_home'], cfg['toc']['root']) + landing = {title: "Home", code: top_c} + cfg['code_struct'] << landing + cfg['link_hash']['Home'] = landing + #puts "topc: #{top_c.inspect}" + cfg['toc']['section_order'].each_index do |si| + sect_name = cfg['toc']['section_order'][si] + puts "going into #{sect_name}" + sect = cfg['sections'][sect_name] # this is a hash + sect[:display_order].each do |fl| + puts "render #{cfg['doc_home']}/#{fl}" + contents = render_file(cfg, sect_name, cfg['doc_home'], fl) + landing = {title: sect[:title], code: contents} + cfg['code_struct'] << landing + cfg['link_hash'][sect[:title]] = landing end end + end - #cfg['files'].each do |relpath| - # render_doc = Kramdown::Document.new(File.read(@doc), - # { :syntax_highlighter => "rouge", - # :syntax_highlighter_opts => { css_class: false, line_numbers: false, inline_theme: "github" }, - # input: 'GFM' - # } - # ).to_shoes - # rendering(render_doc) - #end - end - - # this will get confusing very quickly. - # calls picky to load the indices - # - def load_docs(cfg) - puts "load_docs nested #{cfg['nested']}" - # first, render the toc[root] document on the opening screen - # then grind though the sections and capture the sub-subsection (methods) - # in Shoes manual parlance. - return [] + return cfg['code_struct'] end - def get_title(sect_num) - if @@cfg['nested'] + def get_title(cfg, sect_num) + if cfg['nested'] if sect_num == 0 # intro page - return @@cfg['book_title'] + return cfg['book_title'] else - sect_nm = @@cfg['toc']['section_order'][section] - return @@cfg['sections'][sect_nm]['title'] + sect_nm = cfg['toc']['section_order'][section] + return cfg['sections'][sect_nm]['title'] end else - ka = @@cfg['sections'].keys - return @@cfg['sections'][ka[sect_num]][:title] + ka = cfg['sections'].keys + return cfg['sections'][ka[sect_num]][:title] + end + end + + def open_section(cfg, title) + here = cfg['link_hash'][title] + puts "Open #{title} goes to #{here[:title]}" + @doc.clear do + #puts "DO THIS: #{here[:code]}" + instance_eval here[:code][0] end end @@ -129,19 +141,22 @@ def Shoes.make_ebook(test = false) end } + # title bar: stack do background black stack :margin_left => 118 do - para book_title, :stroke => "#eee", :margin_top => 8, :margin_left => 17, + para @@cfg[:book_title], :stroke => "#eee", :margin_top => 8, :margin_left => 17, :margin_bottom => 0 # @title will change dynamiclly - @title = title get_title(0), :stroke => white, :margin => 4, :margin_left => 14, + @title = title @@cfg[:book_title], :stroke => white, :margin => 4, :margin_left => 14, :margin_top => 0, :font => "Coolvetica" end background "rgb(66, 66, 66, 180)".."rgb(0, 0, 0, 0)", :height => 0.7 background "rgb(66, 66, 66, 100)".."rgb(255, 255, 255, 0)", :height => 20, :bottom => 0 + puts "title bar is set up for #{@@cfg['book_title']}" end - # @doc is the canvas for drawing content (pre-built Shoes coded (load_docs) + + # @doc is the slot for drawing content: (pre-built) Shoes code from load_docs @doc = #stack :margin_left => 130, :margin_top => 20, :margin_bottom => 50, :margin_right => 50 + gutter, # &dewikify(docs[0][-1]['description'], true) @@ -166,18 +181,24 @@ def Shoes.make_ebook(test = false) end @toc = {} stack :margin => 12, :width => 130, :margin_top => 20 do - docs.each do |sect_s, sect_h| - sect_cls = sect_h['class'] - para strong(link(sect_s, :stroke => black) { open_section(sect_s) }), - :size => 11, :margin => 4, :margin_top => 0 - @toc[sect_cls] = - stack :hidden => @toc.empty? ? false : true do - links = sect_h['sections'].map do |meth_s, meth_h| - [link(meth_s) { open_methods(meth_s) }, "\n"] - end.flatten - links[-1] = {:size => 9, :margin => 4, :margin_left => 10} - para *links - end + #docs.each do |sect_s, sect_h| + # sect_cls = sect_h['class'] + # para strong(link(sect_s, :stroke => black) { open_section(sect_s) }), + # :size => 11, :margin => 4, :margin_top => 0 + # @toc[sect_cls] = + # stack :hidden => @toc.empty? ? false : true do + # links = sect_h['sections'].map do |meth_s, meth_h| + # [link(meth_s) { open_methods(meth_s) }, "\n"] + # end.flatten + # links[-1] = {:size => 9, :margin => 4, :margin_left => 10} + # para *links + # end + # end + @@cfg['code_struct'].each do |hsh| + title = hsh[:title] + puts "Menu Title: #{title}" + para strong(link(title, stroke: black) { open_section @@cfg, title }), + size: 11, margin: 4, margin_top: 0 end end stack :margin => 12, :width => 118, :margin_top => 6 do