Class: HtmlMockup::Generators::NewGenerator

Inherits:
Thor::Group
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/html_mockup/generators/new.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#source_pathsObject (readonly)

Returns the value of attribute source_paths.



11
12
13
# File 'lib/html_mockup/generators/new.rb', line 11

def source_paths
  @source_paths
end

Instance Method Details

#create_mockupObject



61
62
63
# File 'lib/html_mockup/generators/new.rb', line 61

def create_mockup
  directory(".", ".")
end

#setup_variablesObject



13
14
15
16
17
18
19
20
# File 'lib/html_mockup/generators/new.rb', line 13

def setup_variables    
  self.destination_root = path
  
  @source_paths = []
  
  # Stuff to rm -rf later
  @cleanup = []
end

#validate_path_is_emptyObject



22
23
24
25
26
27
# File 'lib/html_mockup/generators/new.rb', line 22

def validate_path_is_empty
  if File.directory?(self.destination_root)
    say "Directory #{self.destination_root} already exists, please only use this to create new mockups"
    exit(1)
  end
end

#validate_template_pathObject



29
30
31
32
33
34
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
# File 'lib/html_mockup/generators/new.rb', line 29

def validate_template_path
  if options[:template]
    template = options[:template]
  else
    template = File.dirname(__FILE__) + "/../../../examples/default_template"
  end
  
  if File.exist?(template)
    say "Taking template from #{template}"
    @source_paths << template
  else
    # Hack to create temp directory
    t = Tempfile.new("htmlmockup-generate-new")
    tmp_dir = Pathname.new(t.path)
    t.close
    t.unlink
    
    if run("git clone --depth=1 #{Shellwords.escape(template)} #{tmp_dir}")
      say "Cloned template from #{template}"
      run("rm -rf #{tmp_dir + ".git"}")
      @source_paths << tmp_dir.to_s
      @cleanup << tmp_dir.to_s
    else
      say "Template path #{template} doesn't seem to be a git remote or a local path"
      exit(1)
    end
  end
rescue Exception => e
  puts e
  puts e.backtrace.join("\n")
end