Permalink
Browse files

liquid template support for themes

  • Loading branch information...
timriley committed Dec 9, 2008
1 parent 2c177ac commit c4bb1d7617aee9f2f5d9ff9625212c517a28101f
View
@@ -6,3 +6,4 @@ doc/app
coverage
config/database.yml
config/config.yml
+config/template.html~
View
8 TODO
@@ -0,0 +1,8 @@
+- wrap all calls to flickr in begin and rescue blocks (logger.error in rescue)
+
+- liquid layout-fu:
+
+- need to fix up the syncing. ie. when changing tags, must remove/disable any photos that exist
+ from a sync using the previous tag.
+
+- need to verify that sync order is still correct (it looks like it is oldest first after a recent test)
@@ -1,11 +1,12 @@
class PhotosController < ApplicationController
+ layout 'theme'
+
def show
- # Find the photo from id, or get the most recent one.
+ # Find the photo from id or get the most recent one.
@photo = params[:id] ? Photo.find(params[:id]) : Photo.find(:first, :order => 'created_at DESC')
respond_to do |format|
format.html
- format.xml { render :xml => @photo }
end
end
end
View
@@ -10,6 +10,15 @@ class Photo < ActiveRecord::Base
validates_presence_of :fullsize_source_url, :message => "can't be blank"
validates_presence_of :title, :message => "can't be blank"
+ liquid_methods :id,
+ :title,
+ :square_source_url,
+ :thumb_source_url,
+ :medium_source_url,
+ :fullsize_source_url,
+ :previous,
+ :next
+
def update_from_flickr
self.attributes = self.attributes.merge(FlickrPhoto.new(self.flickr_id).attributes)
end
@@ -21,7 +30,7 @@ def previous
def next
@next_photo ||= Photo.find(:first, :order => 'created_at ASC', :conditions => ['created_at > ?', created_at])
end
-
+
def self.new_from_flickr(flickr_photo)
Photo.new do |photo|
photo.flickr_id = flickr_photo.id
View
@@ -2,7 +2,7 @@ class Theme
include Singleton
include Validatable
- THEME_FILE = "#{Rails.root}/config/template.txt"
+ THEME_FILE = File.join(Rails.root, 'config', 'template.html')
attr_accessor :template
@@ -14,7 +14,7 @@ def initialize
def save
backup_file
- File.open(THEME_FILE) do |file|
+ File.open(THEME_FILE, 'w+') do |file|
file.write(@template)
file.flush
end
@@ -1,15 +0,0 @@
-!!! Strict
-%html
- %head
- %meta{'http-equiv' => 'Content-Type', :content => 'text/html; charset=utf-8'}
- %title= "Photoblogr - #{@title}"
- / = stylesheet_link_tag 'application', :media => 'all'
- = yield :stylesheet_includes
- = javascript_include_tag 'jquery', :cache => false
- = yield :javascript_library_includes
- = javascript_include_tag 'application', :cache => false
- = yield :javascript_includes
- = yield :rss_includes
-
- %body
- = yield
@@ -0,0 +1 @@
+= Liquid::Template.parse(Theme.instance.template).render('photo' => @photo)
View
@@ -31,8 +31,8 @@
config.gem 'bj'
config.gem 'validatable'
config.gem 'flickraw'
- config.gem 'will_paginate'
config.gem 'liquid'
+ config.gem 'mislav-will_paginate', :version => '~> 2.2.3', :lib => 'will_paginate', :source => 'http://gems.github.com'
# Only load the plugins named here, in the order given. By default, all plugins
# in vendor/plugins are loaded in alphabetical order.
View
@@ -0,0 +1,17 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
+<html>
+ <head>
+ <meta content='text/html; charset=utf-8' http-equiv='Content-Type'>
+ <title>Flickr Portfolio</title>
+ </head>
+ <body>
+ <h1>{{ photo.title }}</h1>
+ <img src='{{ photo.medium_source_url }}' alt='{{ photo.title }}'/>
+ {% if photo.previous %}
+ <a href='/photos/{{ photo.previous.id }}'>previous</a>
+ {% endif %}
+ {% if photo.next %}
+ <p>there is a next photo</p>
+ {% endif %}
+ </body>
+</html>
View
@@ -1,2 +0,0 @@
-Photoblogr:
-- wrap all calls to flickr in begin and rescue blocks (logger.error in rescue)
@@ -4,4 +4,5 @@
require 'haml' # From gem
end
+# Load Haml and Sass
Haml.init_rails(binding)

0 comments on commit c4bb1d7

Please sign in to comment.