Sha256: 65c388882959e0dffc6fd2dd9e95783c0319a9c8fdc51bc836519e0e60e96b8f

Contents?: true

Size: 897 Bytes

Versions: 3

Compression:

Stored size: 897 Bytes

Contents

module Blogdown
  class PreviewApp<Sinatra::Application

    helpers do
      def built_files
        @output=ENV['BD']+'/output'
        @files =[]
        out    =Pathname(@output)
        out.each_child do |child|
          if child.extname==".html"
            @files<<child
          end
        end
        @files
      end
    end
    get '/' do
      erb :home, :layout => :base
    end


    # Serves generated files found in the ouput folder
    # It does so, by reading the files, and dumping the string to be rendered with `erb`
    get '/post/:name' do |file_name|
      @source_dir=ENV['BD']+'/output/'+file_name.gsub('-', '_')+'.md.html'
      @path      =Pathname(@source_dir)
      if @path.file?
        @title=@path.basename.to_s.gsub('.html', '')
        erb @path.read, :layout => :post
      else
        halt 404
      end
  end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
blogdown-0.1.2 lib/blogdown/app.rb
blogdown-0.1.1 lib/blogdown/app.rb
blogdown-0.1.0 lib/blogdown/app.rb