-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Sven Fuchs
committed
Mar 17, 2010
1 parent
7fe6bd4
commit 619fa9f
Showing
44 changed files
with
424 additions
and
231 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class String | ||
def camelize | ||
to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase } | ||
end | ||
end unless ''.respond_to?(:camelize) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
class String | ||
if Module.method(:const_get).arity == 1 | ||
def constantize | ||
names = split('::') | ||
names.shift if names.empty? || names.first.empty? | ||
|
||
constant = Object | ||
names.each do |name| | ||
constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name) | ||
end | ||
constant | ||
end | ||
else | ||
def constantize | ||
names = split('::') | ||
names.shift if names.empty? || names.first.empty? | ||
|
||
constant = Object | ||
names.each do |name| | ||
constant = constant.const_get(name, false) || constant.const_missing(name) | ||
end | ||
constant | ||
end | ||
end | ||
end |
File renamed without changes.
4 changes: 2 additions & 2 deletions
4
lib/slick/core_ext/string/titleize.rb → lib/core_ext/string/titleize.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,7 @@ | ||
require 'action_view' | ||
|
||
module Slick | ||
autoload :Blog, 'slick/blog' | ||
autoload :Content, 'slick/content' | ||
autoload :Builder, 'slick/builder' | ||
autoload :Data, 'slick/data' | ||
autoload :Page, 'slick/page' | ||
autoload :Section, 'slick/section' | ||
autoload :Site, 'slick/site' | ||
autoload :Model, 'slick/model' | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module Slick::Builder | ||
autoload :Blog, 'slick/builder/blog' | ||
autoload :Content, 'slick/builder/content' | ||
autoload :Page, 'slick/builder/page' | ||
autoload :Section, 'slick/builder/section' | ||
|
||
class << self | ||
def create(parent, object, data) | ||
const_get(object.class.name.split('::').last).new(data, parent) | ||
end | ||
end | ||
end |
3 changes: 1 addition & 2 deletions
3
lib/slick/data/file_system/blog.rb → lib/slick/builder/blog.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
module Slick::Data::FileSystem | ||
module Slick::Builder | ||
class Blog < Section | ||
end | ||
end | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
require 'fileutils' | ||
|
||
module Slick::Builder | ||
class Content | ||
def view | ||
@@view ||= ActionView::Base.new([File.expand_path('../../views', __FILE__)]) | ||
end | ||
|
||
def document_root | ||
@@document_root ||= File.expand_path('../../../../public', __FILE__) | ||
end | ||
|
||
def write(file_name, html) | ||
path = [document_root, path, file_name].compact.join('/') | ||
FileUtils.mkdir_p(File.dirname(path)) | ||
File.open(path, 'w+') { |f| f.write(html) } | ||
end | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
module Slick | ||
module Slick::Builder | ||
class Page < Section | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
module Slick::Builder | ||
class Section < Content | ||
attr_reader :data, :site, :section, :parent | ||
|
||
def initialize(data, parent = nil) | ||
@parent = parent | ||
@data = data | ||
@site, @section = data.values_at(:site, :section) | ||
end | ||
|
||
def root? | ||
parent.nil? | ||
end | ||
|
||
def path # TODO should be in the model, we don't have routing, so keep it simple | ||
root? ? 'index' : [parent.root? ? nil : parent.path, section.slug].compact.join('/') | ||
end | ||
|
||
def build | ||
render_index | ||
section.contents.each { |content| render_content(content) } | ||
section.children.each { |child| Slick::Builder.create(self, child, data.merge(:section => child)).build } | ||
end | ||
|
||
def render_index | ||
write("#{path}.html", render('index', data)) | ||
end | ||
|
||
def render_content(content) | ||
write("#{content.permalink}.html", render('show', data.merge(:content => content))) | ||
end | ||
|
||
def render(template, locals) | ||
view.render(:file => "#{section.type}/#{template}", :locals => locals) | ||
end | ||
end | ||
end | ||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
require 'core_ext/string/camelize' | ||
|
||
module Slick::Model | ||
autoload :Base, 'slick/model/base' | ||
autoload :Blog, 'slick/model/blog' | ||
autoload :Content, 'slick/model/content' | ||
autoload :Page, 'slick/model/page' | ||
autoload :Section, 'slick/model/section' | ||
autoload :Site, 'slick/model/site' | ||
|
||
TYPES = { | ||
'_articles' => Page, | ||
'_posts' => Blog | ||
} | ||
|
||
class << self | ||
def build(path) | ||
determine_type(path).new(path) | ||
end | ||
|
||
def determine_type(path) | ||
subdirs = Dir["#{path}/_*"].map { |path| File.basename(path) } | ||
subdirs.each { |subdir| type = TYPES[subdir] and return type } | ||
Page | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
require 'pathname' | ||
|
||
module Slick::Model | ||
class Base < Pathname | ||
YAML_PREAMBLE = /^(---\s*\n.*?\n?)^(---\s*$\n?)/m | ||
|
||
attr_writer :attributes | ||
|
||
def attributes | ||
@attributes ||= read | ||
end | ||
|
||
def type | ||
self.class.name.split('::').last.underscore | ||
end | ||
|
||
def slug # TODO | ||
title.underscore.gsub(/[\W]/, '_') | ||
end | ||
|
||
def title_from_path | ||
title = File.basename(self.to_s).gsub(extname, '').titleize | ||
end | ||
|
||
def dirname | ||
directory? ? self : Pathname.new(self.to_s.gsub(extname, '')) | ||
end | ||
|
||
alias :created_at :ctime | ||
alias :updated_at :mtime | ||
|
||
def published_at | ||
attributes.key?(:published_at) ? attributes[:published_at] : ctime | ||
end | ||
|
||
def read | ||
attributes = { :title => title_from_path } | ||
attributes.merge!(parse(::File.read(self.to_s).strip)) if file? | ||
attributes | ||
end | ||
|
||
def parse(content) | ||
parse_yaml_preamble(content).merge(:content => content) | ||
end | ||
|
||
def parse_yaml_preamble(content) | ||
content.gsub!(YAML_PREAMBLE, '') | ||
$1 ? YAML.load($1).symbolize_keys : {} | ||
end | ||
|
||
def respond_to?(name) | ||
attributes.key?(name) | ||
end | ||
|
||
def method_missing(name, *args, &block) | ||
respond_to?(name) ? attributes[name] : super | ||
end | ||
|
||
def inspect | ||
super.gsub(/>/, " #{attributes.inspect}") | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module Slick::Model | ||
class Blog < Section | ||
end | ||
end | ||
|
Oops, something went wrong.