Skip to content
Browse files

Compatibility with Ruby 1.8.7.

  • Loading branch information...
1 parent e72ad00 commit a6eca766e6a2931d361f77d6aa945e965f5786a6 @hmans committed Feb 24, 2012
View
2 lib/schnitzelpress.rb
@@ -43,7 +43,7 @@ module Haml::Filters::Redcarpet
def render(text)
Redcarpet::Markdown.new(SchnitzelPress::MarkdownRenderer,
- autolink: true, space_after_headers: true, fenced_code_blocks: true).
+ :autolink => true, :space_after_headers => true, :fenced_code_blocks => true).
render(text)
end
end
View
6 lib/schnitzelpress/actions/blog.rb
@@ -6,7 +6,7 @@ module Blog
included do
get '/' do
@show_description = true
- if @post = Post.published.pages.where(slugs: 'home').first
+ if @post = Post.published.pages.where(:slugs => 'home').first
render_post
else
render_blog
@@ -65,14 +65,14 @@ def render_blog
get '/:year/:month/:day/:slug/?' do |year, month, day, slug|
@post = Post.
for_day(year.to_i, month.to_i, day.to_i).
- where(slugs: slug).first
+ where(:slugs => slug).first
render_post
end
get '/*/?' do
slug = params[:splat].first
- @post = Post.where(slugs: slug).first
+ @post = Post.where(:slugs => slug).first
render_post
end
View
10 lib/schnitzelpress/helpers.rb
@@ -49,10 +49,10 @@ def admin_only!
def form_field(object, attribute, options = {})
options = {
- label: attribute.to_s.humanize,
- value: object.send(attribute),
- errors: object.errors[attribute.to_sym],
- class_name: object.class.to_s.demodulize.underscore
+ :label => attribute.to_s.humanize,
+ :value => object.send(attribute),
+ :errors => object.errors[attribute.to_sym],
+ :class_name => object.class.to_s.demodulize.underscore
}.merge(options)
options[:name] ||= "#{options[:class_name]}[#{attribute}]"
@@ -66,7 +66,7 @@ def form_field(object, attribute, options = {})
else :text
end
- partial 'form_field', object: object, attribute: attribute, options: options
+ partial 'form_field', :object => object, :attribute => attribute, :options => options
end
end
end
View
40 lib/schnitzelpress/post.rb
@@ -13,24 +13,24 @@ class Post
store_in :posts
# basic data
- field :title, type: String
- field :body, type: String
- field :slugs, type: Array, default: []
+ field :title, :type => String
+ field :body, :type => String
+ field :slugs, :type => Array, :default => []
# optional fields
- field :summary, type: String
- field :link, type: String
- field :read_more, type: String
+ field :summary, :type => String
+ field :link, :type => String
+ field :read_more, :type => String
# times & status
- field :published_at, type: DateTime
- field :status, type: Symbol, default: :draft
+ field :published_at, :type => DateTime
+ field :status, :type => Symbol, :default => :draft
# flags
- field :disqus, type: Boolean, default: false
+ field :disqus, :type => Boolean, :default => false
# extra
- field :body_html, type: String
+ field :body_html, :type => String
# indices
index :slugs
@@ -39,18 +39,18 @@ class Post
# validations
validates_presence_of :status, :slug
- validates_inclusion_of :status, in: [:draft, :published]
+ validates_inclusion_of :status, :in => [:draft, :published]
scope :published, where(:status => :published)
scope :drafts, where(:status => :draft)
scope :pages, where(:published_at => nil)
scope :posts, where(:published_at.ne => nil)
- scope :article_posts, -> { posts.where(:link => nil) }
- scope :link_posts, -> { posts.where(:link.ne => nil) }
- scope :for_year, ->(year) { d = Date.new(year) ; where(published_at: (d.beginning_of_year)..(d.end_of_year)) }
- scope :for_month, ->(year, month) { d = Date.new(year, month) ; where(published_at: (d.beginning_of_month)..(d.end_of_month)) }
- scope :for_day, ->(year, month, day) { d = Date.new(year, month, day) ; where(published_at: (d.beginning_of_day)..(d.end_of_day)) }
- scope :latest, -> { published.posts.desc(:published_at) }
+ scope :article_posts, lambda { posts.where(:link => nil) }
+ scope :link_posts, lambda { posts.where(:link.ne => nil) }
+ scope :for_year, lambda { |year| d = Date.new(year) ; where(:published_at => (d.beginning_of_year)..(d.end_of_year)) }
+ scope :for_month, lambda { |year, month| d = Date.new(year, month) ; where(:published_at => (d.beginning_of_month)..(d.end_of_month)) }
+ scope :for_day, lambda { |year, month, day| d = Date.new(year, month, day) ; where(:published_at => (d.beginning_of_day)..(d.end_of_day)) }
+ scope :latest, lambda { published.posts.desc(:published_at) }
before_validation :nil_if_blank
before_validation :set_defaults
@@ -83,12 +83,12 @@ def slug=(v)
def set_defaults
if slug.blank?
- self.slug = (title || body.truncate(40, separator: ' ')).parameterize
+ self.slug = (title || body.truncate(40, :separator => ' ')).parameterize
end
end
def validate_slug
- conflicting_posts = Post.where(slugs: slug)
+ conflicting_posts = Post.where(:slugs => slug)
if published_at.present?
conflicting_posts = conflicting_posts.for_day(published_at.year, published_at.month, published_at.day)
end
@@ -120,7 +120,7 @@ def to_html
def render
@@markdown ||= Redcarpet::Markdown.new(MarkdownRenderer,
- autolink: true, space_after_headers: true, fenced_code_blocks: true)
+ :autolink => true, :space_after_headers => true, :fenced_code_blocks => true)
@@markdown.render(body)
end
View
10 lib/views/admin/admin.haml
@@ -4,9 +4,9 @@
You're logged in as #{session[:user]}.
%ul.admin
%li
- %a.green.button{href: '/admin/new'} Create new Post
- %a.red.button{href: '/logout'} Logout
+ %a.green.button{:href => '/admin/new'} Create new Post
+ %a.red.button{:href => '/logout'} Logout
- = partial "admin_post_list", posts: @drafts, title: "Drafts"
- = partial "admin_post_list", posts: @posts, title: "Published Posts"
- = partial "admin_post_list", posts: @pages, title: "Pages"
+ = partial "admin_post_list", :posts => @drafts, :title => "Drafts"
+ = partial "admin_post_list", :posts => @posts, :title => "Published Posts"
+ = partial "admin_post_list", :posts => @pages, :title => "Pages"
View
2 lib/views/admin/edit.haml
@@ -1,3 +1,3 @@
%section
%h1 Edit Post
- = partial 'post_form', post: @post
+ = partial 'post_form', :post => @post
View
2 lib/views/admin/new.haml
@@ -1,3 +1,3 @@
%section
%h1 New Post
- = partial 'post_form', post: @post
+ = partial 'post_form', :post => @post
View
10 lib/views/atom.haml
@@ -1,7 +1,7 @@
!!! XML
-%feed{xmlns: 'http://www.w3.org/2005/Atom'}
+%feed{:xmlns => 'http://www.w3.org/2005/Atom'}
%title= settings.blog_title
- %link{href: url_for('/', absolute: true)}
+ %link{:href => url_for('/', :absolute => true)}
%id= base_url
- if @posts.any?
%updated= @posts.first.published_at
@@ -12,12 +12,12 @@
- @posts.each do |post|
%entry
%title= html_escape post.title
- %link{href: url_for(post, absolute: true)}
- %id= url_for(post, absolute: true)
+ %link{:href => url_for(post, :absolute => true)}
+ %id= url_for(post, :absolute => true)
%published= post.published_at
%updated= post.published_at
%author
%name= settings.author_name
- %content{type: 'html'}
+ %content{:type => 'html'}
:cdata
#{post.to_html}
View
2 lib/views/index.haml
@@ -16,4 +16,4 @@
%footer
- if @show_previous_posts_button
- %a.button{ href: "/?page=#{params[:page].to_i + 1}"} View Older Posts
+ %a.button{:href => "/?page=#{params[:page].to_i + 1}"} View Older Posts
View
16 lib/views/layout.haml
@@ -2,18 +2,18 @@
%html
%head
%title= [@page_title, settings.blog_title].compact.join(" | ")
- %meta{ :"http-equiv" => "content-type", content: "text/html; charset=UTF-8" }
- %meta{ name: "viewport", content: "width=device-width, initial-scale=1.0" }
- %link{ href: '/blog.css', media: "screen", rel: "stylesheet", type: "text/css" }
- %link{ href: settings.feed_url, title: "Subscribe via Atom Feed", rel: 'alternate', type: 'application/atom+xml' }
- %script{ type: 'text/javascript', src: '//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js' }
- %script{ type: 'text/javascript', src: '//browserid.org/include.js' }
- %script{ type: 'text/javascript', src: '/js/schnitzelpress.js' }
+ %meta{ :"http-equiv" => "content-type", :content => "text/html; charset=UTF-8" }
+ %meta{ :name => "viewport", :content => "width=device-width, initial-scale=1.0" }
+ %link{ :href => '/blog.css', :media => "screen", :rel => "stylesheet", :type => "text/css" }
+ %link{ :href => settings.feed_url, :title => "Subscribe via Atom Feed", :rel => 'alternate', :type => 'application/atom+xml' }
+ %script{ :type => 'text/javascript', :src => '//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js' }
+ %script{ :type => 'text/javascript', :src => '//browserid.org/include.js' }
+ %script{ :type => 'text/javascript', :src => '/js/schnitzelpress.js' }
%body
.container
%header
.site-title
- %a{href: '/'}= settings.blog_title
+ %a{:href => '/'}= settings.blog_title
- if @show_description
~ markdown settings.blog_description
View
6 lib/views/login.haml
@@ -5,7 +5,7 @@
Please use one of the following services to log in:
%p
- %a.button#browser_id{href: '#'} Log in with BrowserID
+ %a.button#browser_id{:href => '#'} Log in with BrowserID
- %form{method: 'post', action: '/auth/browser_id/callback', noValidate: 'noValidate'}
- %input{type: 'hidden', name: 'assertion'}
+ %form{:method => 'post', :action => '/auth/browser_id/callback', :noValidate => 'noValidate'}
+ %input{:type => 'hidden', :name => 'assertion'}
View
4 lib/views/partials/_admin_post_list.haml
@@ -4,8 +4,8 @@
- posts.each do |post|
%ul.admin
%li
- %a.button{href: "/admin/edit/#{post.id}"} edit
+ %a.button{:href => "/admin/edit/#{post.id}"} edit
%li
- %a.button{href: url_for(post)} view
+ %a.button{:href => url_for(post)} view
%li
= post.title || ("%s..." % html_escape(post.body.first(50)))
View
16 lib/views/partials/_form_field.haml
@@ -1,26 +1,26 @@
- field_options = options.slice(:id, :name, :placeholder)
-.input{ class: [options[:type], options[:class]] }
- %label{ for: options[:id] } #{options[:label]}:
+.input{:class => [options[:type], options[:class]]}
+ %label{:for => options[:id]} #{options[:label]}:
- case options[:type].to_sym
- when :textarea
- %textarea{ id: options[:id], name: options[:name], rows: options[:rows] || 20, placeholder: options[:placeholder] }= html_escape(options[:value])
+ %textarea{:id => options[:id], :name => options[:name], :rows => options[:rows] || 20, :placeholder => options[:placeholder]}= html_escape(options[:value])
- when :radio
- options[:options].each do |o|
.option
- %input{ field_options.merge(type: 'radio', value: o, checked: options[:value] == o) }= o
+ %input{field_options.merge(:type => 'radio', :value => o, :checked => options[:value] == o)}= o
- when :dropdown
- %select{ field_options }
+ %select{field_options}
- options[:options].each do |val, text|
- %option{value: val, selected: options[:value] == val}= text
+ %option{:value => val, :selected => options[:value] == val}= text
- when :datetime
- %input{ field_options.merge(value: options[:value].to_formatted_s(:db)) }
+ %input{field_options.merge(:value => options[:value].to_formatted_s(:db))}
- else # normal inputs
- %input{ field_options.merge(value: options[:value]) }
+ %input{field_options.merge(:value => options[:value])}
- if options[:errors]
.error= options[:errors].join(", ")
View
12 lib/views/partials/_post.haml
@@ -6,11 +6,11 @@
- show_permalink ||= admin_logged_in? || (post.post? && !show_read_more)
- show_twitter ||= complete && post.post? && settings.twitter_id.present?
-%article.post{class: [post.status, post.link_post? ? 'link' : 'article']}
+%article.post{:class => [post.status, post.link_post? ? 'link' : 'article']}
%header
- if show_title
%h1
- %a{href: post.link || post.to_url}= post.title
+ %a{:href => post.link || post.to_url}= post.title
- if post.link_post?
%span.link-arrow
@@ -19,7 +19,7 @@
~ markdown post.summary
- if show_read_more
%p
- %a{href: url_for(post)}= post.read_more.presence || settings.read_more
+ %a{:href => url_for(post)}= post.read_more.presence || settings.read_more
- if show_body
@@ -28,14 +28,14 @@
%footer
- if show_permalink
%p.permalink
- %a{href: url_for(post)}= post.published_at.try(:to_date) || "∞"
+ %a{:href => url_for(post)}= post.published_at.try(:to_date) || "∞"
- if admin_logged_in?
·
- %a{href: "/admin/edit/#{post.id}"} edit
+ %a{:href => "/admin/edit/#{post.id}"} edit
- if show_twitter
.social_media_buttons
- if show_twitter
- %a{ href: "https://twitter.com/share", class: "twitter-share-button", data: { via: settings.twitter_id } }
+ %a{:href => "https://twitter.com/share", :class => "twitter-share-button", :data => {:via => settings.twitter_id}}
:javascript
!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");
View
22 lib/views/partials/_post_form.haml
@@ -1,18 +1,18 @@
-%form.post{ action: @post.new_record? ? '/admin/new' : "/admin/edit/#{@post.id}", method: 'post' }
- %input{ type: 'hidden', name: '_method', value: @post.new_record? ? 'post' : 'put'}
- = form_field @post, :title, placeholder: "Title of your post."
- = form_field @post, :link, placeholder: "Optional link to external URL."
- = form_field @post, :summary, type: :textarea, rows: 5, placeholder: "An optional summary of your post. Markdown formatting available."
- = form_field @post, :body, type: :textarea, rows: 20, placeholder: "Your post's body of text. Markdown formatting available."
- = form_field @post, :read_more, label: "'Read More' Link Text", placeholder: "When supplying a summary text, this will be the link to the full post."
+%form.post{:action => @post.new_record? ? '/admin/new' : "/admin/edit/#{@post.id}", :method => 'post'}
+ %input{:type => 'hidden', :name => '_method', :value => @post.new_record? ? 'post' : 'put'}
+ = form_field @post, :title, :placeholder => "Title of your post."
+ = form_field @post, :link, :placeholder => "Optional link to external URL."
+ = form_field @post, :summary, :type => :textarea, :rows => 5, :placeholder => "An optional summary of your post. Markdown formatting available."
+ = form_field @post, :body, :type => :textarea, :rows => 20, :placeholder => "Your post's body of text. Markdown formatting available."
+ = form_field @post, :read_more, :label => "'Read More' Link Text", :placeholder => "When supplying a summary text, this will be the link to the full post."
.row
.four.columns
- = form_field @post, :slug, label: 'URL Slug', placeholder: "Your post's URL slug.", hint: @post.previous_slugs.any? ? "Previous slugs: #{@post.previous_slugs.join ', '}" : nil
+ = form_field @post, :slug, :label => 'URL Slug', :placeholder => "Your post's URL slug.", :hint => @post.previous_slugs.any? ? "Previous slugs: #{@post.previous_slugs.join ', '}" : nil
.four.columns
- = form_field @post, :published_at, placeholder: 'Try "now", "in 3 days", ...'
+ = form_field @post, :published_at, :placeholder => 'Try "now", "in 3 days", ...'
.four.columns
- = form_field @post, :status, type: :dropdown, options: [[:draft, "Draft"], [:published, "Published"]]
+ = form_field @post, :status, :type => :dropdown, :options => [[:draft, "Draft"], [:published, "Published"]]
.buttons
- %input{ type: 'submit', value: @post.new_record? ? 'Create Post' : 'Update Post' }
+ %input{:type => 'submit', :value => @post.new_record? ? 'Create Post' : 'Update Post' }
View
2 lib/views/post.haml
@@ -1,6 +1,6 @@
- set_page_title @post.title.presence
-= partial @post, complete: true
+= partial @post, :complete => true
- if show_disqus? && @post.disqus?
%section.disqus
View
6 spec/app_spec.rb
@@ -23,8 +23,8 @@ def app
subject { last_response }
it { should be_ok }
- its(:body) { should have_tag 'title', text: "A Test Blog" }
- its(:body) { should have_tag 'section.posts > article.post.published', count: 5 }
+ its(:body) { should have_tag 'title', :text => "A Test Blog" }
+ its(:body) { should have_tag 'section.posts > article.post.published', :count => 5 }
its(:body) { should_not have_tag 'section.posts > article.post.draft' }
end
@@ -49,7 +49,7 @@ def app
describe 'viewing a single post' do
context 'when the post has multiple slugs' do
before do
- @post = Factory(:published_post, published_at: "2011-12-10 12:00", slugs: ['ancient-slug', 'old-slug', 'current-slug'])
+ @post = Factory(:published_post, :published_at => "2011-12-10 12:00", :slugs => ['ancient-slug', 'old-slug', 'current-slug'])
end
it 'should enforce the canonical URL' do
View
12 spec/factories.rb
@@ -1,28 +1,28 @@
FactoryGirl.define do
- factory :post, class: SchnitzelPress::Post do
+ factory :post, :class => SchnitzelPress::Post do
title { Faker::Lorem.sentence }
body { Faker::Lorem.paragraphs }
published_at { Time.now }
end
- factory :published_post, parent: :post do
+ factory :published_post, :parent => :post do
status :published
end
- factory :draft_post, parent: :post do
+ factory :draft_post, :parent => :post do
status :draft
end
- factory :page, parent: :post do
+ factory :page, :parent => :post do
published_at nil
end
- factory :published_page, parent: :page do
+ factory :published_page, :parent => :page do
status :published
published_at nil
end
- factory :draft_page, parent: :page do
+ factory :draft_page, :parent => :page do
status :draft
end
end
View
4 spec/post_spec.rb
@@ -45,7 +45,7 @@
context "when another post on the same day is already using the same slug" do
before do
- @other_post = Factory(:published_post, slugs: ["amazing-slug"])
+ @other_post = Factory(:published_post, :slugs => ["amazing-slug"])
subject.published_at = @other_post.published_at
subject.slug = "amazing-slug"
end
@@ -57,7 +57,7 @@
subject { Factory.build(:draft_page) }
before do
- @other_page = Factory(:published_page, slugs: ["amazing-slug"])
+ @other_page = Factory(:published_page, :slugs => ["amazing-slug"])
subject.slug = "amazing-slug"
end

0 comments on commit a6eca76

Please sign in to comment.
Something went wrong with that request. Please try again.