Class: Octopress::Printable::PostLinkConverter
- Defined in:
- lib/octopress-printable/post_link.rb
Instance Attribute Summary
Attributes inherited from Converter
Instance Method Summary collapse
- #convert(line) ⇒ Object
-
#initialize(source_dir, posts_dir, blog_url) ⇒ PostLinkConverter
constructor
A new instance of PostLinkConverter.
Methods inherited from Converter
#before_xelatex, #envs, get_includes, #header, #last_xelatex, #pandoc_args, timestamp, #xelatex_args
Constructor Details
#initialize(source_dir, posts_dir, blog_url) ⇒ PostLinkConverter
Returns a new instance of PostLinkConverter.
5 6 7 8 9 10 11 |
# File 'lib/octopress-printable/post_link.rb', line 5 def initialize(source_dir, posts_dir, blog_url) super() @source_dir = source_dir @posts_dir = posts_dir @blog_url = blog_url end |
Instance Method Details
#convert(line) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/octopress-printable/post_link.rb', line 13 def convert(line) str = line while /{% post_link (?<markup>[^\s]+)(?<text>\s+.+)? %}/ =~ str @match = true found_year = false if /^(?<year>\d+)-(?<month>\d+)-(?<day>\d+)-(?<title>.*)/ =~ markup found_year = true end if ! text File.open("#{@source_dir}/#{@posts_dir}/#{markup}.markdown", 'r') do |f| found_text = false while l = f.gets if /title: (?:"|')(?<text>.*)(?:"|')/ =~ l found_text = true end if ! found_year if /date: (?<year>\d+)-(?<month>\d+)-(?<day>\d+)/ =~ l found_year = true end end if found_text && found_year break end end end end str = str.sub(/{% post_link (.*?) %}/, "\\href{#{@blog_url}/#{year}/#{month}/#{day}/#{title}/}{#{text}}") end str end |