Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions TODO
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
TODO
====

* Missing a tag-cloud helper for sidebar.
56 changes: 54 additions & 2 deletions lib/toto.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,17 @@ def archives filter = ""
def article route
Article.new("#{Paths[:articles]}/#{route.join('-')}.#{self[:ext]}", @config).load
end


def tagged tag
articles = self.articles.collect do |article|
Article.new article, @config
end.select do |article|
!article[:tags].index(tag.humanize).nil?
end

{:articles => articles, :tag => tag}
end

def /
self[:root]
end
Expand All @@ -113,6 +123,8 @@ def go route, env = {}, type = :html
context[article(route), :article]
else http 400
end
elsif route.first == "tagged"
context[tagged(route.last), :tagged]
elsif respond_to?(path)
context[send(path, type), path.to_sym]
elsif (repo = @config[:github][:repos].grep(/#{path}/).first) &&
Expand Down Expand Up @@ -236,9 +248,10 @@ def load
elsif @obj.is_a? Hash
@obj
end.inject({}) {|h, (k,v)| h.merge(k.to_sym => v) }

self.taint
self.update data
self[:tags] = self[:tags].split(',').collect{|tag| tag.strip.humanize }
self[:date] = Date.parse(self[:date].gsub('/', '-')) rescue Date.today
self
end
Expand Down Expand Up @@ -274,13 +287,51 @@ def body
def path
"/#{@config[:prefix]}#{self[:date].strftime("/%Y/%m/%d/#{slug}/")}".squeeze('/')
end

def tags
self[:tags].collect {|tag| "<a href=\"/tagged/#{tag.slugize}\">#{tag}</a>" }.join(@config[:tag_separator])
end

def title() self[:title] || "an article" end
def date() @config[:date].call(self[:date]) end
def author() self[:author] || @config[:author] end
def to_html() self.load; super(:article, @config) end
alias :to_s to_html
end

class TagCloud < Hash
def initialize articles
# Count all article tags
articles.each do |article|
article[:tags].each do |word|
unless self.key? word
self[word] = 0
else
self[word] = self[word] + 1
end
end
end
end

def font_ratio
min, max = 1000000, -1000000
self.each_key do |word|
max = self[word] if self[word] > max
min = self[word] if self[word] < min
end
18.0 / (max - min)
end

def build
cloud = String.new
ratio = font_ratio
self.each_key do |word|
font_size = (9 + (self[word] * ratio))
cloud << %Q{<span><a href="#" style="font-size:#{font_size}pt;">#{word}</a></span> }
end
cloud
end
end

class Config < Hash
Defaults = {
Expand All @@ -294,6 +345,7 @@ class Config < Hash
:disqus => false, # disqus name
:summary => {:max => 150, :delim => /~\n/}, # length of summary and delimiter
:ext => 'txt', # extension for articles
:tag_separator => ' ', # tag separator for articles
:cache => 28800, # cache duration (seconds)
:github => {:user => "", :repos => [], :ext => 'md'}, # Github username and list of repos
:to_html => lambda {|path, page, ctx| # returns an html, from a path & context
Expand Down
3 changes: 3 additions & 0 deletions test/templates/index.rhtml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
</ul>
<div id="archives">
<%= archives[3...5] %>
</div>
<div id="tag-cloud">

</div>
<!-- testing env variable passing -->
<p>env passed: <%= env != nil %><br/></p>
Expand Down
8 changes: 4 additions & 4 deletions toto.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ Gem::Specification.new do |s|
s.version = "0.4.9"

s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["cloudhead"]
s.date = %q{2010-12-01}
s.authors = ["cloudhead", "endel"]
s.date = %q{2011-04-27}
s.description = %q{the tiniest blog-engine in Oz.}
s.email = %q{self@cloudhead.net}
s.email = %q{talk@endel.me}
s.extra_rdoc_files = [
"LICENSE",
"README.md"
Expand Down Expand Up @@ -44,7 +44,7 @@ Gem::Specification.new do |s|
"test/toto_test.rb",
"toto.gemspec"
]
s.homepage = %q{http://github.com/cloudhead/toto}
s.homepage = %q{http://github.com/endel/toto}
s.rdoc_options = ["--charset=UTF-8"]
s.require_paths = ["lib"]
s.rubygems_version = %q{1.3.5}
Expand Down