Sha256: eeb0c0baeeec236f1b92233c48e511dcaf012e5f9e1d3e041ef80da8e4d98f2f

Contents?: true

Size: 1.56 KB

Versions: 15

Compression:

Stored size: 1.56 KB

Contents

require 'standard'  # FIXME

class Livetext::Functions    # Functions will go here... user-def AND pre-def??
  Formats = ::Livetext::Standard::SimpleFormats

  @param = nil
  @context = nil

  class << self
    attr_accessor :param, :context
  end

  def date
    Time.now.strftime("%F")
  end

  def time
    Time.now.strftime("%T")
  end

  def link
    param = self.class.param
    text, url = param.split("|", 2)  # reverse these?
    "<a href='#{url}'>#{text}</a>"
  end

  def br
    n = self.class.param 
    n = "1" if n.empty?
    n = n.to_i
    "<br>"*n
  end

#   def asset
#     param = self.class.param
#     # FIXME how should this work?
#   end

  def yt
    param = self.class.param
    "https://www.youtube.com/watch?v=#{param}"
  end

  def simple_format(*args)
    param = self.class.param
    param ||= "NO PARAMETER"
    pairs = Formats.values_at(*args)
    str = param.dup
    pairs.reverse.each do |pair|
      str = "#{pair.first}#{str}#{pair.last}"
    end
    str
  end

  def b;    simple_format(:b); end
  def i;    simple_format(:i); end
  def t;    simple_format(:t); end
  def s;    simple_format(:s); end
  def bi;   simple_format(:b, :i); end
  def bt;   simple_format(:b, :t); end
  def bs;   simple_format(:b, :s); end
  def it;   simple_format(:i, :t); end
  def is;   simple_format(:i, :s); end
  def ts;   simple_format(:t, :s); end
  def bit;  simple_format(:b, :i, :t); end
  def bis;  simple_format(:b, :i, :s); end
  def bts;  simple_format(:b, :t, :s); end
  def its;  simple_format(:i, :t, :s); end
  def bits; simple_format(:b, :i, :t, :s); end

end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
livetext-0.8.72 lib/functions.rb
livetext-0.8.71 lib/functions.rb
livetext-0.8.70 lib/functions.rb
livetext-0.8.69 lib/functions.rb
livetext-0.8.68 lib/functions.rb
livetext-0.8.67 lib/functions.rb
livetext-0.8.66 lib/functions.rb
livetext-0.8.65 lib/functions.rb
livetext-0.8.64 lib/functions.rb
livetext-0.8.63 lib/functions.rb
livetext-0.8.62 lib/functions.rb
livetext-0.8.61 lib/functions.rb
livetext-0.8.60 lib/functions.rb
livetext-0.8.59 lib/functions.rb
livetext-0.8.58 lib/functions.rb