Module: Workarea::Tasks::Help

Extended by:
Help
Included in:
Help
Defined in:
lib/workarea/tasks/help.rb

Instance Method Summary collapse

Instance Method Details

#dumpObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/workarea/tasks/help.rb', line 12

def dump
  Workarea::Help::Article.all.each_by(50) do |article|
    article_root = Rails.root.join(
      'data',
      'help',
      article.category.systemize,
      article.name.systemize
    )

    asset_path = article_root.join('assets')

    FileUtils.mkdir_p(article_root)

    if article.thumbnail.present?
      article.thumbnail.to_file(article_root.join(article.thumbnail.name))
    end

    Workarea::Help::Asset.all.each_by(50) do |asset|
      if article.summary.include?(asset.url) || article.body.include?(asset.url)
        FileUtils.mkdir_p(asset_path)
        asset.to_file(asset_path.join(asset.name))
        reference = "<%= #{asset.name.split('.').first} %>"

        article.summary.gsub!(asset.url, reference)
        article.body.gsub!(asset.url, reference)
      end
    end

    if article.summary.present?
      File.open(article_root.join('summary.md'), 'w') do |file|
        file.write(article.summary)
      end
    end

    if article.body.present?
      File.open(article_root.join('body.md'), 'w') do |file|
        file.write(article.body)
      end
    end
  end
end

#reloadObject



6
7
8
9
10
# File 'lib/workarea/tasks/help.rb', line 6

def reload
  Workarea::Help::Article.delete_all
  Workarea::Help::Asset.delete_all
  Workarea::HelpSeeds.new.perform
end