Coder Social home page Coder Social logo

postmarkdown's Introduction

Postmarkdown

A simple Rails blog engine powered by Markdown.

Postmarkdown is compatible with Rails 3 only and the gem is hosted on RubyGems.org.

Build Status

Features

  • Markdown files for blog posts
  • No database
  • RSS Feed
  • Customizable Routes
  • Built-in minimal theme (optional)
  • HTML5
  • Rails engine (so you can override models, views, controllers, etc)
  • Easily customized

Installation

Simply add Postmarkdown to your Gemfile and bundle it up:

gem 'postmarkdown'

Then, run the generator to setup Postmarkdown for your application:

$ rails generate postmarkdown:install

The above command performs the following actions:

  • Create the directory app/posts/. This directory is where your markdown files will live.
  • Generate an example post using today's date, eg. app/posts/2011-01-01-example-post.markdown.
  • Add some routes. By default the routes are setup underneath the path /posts/*, to customize these routes check out the Customizing Routes section below.

Usage

Generate a new Post

Here's an example of how to generate a new post using a slug and publish date:

$ rails generate postmarkdown:post test-post --date=2011-01-01

The above command will create the file app/posts/2011-01-01-test-post.markdown, which you can edit and add content to.

View the Post

Open http://localhost:3000/posts in your browser and you should be able to navigate to your new post. The URL for your new post is http://localhost:3000/posts/2011/01/01/test-post.

Overriding Files

The easiest way to customize the Postmarkdown functionality or appearance is by using the override generator. This generator can copy files from the Postmarkdown core and place them into your Rails app. For example:

$ rails generate postmarkdown:override --all        # overrides all of the things
$ rails generate postmarkdown:override --controller # overrides `app/controllers/posts_controller.rb`
$ rails generate postmarkdown:override --model      # overrides `app/models/post.rb`
$ rails generate postmarkdown:override --views      # overrides all files in directory `app/views/posts/`
$ rails generate postmarkdown:override --theme      # overrides the layout and stylesheet

RSS Feed

Postmarkdown comes prepared with a fully functional RSS feed.

You can take advantage of the built-in feed by adding the feed link to your HTML head tag. For example, simply add the following to your default layout:

<head>
  <!-- include your stylesheets and javascript here... -->
  <%= yield :head %>
</head>

To customize the feed title, add the following to an initializer (config/initializers/postmarkdown.rb):

Postmarkdown::Config.options[:feed_title] = 'Custom Blog Title Goes Here'

To link to the feed in your app, simply use the route helper: <%= link_to 'RSS Feed', posts_feed_path %>

Customizing the layout

By default, Postmarkdown will use your application's default layout, but if you wish to use a specific custom layout, you can set the following configuration in an initializer (config/initializers/postmarkdown.rb):

Postmarkdown::Config.options[:layout] = 'layout_name'

Built-in Theme

Postmarkdown comes with minimal built-in theme for your convenience.

Postmarkdown::Config.options[:layout] = 'postmarkdown'

Syntax Highlighting

Postmarkdown supports fenced code blocks which allows you to add syntax highlighting with an optional language identifier. For example, to syntax highlight Ruby code:

```ruby
require 'some_gem'
class RubyClass
  def some_method
    puts "string"
  end
end
```

This will add CSS classes to the HTML, but you still need to a stylesheet to visually highlight the code. Postmarkdown ships with a GitHub-like set of styles.

In your app/assets/stylesheets/application.css, include the CSS file:

/*
 *= require postmarkdown/syntax/github
 */

Or if you're using SCSS:

@import "postmarkdown/syntax/github";

Postmarkdown adds highlighting to your code using Rouge. See the demo page for supported languages and styles.

Customizing Routes

By default Postmarkdown will setup all routes to go through the /posts/* path. For example:

http://example.com/posts                      # lists all posts
http://example.com/posts/2011                 # lists all posts from 2011
http://example.com/posts/2011/01              # lists all posts from January 2011
http://example.com/posts/2011/01/01           # lists all posts from the 1st of January 2011
http://example.com/posts/2011/01/01/test-post # show the specified post

You can change the default route path by modifying the 'postmarkdown' line in routes.rb. For example:

postmarkdown :as => :blog

This will produce the following routes:

http://example.com/blog                      # lists all posts
http://example.com/blog/2011                 # lists all posts from 2011
http://example.com/blog/2011/01              # lists all posts from January 2011
http://example.com/blog/2011/01/01           # lists all posts from the 1st of January 2011
http://example.com/blog/2011/01/01/test-post # show the specified post

You can also customize the posts#show route via the :permalink_format option:

postmarkdown :as => :blog, :permalink_format => :day   # URL: http://example.com/blog/2011/01/01/test-post
postmarkdown :as => :blog, :permalink_format => :month # URL: http://example.com/blog/2011/01/test-post
postmarkdown :as => :blog, :permalink_format => :year  # URL: http://example.com/blog/2011/test-post
postmarkdown :as => :blog, :permalink_format => :slug  # URL: http://example.com/blog/test-post

What about mapping Postmarkdown to root? We got you covered:

postmarkdown :as => ''
root :to => 'posts#index'

Previewing Future-dated Posts

By default, Postmarkdown will only show posts that are dated on or before today. If you're writing a post to be published sometime in the future, you won't be able to view it in the browser.

To override this behaviour, add the following to an initializer (config/initializers/postmarkdown.rb):

Postmarkdown::Config.options[:allow_preview] = true

With the :allow_preview option set, you'll be able to view individual posts by their URL but they will remain hidden from the index and feed until the post date.

Example Directory Structure

├── app
│   ├── controllers
│   ├── helpers
│   ├── mailers
│   ├── models
│   ├── posts (where your markdown files live)
│   │   ├── 2011-04-01-example-1.markdown
│   │   ├── 2011-04-02-example-2.markdown
│   │   ├── 2011-04-03-example-3.markdown
│   │   ├── 2011-04-04-example-4.markdown
│   └── views
│       └── posts (overridable)
│           ├── _feed_link.html.haml
│           ├── _post.html.haml
│           ├── feed.xml.builder
│           ├── index.html.haml
│           └── show.html.haml

TODO

  • Generated routes should show example usage
  • Support more file formats, eg. textile
  • Built-in theme should have a link to the RSS Feed
  • Generator tests

Development

bundle
rake appraisal:install
rake # run the tests

License

MIT License. Copyright 2011 Ennova.

postmarkdown's People

Contributors

ivanvanderbyl avatar jasoncodes avatar jess avatar lazyatom avatar nathanaelkane avatar nowaterlili avatar twe4ked avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

postmarkdown's Issues

Add Rails 4 Compatibility

I run bundle and get the following output:

$  bundle
Fetching gem metadata from https://rubygems.org/...........
Fetching gem metadata from https://rubygems.org/..
Resolving dependencies...
Bundler could not find compatible versions for gem "rails":
  In Gemfile:
    postmarkdown (>= 0) ruby depends on
      rails (~> 3.0) ruby

    rails (4.0.0)

Error when rendering posts index

When I try to render my index page, I get this error message:

undefined method `captures' for nil:NilClass

The offending piece of code is in my index.html.haml file:

- if collection.present?
  = render collection, :summary => true
- else
  No posts found.

The offending line of code is the frist one. Any ideas?

render bug

If you want to include a reference to render in a post code block, it will try to render that as a partial/file.

Here's a failing test example. Any ideas?

jess@0953fb1

Overridden stylesheets

If you use the rails generate postmarkdown:override --all command, the created postmarkdown stylesheet in app/assets/stylesheets will be prioritised for your entire Rails app. I'm new at this, but I would just like to point this out. It might be obvious to some, but not newbies.

Next and previous post links as default features

Not really an issue I guess but it would be nice to have.

Right now I use a horrible a horrible implementation that goes through all the records and creates an Array to traverse. (Sorry, I'm a newbie to record traversal)

Idea: use Erb rather than Haml

I'm just mooting this; I recognise it's a personal decision, but hear me out :)

I recognise that many people prefer Haml, which is completely fine. It's also completely possible to use Postmarkdown as it current is with Erb templates in my app, since Rails will happily load and render either. However, there's currently no way to include Postmarkdown within an app without also installing Haml.

I think it's a good principle for any library to have only the dependencies that it really needs, so that when it is integrated into other applications there is as little chance as possible that any of the library dependencies interact with the application dependencies in unexpected ways.

It's a totally valid perspective to say "well, we like Haml and we always use Haml so having Postmarkdown generate Haml templates is more convenient for us". I just suspect that losing Haml as a dependency will make the library more attractive to more people, particularly those who are trying to minimise the number of dependencies their application ends up with.

Add format xml to posts_feed_path

Tested under Rails 4.0

posts_feed_path does not have .xml extension
/blog/feed will result in a missing template, because the default format is :html

Adding the .xml extension /blog/feed.xml will work.
We can use posts_feed_path(format: :xml) in app/views/_feed_link.html.haml

Or do you prefer adding xml format as the default format for /blog/feed ?

Proposal: Make the pagination gem configurable

Using kaminari was not feasible for my specific case, since it was causing conflicts with will_paginate which is being used elsewhere.

Fwiw. here's the (minimal) changes to use will_paginate:
delighted@10d6d03

Would you be amenable to the idea of making the pagination library pluggable somehow? Someway to configure which library to use?

If this sounds like something you would merge, I can do it. Let me know your thoughts.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.