Class: Fones::Generator
- Inherits:
-
Object
- Object
- Fones::Generator
- Defined in:
- lib/forge/generator.rb
Class Method Summary collapse
Instance Method Summary collapse
- #copy_functions ⇒ Object
- #copy_images ⇒ Object
- #copy_javascript ⇒ Object
- #copy_stylesheets ⇒ Object
- #copy_templates ⇒ Object
- #create_structure ⇒ Object
-
#initialize(project, layout = 'default') ⇒ Generator
constructor
A new instance of Generator.
- #layout_path ⇒ Object
- #run ⇒ Object
- #write_config ⇒ Object
- #write_template(source, target) ⇒ Object
Constructor Details
#initialize(project, layout = 'default') ⇒ Generator
Returns a new instance of Generator.
11 12 13 14 15 |
# File 'lib/forge/generator.rb', line 11 def initialize(project, layout='default') @project = project @task = project.task @layout = layout end |
Class Method Details
.run(project, layout = 'default') ⇒ Object
5 6 7 8 |
# File 'lib/forge/generator.rb', line 5 def run(project, layout='default') generator = self.new(project, layout) generator.run end |
Instance Method Details
#copy_functions ⇒ Object
76 77 78 79 80 81 |
# File 'lib/forge/generator.rb', line 76 def copy_functions source = File.(File.join(self.layout_path, 'functions')) target = File.(File.join(@project.source_path, 'functions')) render_directory(source, target) end |
#copy_images ⇒ Object
42 43 44 45 46 47 |
# File 'lib/forge/generator.rb', line 42 def copy_images source = File.(File.join(self.layout_path, 'img')) target = File.(File.join(@project.assets_path, 'img')) render_directory(source, target) end |
#copy_javascript ⇒ Object
58 59 60 61 62 63 64 65 |
# File 'lib/forge/generator.rb', line 58 def copy_javascript source = File.(File.join(self.layout_path, 'js')) target = File.(File.join(@project.assets_path, 'js')) render_directory(source, target) self end |
#copy_stylesheets ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'lib/forge/generator.rb', line 49 def copy_stylesheets source = File.(File.join(self.layout_path, 'css')) target = File.(File.join(@project.assets_path, 'css')) render_directory(source, target) self end |
#copy_templates ⇒ Object
67 68 69 70 71 72 73 74 |
# File 'lib/forge/generator.rb', line 67 def copy_templates source = File.(File.join(self.layout_path, 'templates')) target = File.(File.join(@project.source_path, 'templates')) render_directory(source, target) self end |
#create_structure ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/forge/generator.rb', line 17 def create_structure # Create the build directory for Fones output @task.empty_directory @project.build_path source_paths = [ ['assets', 'img'], ['assets', 'js', 'libs'], ['assets', 'css'], ['functions', 'library', 'translation'], ['includes'], ['templates', 'pages'], ['templates', 'partials'], ] # Build out Fones structure in the source directory source_paths.each do |path| @task.empty_directory File.join(@project.source_path, path) end self end |
#layout_path ⇒ Object
83 84 85 |
# File 'lib/forge/generator.rb', line 83 def layout_path @layout_path ||= File.join(Fones::ROOT, 'layouts', @layout) end |
#run ⇒ Object
87 88 89 90 91 92 93 94 95 96 |
# File 'lib/forge/generator.rb', line 87 def run write_config create_structure copy_images copy_stylesheets copy_javascript copy_templates copy_functions return self end |
#write_config ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/forge/generator.rb', line 98 def write_config unless File.exists?(@project.global_config_file) @task.shell.mute do @task.create_file(@project.global_config_file) do "# Place your global configuration values here\n# config[:livereload] = true" end end end write_template(['config', 'config.tt'], @project.config_file) self end |
#write_template(source, target) ⇒ Object
112 113 114 115 116 117 118 119 120 |
# File 'lib/forge/generator.rb', line 112 def write_template(source, target) source = File.join(source) template = File.(@task.find_in_source_paths((source))) target = File.(File.join(target)) @task.create_file target do @project.parse_erb(template) end end |