class Blume

Public Class Methods

new(options_in = {}) click to toggle source
# File lib/blume/blume.rb, line 2
  def initialize(options_in = {})
          options = {
collection: nil,
content_directory: File.join(Dir.pwd, 'content'),
living_dangerously: true,
root_url: 'http://localhost:4567',
site_directory: File.join(Dir.pwd, 'site'),
assets: File.join(Dir.pwd, 'public')
       }.merge(options_in)
          @collection = options[:collection]
          @content_directory = options[:content_directory]
          @living_dangerously = options[:living_dangerously]
          @pilgrim = Pilgrim.new(options[:root_url], options[:site_directory], options[:assets])
  end

Public Instance Methods

build_collection() click to toggle source
# File lib/blume/blume.rb, line 17
def build_collection()
        @collection.remove()
        walk @content_directory
end
evil_mark(text) click to toggle source
# File lib/blume/blume.rb, line 56
def evil_mark text
        part = text.partition(/[^\\]\#{.*?}/)
        return_string = part[0]
        until part[1] == ""
                return_string << eval("\"" + part[1] + "\"")
                part = evil_mark(part[2]).partition(/[^\\]\#{.*?}/)
                return_string << part[0]
        end
        return_string.gsub!(/\\\#{.*?}/){|s| s[1..-1]}
        return return_string
end
generate_site(compress = true) click to toggle source
# File lib/blume/blume.rb, line 22
def generate_site(compress = true)
        @pilgrim.generate(compress)
end
parse(file, path) click to toggle source
# File lib/blume/blume.rb, line 39
def parse(file, path)
        post = YAML.load_file(file)
        post['type'] = path.sub(@content_directory,'').gsub(/\//, '-')[1..-1]
        post['title'] = File.basename(file,File.extname(file))[11..-1]
        post['date_time'] = Date.parse(File.basename(file, File.extname(file))[0..11]).
                to_time
        body = ""
        if @living_dangerously
                body = evil_mark(File.open(file,'rb').read.sub(/\-\-\-.*\-\-\-/m,'').lstrip)
        else
                body = File.open(file,'rb').read.sub(/\-\-\-.*\-\-\-/m,'').lstrip
        end
        post['body'] = RedCloth.new(body).to_html
        return post
end
walk(path) click to toggle source
# File lib/blume/blume.rb, line 26
def walk(path)
        Dir.foreach(path) do |f|
                unless f[0] == '.'
                        file = File.join(path, f)
                        if File.directory?(file)
                                walk file
                        else
                                @collection.insert(parse(file, path))
                        end
                end
        end
end