Sha256: 40241dec6182ddd413fed8c290ff8cda26af9146119b25d03488537b40dba77c

Contents?: true

Size: 1.33 KB

Versions: 3

Compression:

Stored size: 1.33 KB

Contents

# coding: utf-8

module Fig_00
  
  def imgs_list
    result = []
    (imgs rescue a_img_param).each do |h|
      a_img = {}
      raise "Error: No src:" if h["src"].nil?
      a_img[:fig_src] = make_src(h["src"])
      a_img[:href] = h["href"]
      a_img[:alt] = make_alt(h["alt"])
      a_img[:img_size] = make_img_size(h["width"], h["height"])
      result << a_img
    end
    result
  end

  def caption
    begin
      cap.chomp.sub(/^\\/, '').gsub(/\n/,'(((BR)))')
    rescue
      nil
    end
  end

  private
  def a_img_param
    [{"src" => (src rescue nil),
      "href" => (href rescue nil),
      "alt" => (alt rescue caption),
      "width" => (width rescue nil),
      "height" => (height rescue nil)}]
  end

  def make_src(l_src)
    case File.dirname(l_src)
    when ".", "images"
      f = File.basename(l_src)
      "/static/images/article/■記事ID■/#{/^\d+_/ =~ f ? f : '■記事ID■_' + f}"
    when "common"
      "/static/images/article/common/#{File.basename(l_src)}"
    else
      l_src
    end
  end

  def make_alt(l_alt)
    begin
      l_alt.gsub(/\[(.+?)\]\(.+?\)/, '\1').gsub(/\n/, '')
    rescue
      nil
    end
  end
  
  def make_img_size(l_width, l_height)
    s = []
    s << %Q{width="#{l_width}"} unless l_width.nil?
    s << %Q{height="#{l_height}"} unless l_height.nil?
    s.join(' ').strip
  end

end


Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
zine_brewer-1.9.0 lib/zine_brewer/templates/fig/module_fig_base.rb
zine_brewer-1.8.0 lib/zine_brewer/templates/fig/module_fig_base.rb
zine_brewer-1.7.0 lib/zine_brewer/templates/fig/module_fig_base.rb