Sha256: 5a3dff7f737e4d7ca247b7e4eda28d58538170ad4e92e5da404559b79ac92151
Contents?: true
Size: 1.72 KB
Versions: 3
Compression:
Stored size: 1.72 KB
Contents
module Golf class Compiler def initialize(golfpath = ".") puts "starting up in #{golfpath}" @golfpath = "#{golfpath}/golfapp" end def generate_componentsjs "jQuery.golf.components=#{component_json};jQuery.golf.res=#{res_json};jQuery.golf.plugins=#{plugin_json};jQuery.golf.scripts=#{script_json};jQuery.golf.styles=#{style_json};jQuery.golf.setupComponents();" end def component_json traverse("#{@golfpath}/components", "html") end def res_json results = { "Gemfile" => "Gemfile", "plugins" => {},"config.ru" => "config.ru", "404.txt" => "404.txt" } Dir["#{@golfpath}/plugins/*.js"].each do |path| results["plugins"] = results["plugins"].merge({ File.basename(path) => "plugins/#{File.basename(path)}"}) end JSON.dump(results) end def plugin_json traverse("#{@golfpath}/plugins", "js") end def script_json traverse("#{@golfpath}/scripts", "js") end def style_json traverse("#{@golfpath}/styles", "css") end def traverse(dir, type) results = {} if File.exists?(dir) and File.directory?(dir) Dir["#{dir}/**/*.#{type}"].each do |path| if type == "html" name = package_name(path) else name = path.split('/').last.gsub(".#{type}",'') end data = File.read(path) results = results.merge({ name => { "name" => name, "#{type}" => data }}) end end JSON.dump(results) end def package_name(path) if path.include?('golfapp/components') path.match(/golfapp\/components\/(.*)/) component_path = $1 component_path.split('/')[0...-1].join('.') end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
golf-0.2.5 | lib/golf/compiler.rb |
golf-0.2.4 | lib/golf/compiler.rb |
golf-0.2.3 | lib/golf/compiler.rb |