Commit 0ec88e79 authored by Wandenberg's avatar Wandenberg

add task to watch for changes on textile files and automatically generate the preview

parent 24ec447d
......@@ -23,4 +23,5 @@ group :docs do
gem 'github-markup', '~> 0.7.5', :require => 'github/markup'
gem 'RedCloth', '~> 4.2.9'
gem 'nokogiri', '~> 1.5.6'
gem 'filewatcher'
end
......@@ -25,6 +25,8 @@ GEM
eventmachine (1.0.3)
execjs (2.0.2)
ffi (1.9.6)
filewatcher (0.3.4)
trollop (~> 2.0)
github-markup (0.7.5)
http_parser.rb (0.6.0)
jasmine (1.3.2)
......@@ -76,6 +78,7 @@ GEM
daemons (>= 1.0.9)
eventmachine (>= 0.12.6)
rack (>= 1.0.0)
trollop (2.0)
websocket (1.0.7)
PLATFORMS
......@@ -85,6 +88,7 @@ DEPENDENCIES
RedCloth (~> 4.2.9)
byebug (~> 1.3.1)
em-http-request (~> 1.0.3)
filewatcher
github-markup (~> 0.7.5)
jasmine (~> 1.3.1)
jshintrb (~> 0.2.1)
......
project_dir = File.expand_path('..', File.dirname(__FILE__))
javascript_dir = File.expand_path(Dir["#{project_dir}/**/js"].first)
require 'rubygems'
require 'erb'
# Set up gems listed in the Gemfile.
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('./Gemfile', File.dirname(__FILE__))
require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
Bundler.require(:default, :test) if defined?(Bundler)
project_dir = File.expand_path('..', File.dirname(__FILE__))
base_path = File.expand_path('pushstream/docs/preview', Dir.tmpdir)
javascript_dir = File.expand_path(Dir["#{project_dir}/**/js"].first)
begin
require "rspec/core/rake_task"
......@@ -88,28 +90,40 @@ begin
Bundler.require(:default, :docs) if defined?(Bundler)
task :get_static_files do
base_path = File.expand_path('pushstream/docs/preview', Dir.tmpdir)
FileUtils.mkdir_p("#{base_path}/css")
download_file("https://github.global.ssl.fastly.net/assets/github-f226abc7983f8566b17d24236adae64ba647ffea.css", "#{base_path}/css/github.css") unless File.exists?("#{base_path}/css/github.css")
download_file("https://github.global.ssl.fastly.net/assets/github2-6edea06c20f02c9c2ae32842c7455d50c08c3f69.css", "#{base_path}/css/github2.css") unless File.exists?("#{base_path}/css/github2.css")
end
desc "Generates docs files to preview."
task :generate => :get_static_files do
require 'erb'
def generate_preview_for(file, project_dir, base_path)
template = ERB.new File.read("#{project_dir}/misc/github_template.html.erb")
base_path = File.expand_path('pushstream/docs/preview', Dir.tmpdir)
filename = File.basename(file)
content = GitHub::Markup.render(file, File.read(file))
rendered = template.result(binding)
output = File.expand_path(file.gsub(project_dir, "./"), base_path)
output_dir = File.dirname(output)
FileUtils.mkdir_p(output_dir)
File.open(output, 'w') {|f| f.write(rendered) }
puts "Preview rendered to #{output}"
end
desc "Generates docs files to preview."
task :generate => :get_static_files do
Dir.glob("#{project_dir}/**/*.textile").each do |file|
filename = File.basename(file)
content = GitHub::Markup.render(file, File.read(file))
rendered = template.result(binding)
output = file.gsub(project_dir, File.expand_path('pushstream/docs/preview', Dir.tmpdir))
output_dir = File.dirname(output)
FileUtils.mkdir_p(output_dir)
File.open(output, 'w') {|f| f.write(rendered) }
puts "Preview rendered to #{output}"
generate_preview_for(file, project_dir, base_path)
end
end
desc "Watch for changes on doc to generate the preview."
task :watch do
puts "watching for changes on textile files"
Dir.chdir(project_dir) do
FileWatcher.new(["*.textile"]).watch do |file, event|
if(event != :delete)
generate_preview_for(file, project_dir, base_path)
end
end
end
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment