Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add built-in theme.

  • Loading branch information...
commit 419bea8b8bc0f8f40c52fe159c0fa248d926e743 1 parent 24b67f9
@nathanaelkane nathanaelkane authored
View
2  app/controllers/posts_controller.rb
@@ -1,4 +1,6 @@
class PostsController < ApplicationController
+ layout lambda { |controller| Postmarkdown::Config.options[:use_theme] ? 'postmarkdown' : 'application' }
+
def show
resource
end
View
16 app/views/layouts/postmarkdown.html.haml
@@ -0,0 +1,16 @@
+!!! 5
+%html
+ %head
+ %title= Postmarkdown::Util.app_name
+ = stylesheet_link_tag 'postmarkdown/postmarkdown'
+ = yield :head
+ %body
+ %header#header
+ %h1= link_to Postmarkdown::Util.app_name, '/'
+ %p
+ A postmarkdown blog
+ - if Post.last.try(:author)
+ = "by #{Post.last.author}"
+ %section#content= yield
+ %footer
+ %small= "Copyright &copy; #{Date.today.year}".html_safe
View
1  lib/postmarkdown.rb
@@ -3,6 +3,7 @@ module Postmarkdown
require 'postmarkdown/engine'
require 'postmarkdown/config'
require 'postmarkdown/routes'
+ require 'postmarkdown/railtie'
require 'postmarkdown/util'
end
end
View
2  lib/postmarkdown/config.rb
@@ -11,6 +11,8 @@ module Config
Postmarkdown::Config.options[:permalink_format] = :day
+Postmarkdown::Config.options[:use_theme] = false
+
Postmarkdown::Config.options[:permalink_regex] = {}
Postmarkdown::Config.options[:permalink_regex][:day] = %r[\d{4}/\d{2}/\d{2}/[^/]+]
Postmarkdown::Config.options[:permalink_regex][:month] = %r[\d{4}/\d{2}/[^/]+]
View
18 lib/postmarkdown/railtie.rb
@@ -0,0 +1,18 @@
+module Postmarkdown
+ class Railtie < Rails::Railtie
+ initializer :before_initialize do
+ require 'rack'
+ Rails.configuration.middleware.insert_before('Rack::Sendfile', 'Rack::Static',
+ :urls => ['/stylesheets/postmarkdown'],
+ :root => "#{postmarkdown_root}/public"
+ )
+ ActionController::Base.prepend_view_path("#{postmarkdown_root}/app/views")
+ end
+
+ private
+
+ def postmarkdown_root
+ File.expand_path(File.dirname(__FILE__) + '/../..')
+ end
+ end
+end
View
5 lib/postmarkdown/routes.rb
@@ -1,4 +1,6 @@
class ActionDispatch::Routing::Mapper
+ require File.expand_path(File.dirname(__FILE__) + '/util')
+
def postmarkdown(options = {})
options.reverse_merge!({ :as => :posts, :permalink_format => :day })
@@ -17,8 +19,7 @@ def postmarkdown_permalink_regex(options)
end
def postmarkdown_feed_title(path)
- app_name = Rails.application.class.name.split("::")[0..-2].join.titleize
- Postmarkdown::Config.options[:feed_title] ||= "#{app_name} #{path.to_s.tr('/', '_').humanize.titleize}"
+ Postmarkdown::Config.options[:feed_title] ||= "#{Postmarkdown::Util.app_name} #{path.to_s.tr('/', '_').humanize.titleize}"
end
def raise_postmarkdown_permalink_error
View
4 lib/postmarkdown/util.rb
@@ -1,5 +1,9 @@
module Postmarkdown
module Util
+ def self.app_name
+ Rails.application.class.name.split('::')[0..-2].join.titleize
+ end
+
def self.git_config(name)
value = `git config --get #{name}`.chomp
value if $?.success?
View
2  postmarkdown.gemspec
@@ -19,7 +19,7 @@ Gem::Specification.new do |s|
s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
- s.require_paths = ['lib']
+ s.require_paths = ['lib', 'public']
s.add_dependency 'rails', '~> 3.0'
s.add_dependency 'haml', '~> 3.1'
View
67 public/stylesheets/postmarkdown/postmarkdown.css
@@ -0,0 +1,67 @@
+/* -- Reset ----------------------------------------------------------------- */
+body,div,dl,dt,dd,ul,ol,li,h1,h2,h4,h4,h5,h6,pre,code,form,fieldset,legend,input,button,textarea,p,blockquote,th,td{margin:0;padding:0}
+table{border-collapse:collapse;border-spacing:0}
+fieldset,img{border:0}
+address,caption,cite,code,dfn,em,strong,th,var,optgroup{font-style:inherit;font-weight:inherit}
+del,ins{text-decoration:none}
+li{list-style:none}
+caption,th{text-align:left}
+h1,h2,h3,h4,h5,h6{font-size:100%;font-weight:400}
+q:before,q:after{content:''}
+abbr,acronym{border:0;font-variant:normal}
+legend{color:#000}
+input,button,textarea,select,optgroup,option{font-family:inherit;font-size:inherit;font-style:inherit;font-weight:inherit}
+input,button,textarea,select{font-size:100%}
+sup,sub{vertical-align:baseline}
+header, nav, section, article, footer{display:block;}
+
+/* -- Global ---------------------------------------------------------------- */
+html{background:#F3F3F3;text-shadow:0px 1px 0px #fff;}
+body{width:760px;margin:40px auto;font:14px/140% 'Helvetica Neue', Arial, Helvetica, Sans-Serif;}
+a{color:#222;}
+
+h1, h2, h3, h4, h5, h6{font-weight:bold;}
+h1{font-size:26px;margin-bottom:5px;}
+h1 a{text-decoration:none;}
+h2{font-size:24px;padding-top:10px;margin:30px 0 20px;border-top:2px solid #ccc;}
+h3{font-size:20px;margin-bottom:20px;}
+h4{font-size:18px;margin-bottom:10px;}
+h5, h6{font-size:16px;margin-bottom:5px;}
+
+p{margin-bottom:20px;}
+em{font-style:italic;}
+sup{font-size:12px;vertical-align:super;}
+sub{font-size:12px;vertical-align:sub;}
+del{color:#666;font-style:line-through;}
+abbr{border-bottom:1px dotted #bbb;color:#666;text-transform:uppercase;}
+code{background:#eee;padding:2px 5px;font-family:Monospace;}
+small{color:#999;font-size:12px;}
+strong{font-weight:bold;}
+blockquote{color:#666;font-size:16px;margin-left:20px;font-family:Georgia, Serif;}
+
+/* code */
+pre{background:#eee;margin-bottom:20px;padding:10px;border:1px solid #ccc;border-width:1px 0;}
+
+/* lists */
+ol, ul{margin:0 0 20px 20px;}
+ol li{list-style:decimal inside;}
+ul li{list-style:disc inside;}
+
+/* -- Header ---------------------------------------------------------------- */
+header#header {margin-bottom:40px;}
+header#header h1 {font-size:42px;margin-bottom:10px;font-family:Georgia, Serif;font-weight:normal;}
+header#header p {color:#999;}
+
+/* -- Content --------------------------------------------------------------- */
+section#content{}
+
+section#content section article p{margin-bottom:10px;}
+
+section#content article{margin-bottom:40px;}
+section#content article header{overflow:hidden;}
+section#content article header h1{}
+section#content article header img{display:none;}
+section#content article header .meta{color:#999;font-size:12px;}
+
+/* -- Footer ---------------------------------------------------------------- */
+footer{margin-bottom:20px;}
View
6 readme.md
@@ -59,6 +59,12 @@ To customize the feed title, add the following to an initializer:
To link to the feed in your app, simply use the route helper: `<%= link_to 'RSS Feed', posts_feed_path %>`
+## Built-in Theme
+
+Postmarkdown comes with minimal built-in theme for your convenience. To turn on the theme, add the following to an initializer:
+
+ Postmarkdown::Config.options[:use_theme] = true
+
## Customizing Routes
By default Postmarkdown will setup all routes to go through the `/posts/*` path. For example:
View
13 spec/acceptance/posts_spec.rb
@@ -151,4 +151,17 @@
end.should raise_error(ActiveRecord::RecordNotFound)
end
end
+
+ context 'theme' do
+ it 'should not use the built-in layout by default' do
+ visit posts_path
+ page.should_not have_content('A postmarkdown blog')
+ end
+
+ it 'should use the built-in layout when the global option is set' do
+ Postmarkdown::Config.options[:use_theme] = true
+ visit posts_path
+ page.should have_content('A postmarkdown blog')
+ end
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.