class Dothtml::DotTask
Attributes
behavior[RW]
cdn[RW]
d3js[RW]
style[RW]
template[RW]
Public Class Methods
new() { |self| ... }
click to toggle source
# File lib/dothtml/dot_task.rb, line 11 def initialize @style = File.join(TEMPLATES_DIR, 'style.css') @behavior = File.join(TEMPLATES_DIR, 'behavior.js') @template = File.join(TEMPLATES_DIR, 'index.html.erb') self.cdn = true yield self if block_given? end
Public Instance Methods
build(*files)
click to toggle source
# File lib/dothtml/dot_task.rb, line 28 def build(*files) files.flatten.each do |f| dot_to_svg(f) dot_to_html(f) end end
cdn=(val)
click to toggle source
# File lib/dothtml/dot_task.rb, line 19 def cdn=(val) @cdn = val @d3js = case val when true then "//cdnjs.cloudflare.com/ajax/libs/d3/3.5.6/d3.min.js" when false then "d3.v3.js" else val end end
create(dir)
click to toggle source
# File lib/dothtml/dot_task.rb, line 35 def create(dir) require 'colorize' if Dir.exists?(dir) say_status(:exists, dir) else FileUtils.mkdir_p(dir) say_status(:create, dir) end sample = File.join(dir, "sample.dot") if File.exists?(sample) say_status(:exists, sample) else sample_source = File.join(TEMPLATES_DIR, "sample.dot") FileUtils.cp(sample_source, sample) say_status(:create, sample) end gitignore = File.join(dir, ".gitignore") if File.exists?(gitignore) say_status(:exists, gitignore) else File.write(gitignore, "*.html\n*.svg") say_status(:create, gitignore) end git_dir = File.join(dir, ".git") if Dir.exists?(git_dir) say_status(:exists, git_dir) else system("git init", :chdir => dir) end end
Private Instance Methods
dot_to_html(source)
click to toggle source
# File lib/dothtml/dot_task.rb, line 72 def dot_to_html(source) target = source.sub(/.dot$/, ".html") puts "#{source} -> #{target}" doc = DotHelper.from_dotfile(source)#.embed_images doc.write target, @template, title: doc.extractTitle, body: doc.to_xml, choices: doc.extractChoices, descriptions: doc.descriptions?, style: File.read(style), behavior: File.read(behavior), d3js: d3js end
dot_to_svg(source)
click to toggle source
# File lib/dothtml/dot_task.rb, line 87 def dot_to_svg(source) target = source.sub(/.dot$/, ".svg") puts "#{source} -> #{target}" doc = DotHelper.from_dotfile(source)#.embed_images File.write(target, doc.to_xml) end
say_status(mode, text)
click to toggle source
# File lib/dothtml/dot_task.rb, line 95 def say_status(mode, text) mode_text = case mode when :exists then mode.to_s.yellow.bold when :create then mode.to_s.green.bold else mode.to_s.bold end puts "\t#{mode_text}\t#{text}" end