Class: ProcessIt::Builder
- Inherits:
-
Object
- Object
- ProcessIt::Builder
- Defined in:
- lib/processit/builder.rb
Instance Method Summary collapse
- #build ⇒ Object
- #cms ⇒ Object
- #copy_file(from, to) ⇒ Object
- #evaluate(path, options = {}) ⇒ Object
- #generate_site_file(relative_name, extension, content) ⇒ Object
-
#initialize(root = ".") ⇒ Builder
constructor
A new instance of Builder.
- #save_page(path, content) ⇒ Object
-
#source_template_from_path(path) ⇒ Object
Returns a raw template name from a source file path: source_template_from_path(“/path/to/site/src/stylesheets/application.sass”) -> “application”.
- #watch ⇒ Object
Constructor Details
#initialize(root = ".") ⇒ Builder
Returns a new instance of Builder.
8 9 10 11 12 13 14 15 |
# File 'lib/processit/builder.rb', line 8 def initialize(root = ".") @base_dir = Dir.pwd @src_dir = File.join(@base_dir, "src") @site_dir = File.join(@base_dir, "site") @html_src_dir = File.join(@src_dir, "pages") @config = YAML.load_file("#{@src_dir}/data/data.yml") end |
Instance Method Details
#build ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'lib/processit/builder.rb', line 40 def build puts ">>> ProcessIt is building your site." Dir["#{@src_dir}/**/*"].each do |path| next if File.basename(path) =~ /^\_/ or File.directory?(path) # skip partials and directories save_page(path, evaluate(path)) end end |
#cms ⇒ Object
66 67 68 |
# File 'lib/processit/builder.rb', line 66 def cms() end |
#copy_file(from, to) ⇒ Object
70 71 72 |
# File 'lib/processit/builder.rb', line 70 def copy_file(from, to) FileUtils.cp(from, to) end |
#evaluate(path, options = {}) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/processit/builder.rb', line 49 def evaluate(path, = {}) ext = File.extname(path) path = File.absolute_path(path, @src_dir) result = ProcessIt::Utils.read_unicode(path) Processors.instance.processor(ext)["klasses"].each do |processor| begin template = processor.new(path) { result } result = template.render(self, @config) rescue Exception => e puts e raise end end result end |
#generate_site_file(relative_name, extension, content) ⇒ Object
85 86 87 88 89 90 91 92 93 94 |
# File 'lib/processit/builder.rb', line 85 def generate_site_file(relative_name, extension, content) path = File.join(@site_dir, "#{relative_name}.#{extension}") FileUtils.mkdir_p(File.dirname(path)) File.open(path, 'w+') do |f| f << content end puts "created #{path}" end |
#save_page(path, content) ⇒ Object
74 75 76 77 78 79 80 81 82 83 |
# File 'lib/processit/builder.rb', line 74 def save_page(path, content) ext = File.extname(path) file_dir, file_name = File.split(path) relative_name = path.sub(/^#{@src_dir}/, '') relative_name.chomp!(ext) output_ext = Processors.instance.processor(ext)["output_ext"] if (output_ext) generate_site_file(relative_name, output_ext, content) end end |
#source_template_from_path(path) ⇒ Object
Returns a raw template name from a source file path: source_template_from_path(“/path/to/site/src/stylesheets/application.sass”) -> “application”
98 99 100 101 102 |
# File 'lib/processit/builder.rb', line 98 def source_template_from_path(path) file_dir, file_name = File.split(path) file_name.chomp!(File.extname(file_name)) [ file_dir, file_name, File.extname(path) ] end |
#watch ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/processit/builder.rb', line 17 def watch puts ">>> ProcessMe is watching for changes. Press Ctrl-C to Stop." require 'fssm' begin FSSM.monitor do |monitor| monitor.path @src_dir do |path| path.create do |base, relative| build end path.update do |base, relative| build end path.delete do |base, relative| build end end end end end |