Skip to content

Commit

Permalink
haml templates for mars, v0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
joshu committed Apr 9, 2008
1 parent 41bfc6f commit a4c9e7e
Show file tree
Hide file tree
Showing 71 changed files with 2,455 additions and 28 deletions.
19 changes: 19 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
HAML FOR MARS release 0.4

To run the haml example, execute:

rake setup
rake planet

and point your browser to yourdir/index.html

To play with templates once the cache has been built:

rake splice

Setup copies in config and .haml templates for the intertwingly theme.
The various clean tasks remove the extra files. See rake -T


Previously on Planet Mars...

To verify that you have the necessary prereqs installed, execute:

rake prereqs
Expand Down
51 changes: 51 additions & 0 deletions Rakefile.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,60 @@
task :default => [:test]

desc "Run the unit tests"
task :test do
ruby "-rubygems", "test.rb"
end

desc "Test for Mars prerequisites"
task :prereqs do
ruby "-rubygems", "prereqs.rb"
end

desc "Clean up published files"
task :clean do
CLEAN_FILES = FileList['./*.xml', './*.html']
CLEAN_FILES.each do |fn|
rm fn
end
rmdir "images"
end

desc "Clean up all files"
task :clean_all do
CLEAN_ALL_FILES = FileList['./*.xml', './*.html', './*.haml', './*.xslt', './*.ini', './*.css', './*.ico', './*.js', './images/*', "source/*", "http/*", "entry/*"]
CLEAN_ALL_FILES.each do |fn|
rm fn
end
rmdir "images"
rmdir "source"
rmdir "http"
rmdir "entry"
end

desc "Clean up cache files"
task :clean_cache do
CLEAN_CACHE_FILES = FileList[ "source/*", "http/*", "entry/*"]
CLEAN_CACHE_FILES.each do |fn|
rm fn
end
rmdir "source"
rmdir "http"
rmdir "entry"
end

desc "Install config files for haml/intertwingly example"
task :setup do
FileList['./themes/intertwingly/*'].each do |f| cp "#{f}", "." end
mkdir "images"
mv "feed-icon-10x10.png", "images"
end

desc "Run planet for haml example"
task :planet do
ruby "planet.rb", "basic.ini"
end

desc "Splice planet for haml example"
task :splice do
ruby "splice.rb", "basic.ini"
end
9 changes: 9 additions & 0 deletions planet/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ def Planet.config
@@config
end

def Planet.predefine_options(planet_hash)
planet_hash['name'] = "Unconfigured Planet" unless planet_hash['name']
planet_hash['link'] = '' unless planet_hash['link']
planet_hash['date_format'] = "%B %d, %Y %I:%M %p" unless planet_hash['date_format']
planet_hash['new_date_format'] = "%B %d, %Y" unless planet_hash['new_date_format']
end

# Configuration parser compatible with the data format supported by Python:
# http://docs.python.org/lib/module-ConfigParser.html
class PythonConfigParser < DelegateClass(Hash)
Expand Down Expand Up @@ -85,6 +92,8 @@ def read filename

planet = self['Planet']

Planet.predefine_options(planet)

Planet.log_format planet['log_format'] if planet['log_format']
Planet.log_level planet['log_level'] if planet['log_level']
end
Expand Down
39 changes: 39 additions & 0 deletions planet/formatter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
require 'planet/config'

class PlanetFormatter

def process( stylesheet, feed )
raise 'Abstract method called'
end

def plain(value)
#TODO add HTML stripper
return value
end

def string(value)
#TODO deal with encoding issues
return value
end

def planet_date(value)
df = Planet.config['Planet']['date_format']
df = "%B %d, %Y %I:%M %p" unless df
return value ? Time.parse(value).gmtime.strftime(df): nil
end

def new_date(value)
ndf = Planet.config['Planet']['new_date_format']
ndf = "%B %d, %Y %I:%M %p" unless ndf
return value ? Time.parse(value).gmtime.strftime(ndf): nil
end

def rfc822(value)
return value ? Time.parse(value).gmtime.strftime("%a, %d %b %Y %H:%M:%S +0000"): nil
end

def rfc3399(value)
return value ? Time.parse(value).gmtime.strftime("%Y-%m-%dT%H:%M:%S+00:00"): nil
end

end
Loading

0 comments on commit a4c9e7e

Please sign in to comment.