Class: Fones::Generator
- Inherits:
-
Object
- Object
- Fones::Generator
- Defined in:
- lib/fones/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/fones/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/fones/generator.rb', line 5 def run(project, layout='default') generator = self.new(project, layout) generator.run end |
Instance Method Details
#copy_functions ⇒ Object
75 76 77 78 79 80 |
# File 'lib/fones/generator.rb', line 75 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
41 42 43 44 45 46 |
# File 'lib/fones/generator.rb', line 41 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
57 58 59 60 61 62 63 64 |
# File 'lib/fones/generator.rb', line 57 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
48 49 50 51 52 53 54 55 |
# File 'lib/fones/generator.rb', line 48 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
66 67 68 69 70 71 72 73 |
# File 'lib/fones/generator.rb', line 66 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 |
# File 'lib/fones/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'], ] # 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
82 83 84 |
# File 'lib/fones/generator.rb', line 82 def layout_path @layout_path ||= File.join(Fones::ROOT, 'layouts', @layout) end |
#run ⇒ Object
86 87 88 89 90 91 92 93 94 95 |
# File 'lib/fones/generator.rb', line 86 def run write_config create_structure copy_images copy_stylesheets copy_javascript copy_templates copy_functions return self end |
#write_config ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/fones/generator.rb', line 97 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
111 112 113 114 115 116 117 118 119 |
# File 'lib/fones/generator.rb', line 111 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 |