Class: Dothtml::DotTask

Inherits:
Object
  • Object
show all
Defined in:
lib/dothtml/dot_task.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize {|_self| ... } ⇒ DotTask

Returns a new instance of DotTask.

Yields:

  • (_self)

Yield Parameters:



11
12
13
14
15
16
17
# 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

Instance Attribute Details

#behaviorObject

Returns the value of attribute behavior.



7
8
9
# File 'lib/dothtml/dot_task.rb', line 7

def behavior
  @behavior
end

#cdnObject

Returns the value of attribute cdn.



8
9
10
# File 'lib/dothtml/dot_task.rb', line 8

def cdn
  @cdn
end

#d3jsObject

Returns the value of attribute d3js.



9
10
11
# File 'lib/dothtml/dot_task.rb', line 9

def d3js
  @d3js
end

#styleObject

Returns the value of attribute style.



6
7
8
# File 'lib/dothtml/dot_task.rb', line 6

def style
  @style
end

#templateObject

Returns the value of attribute template.



5
6
7
# File 'lib/dothtml/dot_task.rb', line 5

def template
  @template
end

Instance Method Details

#build(*files) ⇒ Object



28
29
30
31
32
33
# 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

#create(dir) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# 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