Class: WpFire::Generator

Inherits:
Object
  • Object
show all
Defined in:
lib/wp_fire/generator.rb

Instance Method Summary collapse

Constructor Details

#initialize(project_name, task, configuration) ⇒ Generator

Returns a new instance of Generator.



4
5
6
7
8
9
10
11
12
# File 'lib/wp_fire/generator.rb', line 4

def initialize(project_name, task, configuration)
  @project_name = project_name
  @task    = task
  @configuration  = configuration

  @source_path = File.join(project_name,"source")
  @config_file = File.join(project_name,"config.rb")
  @assets_path = File.join(project_name,"source","assets")
end

Instance Method Details

#copy_functionsObject



71
72
73
74
75
76
# File 'lib/wp_fire/generator.rb', line 71

def copy_functions
  source = File.expand_path(File.join(self.layout_path, 'functions', 'functions.php.erb'))
  target = File.expand_path(File.join(@source_path, 'functions', 'functions.php'))

  write_template(source, target)
end

#copy_javascriptObject



40
41
42
43
44
45
46
47
# File 'lib/wp_fire/generator.rb', line 40

def copy_javascript
  source = File.expand_path(File.join(self.layout_path, 'javascripts'))
  target = File.expand_path(File.join(@assets_path, 'javascripts'))

  render_directory(source, target)

  self
end

#copy_stylesheetsObject



49
50
51
52
53
54
55
56
# File 'lib/wp_fire/generator.rb', line 49

def copy_stylesheets
  source = File.expand_path(File.join(self.layout_path, 'stylesheets'))
  target = File.expand_path(File.join(@assets_path, 'stylesheets'))

  render_directory(source, target)

  self
end

#copy_templatesObject



58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/wp_fire/generator.rb', line 58

def copy_templates
  if @configuration[:template].nil? or !File.directory?(File.join(@configuration[:template_path],@configuration[:template],"children_files"))
    source = File.expand_path(File.join(self.layout_path, 'templates'))
  else
    source = File.expand_path(File.join(@configuration[:template_path],@configuration[:template],"children_files"))
  end
  target = File.expand_path(File.join(@source_path, 'templates'))

  render_directory(source, target)

  self
end

#create_structureObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/wp_fire/generator.rb', line 14

def create_structure
  source_paths = [
    ['assets', 'fonts'],
    ['assets', 'images'],
    ['assets', 'javascripts'],
    ['assets', 'stylesheets'],
    ['functions'],
    ['templates']
  ]

  source_paths.each do |path|
    @task.empty_directory File.join(@source_path, path)
  end

  self
end

#layout_pathObject



31
32
33
# File 'lib/wp_fire/generator.rb', line 31

def layout_path
  @layout_path ||= File.join(WpFire::ROOT, 'generators', 'wp_fire')
end

#theme_idObject



88
89
90
# File 'lib/wp_fire/generator.rb', line 88

def theme_id
  @project_name
end

#write_configObject



35
36
37
38
# File 'lib/wp_fire/generator.rb', line 35

def write_config
  write_template(['generators', 'wp_fire', 'config', 'config.tt'], @config_file)
  self
end

#write_template(source, target) ⇒ Object



78
79
80
81
82
83
84
85
86
# File 'lib/wp_fire/generator.rb', line 78

def write_template(source, target)
  source   = File.join(source)
  template = File.expand_path(@task.find_in_source_paths((source)))
  target   = File.expand_path(File.join(target))

  @task.create_file target do
    parse_erb(template)
  end
end