class Fones::Generator
Public Class Methods
new(project, layout='default')
click to toggle source
# File lib/fones/generator.rb, line 11 def initialize(project, layout='default') @project = project @task = project.task @layout = layout end
run(project, layout='default')
click to toggle source
# File lib/fones/generator.rb, line 5 def run(project, layout='default') generator = self.new(project, layout) generator.run end
Public Instance Methods
copy_functions()
click to toggle source
# File lib/fones/generator.rb, line 75 def copy_functions source = File.expand_path(File.join(self.layout_path, 'functions')) target = File.expand_path(File.join(@project.source_path, 'functions')) render_directory(source, target) end
copy_images()
click to toggle source
# File lib/fones/generator.rb, line 41 def copy_images source = File.expand_path(File.join(self.layout_path, 'img')) target = File.expand_path(File.join(@project.assets_path, 'img')) render_directory(source, target) end
copy_javascript()
click to toggle source
# File lib/fones/generator.rb, line 57 def copy_javascript source = File.expand_path(File.join(self.layout_path, 'js')) target = File.expand_path(File.join(@project.assets_path, 'js')) render_directory(source, target) self end
copy_stylesheets()
click to toggle source
# File lib/fones/generator.rb, line 48 def copy_stylesheets source = File.expand_path(File.join(self.layout_path, 'css')) target = File.expand_path(File.join(@project.assets_path, 'css')) render_directory(source, target) self end
copy_templates()
click to toggle source
# File lib/fones/generator.rb, line 66 def copy_templates source = File.expand_path(File.join(self.layout_path, 'templates')) target = File.expand_path(File.join(@project.source_path, 'templates')) render_directory(source, target) self end
create_structure()
click to toggle source
# 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()
click to toggle source
# File lib/fones/generator.rb, line 82 def layout_path @layout_path ||= File.join(Fones::ROOT, 'layouts', @layout) end
run()
click to toggle source
# 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()
click to toggle source
# 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)
click to toggle source
# File lib/fones/generator.rb, line 111 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 @project.parse_erb(template) end end
Protected Instance Methods
render_directory(source, target)
click to toggle source
# File lib/fones/generator.rb, line 122 def render_directory(source, target) Dir.glob("#{source}/**/*") do |file| unless File.directory?(file) source_file = file.gsub(source, '') target_file = File.join(target, source_file) if source_file.end_with? ".erb" target_file = target_file.slice(0..-5) content = @project.parse_erb(file) else content = File.open(file).read end @task.create_file target_file do content end end end end