Usage:
bundle install
bundle exec ruby app.rb
Server should start and you can point your page to http://localhost:8080 or one of the added pages, like: http://localhost:8080/this-is-cool (example pages are added in page.rb)
Usage:
bundle install
bundle exec ruby app.rb
Server should start and you can point your page to http://localhost:8080 or one of the added pages, like: http://localhost:8080/this-is-cool (example pages are added in page.rb)
class AbstractResource < Webmachine::Resource | |
private | |
def paths | |
ActionView::PathSet.new(["views"]) | |
end | |
def lookup_context | |
@_lookup_context ||= begin | |
ActionView::LookupContext.new(paths) | |
end | |
end | |
def renderer | |
@_renderer ||= ActionView::Renderer.new(lookup_context) | |
end | |
def view_context | |
@_view_context ||= begin | |
ActionView::Base.new(renderer, assigns, self) | |
end | |
end | |
end |
require 'bundler/setup' | |
require 'webmachine' | |
require 'action_view' | |
$:.unshift(".") | |
require 'page' | |
require 'abstract_resource' | |
class PageResource < AbstractResource | |
def resource_exists? | |
@page = Page.first(:slug => request.path_info[:slug]) | |
@page.present? | |
end | |
def to_html | |
renderer.render(view_context, :template => "page") | |
end | |
def assigns | |
{ :page => @page } | |
end | |
end | |
require 'webmachine/adapters/rack' | |
App = Webmachine::Application.new do |app| | |
app.configure do |config| | |
config.adapter = :Rack | |
end | |
app.routes do | |
add [:slug], PageResource | |
add [], PageResource, :slug => "__root" | |
end | |
end | |
App.run |
source "http://rubygems.org" | |
gem "webmachine" | |
gem "actionpack" | |
gem "thin" | |
gem "datamapper" | |
gem "dm-migrations" | |
gem "dm-sqlite-adapter" | |
gem "debugger" |
<!DOCTYPE html> | |
<html> | |
<head> | |
<title><%= @page.title %></title> | |
</head> | |
<body> | |
<h1><%= @page.title %></h1> | |
<article><%= @page.content %></article> | |
</body> | |
</html> |
require 'data_mapper' | |
require 'dm-migrations' | |
DataMapper.setup(:default, 'sqlite::memory:') | |
class Page | |
include DataMapper::Resource | |
property :id, Serial | |
property :title, String | |
property :slug, String | |
property :content, Text | |
end | |
DataMapper.finalize | |
DataMapper.auto_migrate! | |
Page.create(:title => "This is cool!", | |
:slug => "this-is-cool", | |
:content => "Yup, very cool") | |
Page.create(:title => "Main page", | |
:slug => "__root", | |
:content => "main page content") | |