Sitepress ruby gems
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
benchmarks
bin
gemfiles
sitepress-cli
sitepress-core
sitepress-rails
sitepress-server
sitepress
support
.codeclimate.yml
.gitignore
.rspec
.rubocop.yml
.travis.yml
Appraisals
Gemfile
Guardfile
README.md
Rakefile

README.md

Sitepress

Sitepress is a file-backed website content manager that can be embedded in popular web frameworks like Rails, run stand-alone, or be compiled into static sites. Its useful for marketing pages or small websites that you need to deploy within your web frameworks.

Build Status Code Climate

Installation

Rails Installation

Follow the instructions in the Sitepress Rails gem.

Standalone Installation

Add this line to your application's Gemfile:

gem 'sitepress'

And then execute:

$ bundle

Or install it yourself as:

$ gem install sitepress

Usage

Given a the file hi.html.haml:

---
title: Name
meta:
  keywords: One
---

!!!
%html
  %head
    %title=current_page.data["title"]
  %body
    %h1 Hi
    %p This is just some content
    %h2 There

Sitepress can parse out the frontmatter and body to render inside your framework of choice, like Rails:

class SitepressController < ApplicationController
  def show
    sitepress.render "/hi"
  end
end

so when you call current_page.data from your templates, you get something like this:

> current_page.data
=> {"title"=>"Name", "meta"=>{"keywords"=>"One"}, "toc"=>["Hi", "There"]}
> current_page.data.dig("meta", "keywords")
=> "One"

Sitepress is designed to be embedded in rails and other Ruby web frameworks.

Features

Sitepress implements a subset of the best features from the Middleman static site generator including the Site and Frontmatter.

Frontmatter

Frontmatter is a way to attach metadata to content pages. Its a powerful way to enable a team of writers and engineers work together on content. The engineers focus on reading values from frontmatter while the writers can change values.

---
title: This is a swell doc
meta:
  keywords: this, is, a, test
background_color: #0f0
---

%html
  %head
    %meta(name="keywords" value="#{current_page.data.dig("meta", "keywords")}")
  %body(style="background: #{current_page.data["background_color"]};")
    %h1=current_page.data["title"]
    %p And here's the rest of the content!

Site

The Site accepts a directory path

> site = Sitepress::Site.new(root_path: "spec/pages")
=> #<Sitepress::Site:0x007fcd24103710 @root=#<Pathname:spec/pages>, @request_path=#<Pathname:/>>

Then you can request a resource by request path:

> resource = site.get("/test")
=> #<Sitepress::Resource:0x007fcd2488a128 @request_path="/test", @content_type="text/html", @file_path=#<Pathname:spec/pages/test.html.haml>, @frontmatter=#<Sitepress::Frontmatter:0x007fcd24889e80 @data="title: Name\nmeta:\n  keywords: One", @body="\n!!!\n%html\n  %head\n    %title=current_page.data[\"title\"]\n  %body\n    %h1 Hi\n    %p This is just some content\n    %h2 There\n">>

And access the frontmatter data (if available) and body of the template.

> resource.data
=> {"title"=>"Name", "meta"=>{"keywords"=>"One"}}
> resource.body
=> "\n!!!\n%html\n  %head\n    %title=current_page.data[\"title\"]\n  %body\n    %h1 Hi\n    %p This is just some content\n    %h2 There\n"

Resource globbing

The Site API is a powerful way to query content via resource globbing. For example, if you have a folder full of files but you only want all .html files within the docs directory, you'd do something like:

%ol
  -site.root.glob("docs/*.html*").each do |page|
    %li=link_to page.data["title"], page.request_path

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/sitepress/sitepress.