Class: Guard::ReadmeOnGithub

Inherits:
Guard
  • Object
show all
Defined in:
lib/guard/readme-on-github.rb

Instance Method Summary collapse

Instance Method Details

#asset_dirObject



16
17
18
# File 'lib/guard/readme-on-github.rb', line 16

def asset_dir
  File.join(this_dir, 'readme-on-github', 'assets')
end

#copy_assetsObject



20
21
22
23
24
# File 'lib/guard/readme-on-github.rb', line 20

def copy_assets
  %w[github.css github-logo.png github-logo-hover.png jquery.js github.js].each do |filename|
    FileUtils.cp "#{asset_dir}/#{filename}", "/tmp/#{filename}"
  end
end

#run_allObject



31
32
33
# File 'lib/guard/readme-on-github.rb', line 31

def run_all
  true
end

#run_on_change(paths) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/guard/readme-on-github.rb', line 35

def run_on_change(paths)
  paths.each do |path|
    text = GithubFlavoredMarkdown.gfm(File.read(path))
    html = RDiscount.new(text).to_html
    github = File.read("#{asset_dir}/github.html")
    File.open('/tmp/markdown-preview.html', 'w') do |f|
      f.puts github.sub(/INSERT_BODY/, html)
    end
  end
  puts 'compiled markdown'
  true
end

#startObject



26
27
28
29
# File 'lib/guard/readme-on-github.rb', line 26

def start
  copy_assets
  true
end

#this_dirObject



12
13
14
# File 'lib/guard/readme-on-github.rb', line 12

def this_dir
  File.expand_path('..', __FILE__)
end