Sha256: 6c93c8cc1f934ead0e86d2710ee631d1c001949de215bccf6633e2a5d5ef75c1
Contents?: true
Size: 1.36 KB
Versions: 2
Compression:
Stored size: 1.36 KB
Contents
require 'rack' class Susanoo::Application # This controller is responsible to serving/building angularjs templates. class Views < Susanoo::Controller def call(env) path = env['PATH_INFO'] if File.exist?(File.join(project_root, "src/views#{path}.erb")) template = Tilt.new(File.join(project_root, "src/views#{path}.erb")) elsif File.exist?(File.join(project_root, "src/views#{path}")) template = Tilt.new(File.join(project_root, "src/views#{path}")) else fail "There is no '#{path}' in 'src/views' directory." end [200, {'Content-Type' => 'text/html'}, [template.render(self)]] end def build(generator, route) file_pattern = File.join(project_root, 'src/views/**/*.{html,html.erb}') dest_path = File.join(project_root, 'www') src_path = File.join(project_root, 'src') Dir.glob(file_pattern) do |file| template = Tilt.new file dest_file = File.join(dest_path, file.gsub(src_path, '')) # Create missing directories in destination path FileUtils.mkpath dest_path # Remove erb extension name from destination path dest_file.gsub!('.erb', '') if File.extname(dest_file) == 'erb' # Create the destination file generator.create_file dest_file, template.render(self) end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
susanoo-0.11.1 | lib/susanoo/controllers/views.rb |
susanoo-0.10.0 | lib/susanoo/controllers/views.rb |