Class: QiitaExport::Article

Inherits:
Object
  • Object
show all
Defined in:
lib/qiita-export/article.rb

Constant Summary collapse

HTML_TEMPLATE =
<<-"EOS"
  <!DOCTYPE html>
  <html>
    <head>
      <meta charset="UTF-8" />
      <title><%= @title %></title>
    </head>
    <body>
      <h1><%= @title %></h1>
      <%= @rendered_body %>
    </body>
  </html>
EOS

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, url, title, raw_body, rendered_body, created_at, updated_at, user_id) ⇒ Article

Returns a new instance of Article.



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/qiita-export/article.rb', line 23

def initialize(key, url, title, raw_body, rendered_body, created_at, updated_at, user_id)
  @key           = key
  @url           = url
  @title         = title
  @raw_body      = raw_body
  @rendered_body = rendered_body
  @created_at    = created_at
  @updated_at    = updated_at
  @user_id       = user_id
  @images        = Image.extract_urls(@key, @raw_body)
end

Instance Attribute Details

#created_atObject (readonly)

Returns the value of attribute created_at.



6
7
8
# File 'lib/qiita-export/article.rb', line 6

def created_at
  @created_at
end

#imagesObject (readonly)

Returns the value of attribute images.



6
7
8
# File 'lib/qiita-export/article.rb', line 6

def images
  @images
end

#keyObject (readonly)

Returns the value of attribute key.



6
7
8
# File 'lib/qiita-export/article.rb', line 6

def key
  @key
end

#raw_bodyObject (readonly)

Returns the value of attribute raw_body.



6
7
8
# File 'lib/qiita-export/article.rb', line 6

def raw_body
  @raw_body
end

#rendered_bodyObject (readonly)

Returns the value of attribute rendered_body.



6
7
8
# File 'lib/qiita-export/article.rb', line 6

def rendered_body
  @rendered_body
end

#titleObject (readonly)

Returns the value of attribute title.



6
7
8
# File 'lib/qiita-export/article.rb', line 6

def title
  @title
end

#updated_atObject (readonly)

Returns the value of attribute updated_at.



6
7
8
# File 'lib/qiita-export/article.rb', line 6

def updated_at
  @updated_at
end

#urlObject (readonly)

Returns the value of attribute url.



6
7
8
# File 'lib/qiita-export/article.rb', line 6

def url
  @url
end

#user_idObject (readonly)

Returns the value of attribute user_id.



6
7
8
# File 'lib/qiita-export/article.rb', line 6

def user_id
  @user_id
end

Instance Method Details

#saveObject



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/qiita-export/article.rb', line 35

def save
  save_dir  = File.join(Config.export_dir_path, Config.team_name(@url), @key)

  FileUtils.makedirs(save_dir) unless Dir.exists?(save_dir)

  file_path = File.join(save_dir, Config.filename(title))
  File.open(file_path, "w") { |f| f.write export_content }
  if (Config.image_export?)
    @images.each { |image| image.save(save_dir) }
  end
end