Class: SimpleBlog

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

Class Method Summary collapse

Class Method Details

.list_articles(tag = "", in_progress: "true") ⇒ Object



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

def self.list_articles(tag = "", in_progress: "true")
  articles_yml_result = YAML.load_file("app/articles/articles.yml")["articles"]
  articles = Article.build_list_of_articles(articles_yml_result)

  if tag.present?
    articles = articles.filter { |article| article.tags.include?(tag) }
  end

  if in_progress == "true"
    articles = articles.filter { |article| article.in_progress }
  else
    articles = articles.filter { |article| !article.in_progress }
  end

  articles.sort_by(&:id).reverse!
end

.render_article(id) ⇒ Object



18
19
20
21
22
23
# File 'lib/simpleblog.rb', line 18

def self.render_article(id)
  article_content = File.open("app/articles/#{id.to_i}.md").read
  markdown = Redcarpet::Markdown.new(ArticleHTMLRender, fenced_code_blocks: true)

  markdown.render(article_content)
end