lib/verku/exporter/base.rb in verku-0.15.0 vs lib/verku/exporter/base.rb in verku-0.16.0

- old
+ new

@@ -2,14 +2,16 @@ require "English" module Verku class Exporter class Base - + attr_accessor :root_dir # The e-book directory. attr_accessor :source # Where the text files are stored. - + + EXTENSIONS = %w[markdown mkdown mkdn mkd md text] + def handle_error(error) ui.say "#{error.class}: #{error.message}", :red ui.say error.backtrace.join("\n"), :white end def self.export!(root_dir) @@ -17,42 +19,66 @@ end def initialize(root_dir) @root_dir = Pathname.new(root_dir) @source = root_dir.join("text") - # @build = Build.new end # Return directory's basename. def name File.basename(root_dir) end + def git_branch + branch = if (File.exist?(root_dir.join(".git/HEAD"))) + File.read( root_dir.join(".git/HEAD") ).sub("ref: refs/heads/","").sub(/\n/,'') + else + "none" + end + return branch + end + def base_name(ext='') + oname = "#{name}-#{git_branch}" + end + def output_name(ext='txt') + root_dir.join("builds/#{base_name}.#{ext}") + end # Return the configuration file. def config Verku.config(root_dir) end - # def build_data - # Verku.build(root_dir) - # end + def build_data + source_list.each do |file| + data = read_content(file)[1] + end + end + def source_list - @source_list ||= SourceList.new(root_dir) + # @source_list ||= SourceList.new(root_dir) + @source_list ||= Dir.glob("#{@root_dir.join('text')}/**/*.{#{EXTENSIONS.join(",")}}") end def render_template(file, locals = {}) ERB.new(File.read(file)).result OpenStruct.new(locals).instance_eval{ binding } end def ui @ui ||= Thor::Base.shell.new end + def html_file + output_name("html") + end + def epub_file + output_name("epub") + end + def tex_file + output_name("tex") + end def read_content(file) content = File.read(file) data = {} begin # YAML_FRONT_MATTER_REGEXP = /\A(---\s*\n.*?\n?)^((---|\.\.\.)\s*$\n?)/m if content =~ /\A(---\s*\n.*?\n?)^((---|\.\.\.)\s*$\n?)/m - # content = "\n#{$'}\n" content = $POSTMATCH - # data = SafeYAML.load($1) data = YAML.load($1, :safe => true) end return [content, data] rescue SyntaxError => e puts "YAML Exception reading #{file}: #{e.message}"