Created
August 16, 2011 16:23
-
-
Save rfunduk/1149469 to your computer and use it in GitHub Desktop.
Code snippets for http://ryanfunduk.com/simple-partials
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <div id="footer"> | |
| This site is Copyright © 2008 - blah, blah, blah | |
| </div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <div id="footer"><%= partial 'footer' %></div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'erb' | |
| def write_output( filename, result ) | |
| filename = filename.split( '/' ).last | |
| File.open( filename, 'wb' ).write( result ) | |
| puts "WROTE : #{filename}" | |
| end | |
| def partial( name ) | |
| filename = "sources/#{name}.partial" | |
| if File.exists? filename | |
| puts "LOADED : #{name}.partial" | |
| File.open( filename, 'rb' ).read.chomp | |
| else | |
| puts "ERROR : #{filename}" | |
| end | |
| end | |
| task :build do | |
| sources = FileList["sources/*.*"].exclude( "sources/*.partial" ) | |
| sources.each do |f| | |
| puts "\nCOMPILING : #{f}" | |
| page = ERB.new( File.open( f, 'rb' ).read ) | |
| write_output f, page.result | |
| end | |
| end | |
| task :default => [ :build ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| COMPILING : sources/simple-partials.html | |
| LOADED : 1.html.partial | |
| LOADED : 2.html.partial | |
| LOADED : 3.rb.partial | |
| LOADED : 4.txt.partial | |
| WROTE : simple-partials.html |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment