Module: Middleman::Org::OrgArticle
- Defined in:
- lib/middleman-org/org_article.rb
Constant Summary collapse
- IN_BUFFER_SETTING_REGEXP =
/^#\+(\w+):\s*(.*)$/
Class Method Summary collapse
Instance Method Summary collapse
- #body ⇒ Object
- #date ⇒ Object
- #fix_links(content) ⇒ Object
- #in_buffer_setting ⇒ Object
- #org_data ⇒ Object
- #org_options ⇒ Object
- #published? ⇒ Boolean
- #render(opts = {}, locs = {}, &block) ⇒ Object
- #slug ⇒ Object
- #tags ⇒ Object
- #title ⇒ Object
Class Method Details
.extended(base) ⇒ Object
10 11 12 |
# File 'lib/middleman-org/org_article.rb', line 10 def self.extended(base) base.class.send(:attr_accessor, :org_controller) end |
Instance Method Details
#body ⇒ Object
76 77 78 |
# File 'lib/middleman-org/org_article.rb', line 76 def body render layout: false end |
#date ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/middleman-org/org_article.rb', line 80 def date return @_date if @_date @_date = in_buffer_setting['DATE'] # frontmatter_date = data['date'] # # First get the date from frontmatter # if frontmatter_date.is_a? Time # @_date = frontmatter_date.in_time_zone # else # @_date = Time.zone.parse(frontmatter_date.to_s) # end @_date end |
#fix_links(content) ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/middleman-org/org_article.rb', line 49 def fix_links(content) html = ::Nokogiri::HTML(content) html.xpath("//@src | //@href | //@poster").each do |attribute| attribute.value = attribute.value.gsub(/^(.+)\.org$/, '\1.html') end html.to_s end |
#in_buffer_setting ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/middleman-org/org_article.rb', line 24 def in_buffer_setting return @_in_buffer_setting if @_in_buffer_setting @_in_buffer_setting = {} File.open(source_file, 'r') do |f| f.each_line do |line| if line =~ IN_BUFFER_SETTING_REGEXP @_in_buffer_setting[$1] = $2 end end end @_in_buffer_setting end |
#org_data ⇒ Object
14 15 16 |
# File 'lib/middleman-org/org_article.rb', line 14 def org_data org_controller.data end |
#org_options ⇒ Object
18 19 20 |
# File 'lib/middleman-org/org_article.rb', line 18 def org_controller. end |
#published? ⇒ Boolean
72 73 74 |
# File 'lib/middleman-org/org_article.rb', line 72 def published? true end |
#render(opts = {}, locs = {}, &block) ⇒ Object
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/middleman-org/org_article.rb', line 38 def render(opts={}, locs={}, &block) unless opts.has_key?(:layout) opts[:layout] = .layout if opts[:layout].nil? # Convert to a string unless it's a boolean opts[:layout] = opts[:layout].to_s if opts[:layout].is_a? Symbol end content = super(opts, locs, &block) fix_links(content) end |
#slug ⇒ Object
97 98 |
# File 'lib/middleman-org/org_article.rb', line 97 def slug end |
#tags ⇒ Object
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/middleman-org/org_article.rb', line 61 def = in_buffer_setting['KEYWORDS'] return [] unless if .is_a? String .split(' ').map(&:strip) else Array().map(&:to_s) end end |
#title ⇒ Object
57 58 59 |
# File 'lib/middleman-org/org_article.rb', line 57 def title in_buffer_setting['TITLE'] || File.basename(source_file, '.*') end |