Class: Blume
- Inherits:
-
Object
- Object
- Blume
- Defined in:
- lib/blume/blume.rb
Instance Method Summary collapse
- #build_collection ⇒ Object
- #evil_mark(text) ⇒ Object
- #generate_site(compress = true) ⇒ Object
-
#initialize(options_in = {}) ⇒ Blume
constructor
A new instance of Blume.
- #parse(file, path) ⇒ Object
- #walk(path) ⇒ Object
Constructor Details
#initialize(options_in = {}) ⇒ Blume
Returns a new instance of Blume.
2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/blume/blume.rb', line 2 def initialize( = {}) = { 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() @collection = [:collection] @content_directory = [:content_directory] @living_dangerously = [:living_dangerously] @pilgrim = Pilgrim.new([:root_url], [:site_directory], [:assets]) end |
Instance Method Details
#build_collection ⇒ Object
17 18 19 20 |
# File 'lib/blume/blume.rb', line 17 def build_collection() @collection.remove() walk @content_directory end |
#evil_mark(text) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 |
# 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) ⇒ Object
22 23 24 |
# File 'lib/blume/blume.rb', line 22 def generate_site(compress = true) @pilgrim.generate(compress) end |
#parse(file, path) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# 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) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 |
# 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 |