class MyMediaBlogBase

Public Class Methods

new(media_type: 'blog', public_type: 'blog', ext: 'txt', config: nil) click to toggle source
Calls superclass method
# File lib/mymedia-blogbase.rb, line 12
def initialize(media_type: 'blog', public_type: 'blog', ext: 'txt', config: nil)
  
  super(media_type: media_type, public_type: public_type, ext: ext, config: config)
  @media_src = "%s/media/%s" % [@home, @public_type]
  @target_ext = '.html'
  @rss = true
  
end

Public Instance Methods

copy_publish(filename, raw_msg='') click to toggle source
# File lib/mymedia-blogbase.rb, line 22
def copy_publish(filename, raw_msg='')    
 
  src_path = File.join(@media_src, filename)

  raise "tags missing or too many tags" if File.open(src_path,'r')\
        .readlines.last.split.length > 5
  
  file_publish(src_path) do |destination, raw_destination|
    
    raw_msg = ''

    File.open(destination,'w') do |f|

      txt_destination = destination.sub(/html$/,'txt')
      FileUtils.cp src_path, txt_destination
      
      doc = html(File.open(src_path, 'r').read, File.basename(txt_destination))
      raw_msg = microblog_title(doc)
      f.write doc.xml
    end

    FileUtils.cp destination, raw_destination
    
    raw_msg
  end

end

Protected Instance Methods

html(raw_buffer, filename) click to toggle source
# File lib/mymedia-blogbase.rb, line 52
def html(raw_buffer, filename)

  doc = nil
  
  begin

    buffer = Martile.new(raw_buffer).to_html
    buffer = string_modifier(buffer)

    a = buffer.strip.lines.to_a
    a.first.sub!(/^[^#]/, '#\0') # add a '#' to the title of it's not there
    # make a list from the tags
    
    s = a.pop[/[^>]+$/].split.map{|x| "<li>%s</li>" % x}.join
    a.push "%s<ul>%s</ul>" % [$`, s]
    
    s = a.join

    raw_body = "<body>%s</body>" % RDiscount.new(s).to_html
    
    body = Rexle.new(raw_body)
          
    #format the code in the body

    document_modifier(body)

    ul = body.root.xpath('ul').last
    tags = ul.deep_clone

    ul.delete
    dl = "<dl id='info'><dt>Tags:</dt><dd/>\
      <dt>Source:</dt><dd><a href='#{filename}'>#{File.basename(filename)}</a></dd>\
      <dt>Published:</dt><dd>#{Time.now.strftime("%d-%m-%Y %H:%M")}</dd></dl>"

    body.root.add Rexle.new(dl)
    body.root.element('dl/dd').add tags        

    title = "%s %s | %s" % [body.root.text('h1'), \
      tags.xpath('li/text()').map{|x| "[%s]" % x}.join(' '), @domain]

    
    xml = RexleBuilder.new
    
    a = xml.html do 
      xml.head do
        xml.title title
        xml.link({rel: 'stylesheet', type: 'text/css', \
          href: @website + '/blog/layout.css', media: 'screen, projection, tv, print'},'')
        xml.link({rel: 'stylesheet', type: 'text/css', \
          href: @website + '/blog/style.css', media: 'screen, projection, tv, print'},'')          
        add_css_js(xml)      
      end
    end

    doc = Rexle.new(a)
    doc.root.add body
  
  rescue
    @logger.debug "mymedia-blogbase.rb: html: " + ($!).to_s
  end
  
  return doc
end
microblog_title(doc) click to toggle source
# File lib/mymedia-blogbase.rb, line 118
def microblog_title(doc)
  
  a = doc.root.element('head/title').text.split(/(?=\[(\w+)\])/)
  tags = a[1..-1].select.with_index {|x, i| i % 2 == 0}.map{|x| '#' + x}.join ' '
  title = a[0]
  url = "%s/%s/yy/mm/dd/hhmmhrs.html" % [@website, @media_type]
  full_title = (url + title + ' ' + tags)
  
  if full_title.length > 140 then
    extra = full_title.length - 140
    title = title[0..-(extra)] + ' ...'
  end

  title + ' ' + tags

end

Private Instance Methods

add_css_js(xml) click to toggle source
# File lib/mymedia-blogbase.rb, line 138
def add_css_js(xml)
  # overridden in the RSF file
end
document_modifier(body) click to toggle source
# File lib/mymedia-blogbase.rb, line 145
def document_modifier(body)
  # overridden in the RSF file
end
string_modifier(s) click to toggle source
# File lib/mymedia-blogbase.rb, line 141
def string_modifier(s)
  # overridden in the RSF file
  s
end