Sha256: dc9a15fb5f78825eab3d3bee0a4672b02a1fa80db5482c51b6449211a149e30b
Contents?: true
Size: 1.98 KB
Versions: 4
Compression:
Stored size: 1.98 KB
Contents
# encoding: utf-8 # this class represents a project and handles generators and ressources class EasyHtmlGenerator::Project attr_reader :src_path, :dist_path, :name, :generators, :config def initialize(name, src_path, dist_path, config_file) @name = name @src_path = src_path @dist_path = dist_path @config_file = config_file load_config config_file load_generators end def src_path_to(type, relative_path = '') File.join(@src_path, @config.paths.src[type.to_sym], relative_path) end def dist_path_to(type, relative_path = '') File.join(@dist_path, @config.paths.dist[type.to_sym], relative_path) end def uri_path_to(type, relative_path = '') File.join('/', @name, @config.paths.dist[type.to_sym], relative_path) end def generate STDERR.puts '' STDERR.puts ' -----------------------------'.green STDERR.puts " | compiling project #{@name}".green STDERR.puts ' -----------------------------'.green reaload_if_config_changed @generators.generate end def list_dir(_relative_path = '/') dir_pattern = File.join(src_path_to(:views), '*.html*') dirs = Dir[dir_pattern].map { |file| file.sub('.html.haml', '.html') } dirs.map { |file| file.sub(src_path_to(:views), "#{name}/") } end def should_generate_for?(path) return true unless path @config.generate_on_request_path_match.each do |pattern| return true if pattern.match path end false end private def load_config(file) @config = EasyHtmlGenerator::Config.from_file file @config[:generate_on_request_path_match].map! { |p| Regexp.new(p) } EasyHtmlGenerator::Checksum.store_file file end def load_generators @generators = EasyHtmlGenerator::Generators.new self end def reaload_if_config_changed return unless EasyHtmlGenerator::Checksum.file_changed? @config_file STDERR.puts " | -> reloading config(#{@config_file.green})" load_config @config_file load_generators end end
Version data entries
4 entries across 4 versions & 1 rubygems