Class: Sancho::Task::BuildSite
- Defined in:
- lib/sancho/tasks/build_site.rb
Overview
Build site
Constant Summary collapse
- PANDOC_OPTIONS =
"-s --toc --template #{Sancho::LAYOUTS_DIR}/layout.html -c css/styles.css"
Class Method Summary collapse
Class Method Details
.run(config) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/sancho/tasks/build_site.rb', line 11 def self.run(config) %w[images css jss] .map{ File.join(config.directory, it) } .each{ mkdir_p it } styles = File.join(Sancho::LAYOUTS_DIR, 'styles.css') cp styles, File.join(config.directory, 'css') pages = config.pages.map{ Model::Page.from(it) } index = config.pages.find{ it.downcase =~ /^index/ } pages << Model::Page.from(config.pages.first, 'index.html') \ unless index site = Model::Site.new( domain: config.domain, title: config.title, pages:) # process erb require site variable Dir["#{Sancho::LAYOUTS_DIR}/*.erb"].each do |erb| content = ERB.new(File.read(erb), trim_mode: '%').result(binding) filename = File.join(config.directory, File.basename(erb,'.erb')) File.write(filename, content) end srcdir = Dir.pwd Dir.mktmpdir do |dir| header = File.join(dir, 'header.html') = File.join(dir, 'footer.html') system "pandoc -o #{header} #{Sancho::LAYOUTS_DIR}/header.md" system "pandoc -o #{} #{Sancho::LAYOUTS_DIR}/footer.md" optns = PANDOC_OPTIONS + " -B #{header} -A #{}" site.pages.each{ source = File.join(srcdir, it.source) system "pandoc #{optns} -o #{config.directory}/#{it.url} #{source}" } end end |