lib/toto-bongo.rb in toto-bongo-1.0.2 vs lib/toto-bongo.rb in toto-bongo-1.0.3

- old
+ new

@@ -2,11 +2,11 @@ require 'date' require 'haml' require 'rack' require 'digest' require 'open-uri' -require 'RedCloth' +require 'rdiscount' require 'builder' require 'logger' $:.unshift File.dirname(__FILE__) require 'ext/ext' @@ -49,16 +49,16 @@ #set logger for debug if(ENV['TOTODEBUG']) @logger.level = Logger::DEBUG end - + # # Handles all templating options # Is responsible for: # 1. Calling the Haml engine on pages to render them to html - # 2. Calling the Textile engine on textile text to render them to html + # 2. Calling the markdown engine on markdown text to render them to html # 3. Registering All the classes at initialization # module Template # # This will call Haml render @@ -71,15 +71,21 @@ path = ([:layout, :repo].include?(page) ? Paths[:templates] : Paths[:pages]) result = config[:to_html].call(path, page, binding) end # - #Converst a textile text into html + #Converst a markdown text into html # - def textile text - TotoBongo::logger.debug("Called Template::Textile") - RedCloth.new(text.to_s.strip).to_html + def markdown text + TotoBongo::logger.debug("Called Template::Markdown") + if (options = @config[:markdown]) + Markdown.new(text.to_s.strip, *(options.eql?(true) ? [] : options)).to_html + else + text.strip + end + + Markdown.new(text.to_s.strip).to_html end # # Intercept any method missing # @@ -383,22 +389,22 @@ sum = if self[:body] =~ config[:delim] self[:body].split(config[:delim]).first else self[:body].match(/(.{1,#{length || config[:length] || config[:max]}}.*?)(\n|\Z)/m).to_s end - textile(sum.length == self[:body].length ? sum : sum.strip.sub(/\.\Z/, '&hellip;')) + markdown(sum.length == self[:body].length ? sum : sum.strip.sub(/\.\Z/, '&hellip;')) end def url TotoBongo::logger.debug("Article::url") "http://#{(@config[:url].sub("http://", '') + self.path).squeeze('/')}" end alias :permalink url def body TotoBongo::logger.debug("Article::body") - textile self[:body].sub(@config[:summary][:delim], '') rescue textile self[:body] + markdown self[:body].sub(@config[:summary][:delim], '') rescue markdown self[:body] end #Path returns a SEO friendly URL path # Eg for blog/articles/1900-05-17-the-wonderful-wizard-of-oz.txt # it returns /blog/1900/05/17/the-wonderful-wizard-of-oz/ @@ -451,10 +457,11 @@ Defaults = { :author => ENV['USER'], # blog author :title => Dir.pwd.split('/').last, # blog index title :description => "Blog for your existing rails app", # blog meta description + :markdown => :smart, # use markdown :keywords => "blog rails existing", # blog meta keywords :root => "index", # site index :url => "http://127.0.0.1", # root URL of the site :prefix => "blog", # common path prefix for the blog :date => lambda {|now| now.strftime("%d/%m/%Y") }, # date function @@ -468,13 +475,12 @@ :error => lambda {|code| # The HTML for your error page "<font style='font-size:300%'>toto-bongo error (#{code})</font>" } } - def initialize obj - + self.update Defaults self.update obj end def set key, val = nil, &blk @@ -492,17 +498,16 @@ # The HTTP server class Server attr_reader :config, :site - + def initialize config = {}, &blk @config = config.is_a?(Config) ? config : Config.new(config) @config.instance_eval(&blk) if block_given? @site = TotoBongo::Site.new(@config) end - # # This is the entry point of the request # On each request, this is the first method that gets # called #