Class: EasyHtmlGenerator::Project

Inherits:
Object
  • Object
show all
Defined in:
lib/easy_html_generator/project.rb

Overview

this class represents a project and handles generators and ressources

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, src_path, dist_path, config_file) ⇒ Project

Returns a new instance of Project.



7
8
9
10
11
12
13
14
15
# File 'lib/easy_html_generator/project.rb', line 7

def initialize(name, src_path, dist_path, config_file)
  @name           = name
  @src_path       = src_path
  @dist_path      = dist_path

  @config_file    = config_file
  load_config config_file
  load_generators
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



5
6
7
# File 'lib/easy_html_generator/project.rb', line 5

def config
  @config
end

#dist_pathObject (readonly)

Returns the value of attribute dist_path.



5
6
7
# File 'lib/easy_html_generator/project.rb', line 5

def dist_path
  @dist_path
end

#generatorsObject (readonly)

Returns the value of attribute generators.



5
6
7
# File 'lib/easy_html_generator/project.rb', line 5

def generators
  @generators
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/easy_html_generator/project.rb', line 5

def name
  @name
end

#src_pathObject (readonly)

Returns the value of attribute src_path.



5
6
7
# File 'lib/easy_html_generator/project.rb', line 5

def src_path
  @src_path
end

Instance Method Details

#clean_dist_pathObject



25
26
27
28
# File 'lib/easy_html_generator/project.rb', line 25

def clean_dist_path
  FileUtils.rm_rf Dir["#{@dist_path}/**/*"]
  EasyHtmlGenerator::Checksum.invalidate_all
end

#dist_path_to(type, relative_path = '') ⇒ Object



21
22
23
# File 'lib/easy_html_generator/project.rb', line 21

def dist_path_to(type, relative_path = '')
  File.join(@dist_path, @config.paths.dist[type.to_sym], relative_path)
end

#generateObject



36
37
38
39
40
41
42
43
44
45
# File 'lib/easy_html_generator/project.rb', line 36

def generate
  STDERR.puts ''
  STDERR.puts ' -----------------------------'.green
  STDERR.puts " | compiling project #{@name}".green
  STDERR.puts ' -----------------------------'.green

  reaload_if_config_changed

  @generators.generate
end

#list_dir(_relative_path = '/') ⇒ Object



47
48
49
50
51
52
53
# File 'lib/easy_html_generator/project.rb', line 47

def list_dir(_relative_path = '/')
  dir_pattern = File.join(src_path_to(:views), '*.html*')

  dirs = Dir[dir_pattern].map { |file| file.sub('.html.haml', '.html') }

  dirs.map { |file| file.sub(src_path_to(:views), "#{name}/") }
end

#should_generate_for?(path) ⇒ Boolean

Returns:

  • (Boolean)


55
56
57
58
59
60
61
62
63
# File 'lib/easy_html_generator/project.rb', line 55

def should_generate_for?(path)
  return true unless path

  @config.generate_on_request_path_match.each do |pattern|
    return true if pattern.match path
  end

  false
end

#src_path_to(type, relative_path = '') ⇒ Object



17
18
19
# File 'lib/easy_html_generator/project.rb', line 17

def src_path_to(type, relative_path = '')
  File.join(@src_path, @config.paths.src[type.to_sym], relative_path)
end

#uri_path_to(type, relative_path = '') ⇒ Object



30
31
32
33
34
# File 'lib/easy_html_generator/project.rb', line 30

def uri_path_to(type, relative_path = '')
  uri_path   = File.join(@config.paths.dist[type.to_sym], relative_path)
  local_path = File.join(@dist_path, uri_path)
  File.exist?(local_path) ? uri_path : relative_path
end