class Octopress::Tags::Quote::Tag
Constants
- Author
- AuthorTitle
- FullCite
- FullCiteWithTitle
Public Class Methods
new(tag_name, markup, tokens)
click to toggle source
Calls superclass method
# File lib/octopress-quote-tag.rb, line 15 def initialize(tag_name, markup, tokens) super if tag_name.strip == 'blockquote' @options = parse_legacy_markup(markup) else @options = parse_markup(%w{author title url}, markup) end end
Public Instance Methods
extract(input, regexp, indices_to_try = [1], default = nil)
click to toggle source
# File lib/octopress-quote-tag.rb, line 35 def extract(input, regexp, indices_to_try = [1], default = nil) thing = input.match(regexp) if thing.nil? default else indices_to_try.each do |index| return thing[index] if thing[index] end end end
figcaption()
click to toggle source
# File lib/octopress-quote-tag.rb, line 73 def figcaption if @options['author'] || @options['url'] || @options['title'] "<figcaption class='quote-source'>#{author || ''}#{title || ''}</figcaption>" end end
link(text)
click to toggle source
# File lib/octopress-quote-tag.rb, line 90 def link(text) if @options['url'] "<a class='quote-link' href='#{@options['url']}'>#{text}</a>" else text end end
parse_legacy_markup(markup)
click to toggle source
Use legacy regex matching to parse markup
# File lib/octopress-quote-tag.rb, line 47 def parse_legacy_markup(markup) options = {} if markup =~ FullCiteWithTitle options['author'] = $1 options['url'] = $2 + $3 options['title'] = $4.strip elsif markup =~ FullCite options['author'] = $1 options['url'] = $2 + $3 elsif markup =~ AuthorTitle options['author'] = $1 options['title'] = $2.strip elsif markup =~ Author options['author'] = $1 end options end
parse_markup(keys, markup)
click to toggle source
Parse string into hash object
# File lib/octopress-quote-tag.rb, line 26 def parse_markup(keys, markup) options = {} keys.each do |k| value = extract(markup, /\s*#{k}:\s*(("(.+?)")|('(.+?)')|(\S+))/i, [3, 5, 6]) options[k] = value end options end
render(context)
click to toggle source
# File lib/octopress-quote-tag.rb, line 65 def render(context) quote = "<blockquote>#{Utils.parse_content(super, context).strip}</blockquote>" if cap = figcaption quote = "<figure class='quote'>#{quote}#{cap}</figure>" end quote end
title()
click to toggle source
# File lib/octopress-quote-tag.rb, line 98 def title if @options['title'] t = "<cite class='quote-title'>#{link(@options['title'])}</cite>" t = " #{t}" if author t end end
trim_url(full_url)
click to toggle source
# File lib/octopress-quote-tag.rb, line 106 def trim_url(full_url) parts = [] short_url = full_url.match(/https?:\/\/(.+)/)[1][0..30] short_url << '…' unless short_url == full_url short_url end