Class: Msgtrail::Blog

Inherits:
Object
  • Object
show all
Defined in:
lib/msgtrail/blog.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Blog

Returns a new instance of Blog.



6
7
8
# File 'lib/msgtrail/blog.rb', line 6

def initialize(config)
  self.config = config
end

Instance Attribute Details

#articlesObject

Returns the value of attribute articles.



4
5
6
# File 'lib/msgtrail/blog.rb', line 4

def articles
  @articles
end

#configObject

Returns the value of attribute config.



4
5
6
# File 'lib/msgtrail/blog.rb', line 4

def config
  @config
end

Instance Method Details

#fetch_article_contentObject



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/msgtrail/blog.rb', line 42

def fetch_article_content
  self.articles.each do |article|
    if article.has_key?(:file)
      Article.fetch_file_based_article(self.config.working_directory, article)
    elsif article.has_key?(:gist_id)
      Article.fetch_gist_based_article(article)
    elsif article.has_key?(:tweet_ids)
      Article.fetch_tweet_based_article(article)
    else
      puts("Error preparing article based on '#{article}'")
    end
  end
end

#fetch_blog_articlesObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/msgtrail/blog.rb', line 10

def fetch_blog_articles
  begin
    filepath = File.join(self.config.working_directory, self.config.settings.file_matter.blog_manifest_file)
    manifest = File.read(filepath)
  rescue
    puts("Can't find blog manifest '#{filepath}' (#{$!})")
    exit(2)
  end
  begin
    self.articles = MultiJson.load(manifest, symbolize_keys: true)
  rescue
    puts("Invalid JSON in '#{filepath}' (#{$!})")
    exit(2)
  end
end

#generate_article_slugsObject



56
57
58
59
60
# File 'lib/msgtrail/blog.rb', line 56

def generate_article_slugs
  self.articles.each do |article|
    article[:slug] = Slug.generate(article[:title], article[:published][:date], article[:published][:time])
  end
end

#prepare_output_directoryObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/msgtrail/blog.rb', line 26

def prepare_output_directory
  directory = File.join(self.config.working_directory, self.config.settings.file_matter.blog_directory)
  begin
    FileUtils.remove_dir(directory)
    puts("Deleted '#{directory}'")
  rescue
    # It is OK if this directory doesn't exist.
  end
  begin
    FileUtils.mkdir(directory)
    puts("Created '#{directory}'")
  rescue
    puts("Can't create '#{directory}' (#{$!})")
  end
end