Class: Yuzu::Content::BlogPost

Inherits:
Object
  • Object
show all
Defined in:
lib/yuzu/content/blog_post.rb

Instance Method Summary collapse

Constructor Details

#initialize(postname, config) ⇒ BlogPost

Returns a new instance of BlogPost.



4
5
6
7
8
# File 'lib/yuzu/content/blog_post.rb', line 4

def initialize(postname, config)
  @postname = postname
  @filename = postname.dasherize.downcase
  @config = config
end

Instance Method Details

#contentsObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/yuzu/content/blog_post.rb', line 29

def contents
  return %Q{# #{@postname}

The title of this post is #{@postname}.

Lorem ipsum dolor sit amet, consectetur adipisicing elit, 
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim 
ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip 
ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate 
velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat 
cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id 
est laborum.
}
end

#deliver!Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/yuzu/content/blog_post.rb', line 10

def deliver!
  date = Time.now.strftime("%Y-%m-%d")
  full_filename = "#{date}-#{@filename}.md"

  file_path = File.join(@config.blog_dir, full_filename)

  if File.exists?(file_path)
    $stderr.puts "Warning: File #{@filename} already exists!"

  else
    $stderr.puts "Creating file: #{@filename}"

    File.open(file_path, "w+") do |f|
      f.puts(contents)
    end

  end
end