Sha256: c9c8e972101dc967c8c239835404f59572ac8122ad44cde02a8fbb53beaebdb2

Contents?: true

Size: 1.09 KB

Versions: 13

Compression:

Stored size: 1.09 KB

Contents

class Paste < Sequel::Model(:paste)
  set_schema do
    primary_key :id

    text :text, :null => false
    text :syntax, :null => false
    time :created
  end

  def text_fragment(style = STYLE)
    fragment = lines[0...10].join("\n")
    uv(fragment, style, lines = false)
  end

  def lines
    text.scan(/^.*?$/)
  end

  def view(format, style = STYLE)
    case format.downcase
    when /x?html/
      uv(text, style)
    else
      text
    end
  end

  def uv(text, style = STYLE, lines = true)
    Uv.parse(text, "xhtml", syntax, lines, style)
  rescue ArgumentError => ex
    Ramaze::Log::error(ex)
    "<pre>#{text}</pre>"
  end

  def syntax_name
    SYNTAX_LIST[syntax]
  end

  # Create prioritized and sorted list of syntaxes

  list = Ramaze::Dictionary.new

  syntaxes = Uv.instance_variable_get('@syntaxes')

  UV_PRIORITY_NAMES.each do |key|
    list[key] = syntaxes[key].name
  end

  (syntaxes.keys - UV_PRIORITY_NAMES).
    sort_by{|key| syntaxes[key].name}.
    each do |key|
    list[key] = syntaxes[key].name
  end

  SYNTAX_LIST = list
end

Paste.create_table! unless Paste.table_exists?

Version data entries

13 entries across 13 versions & 4 rubygems

Version Path
Pistos-ramaze-2008.09 examples/app/rapaste/model/paste.rb
Pistos-ramaze-2008.12 examples/app/rapaste/model/paste.rb
Pistos-ramaze-2009.01 examples/app/rapaste/model/paste.rb
Pistos-ramaze-2009.02 examples/app/rapaste/model/paste.rb
manveru-ramaze-2008.10 examples/app/rapaste/model/paste.rb
manveru-ramaze-2008.12 examples/app/rapaste/model/paste.rb
manveru-ramaze-2009.01 examples/app/rapaste/model/paste.rb
ptomato-ramaze-2009.02.1 examples/app/rapaste/model/paste.rb
ptomato-ramaze-2009.02 examples/app/rapaste/model/paste.rb
ramaze-2009.01 examples/app/rapaste/model/paste.rb
ramaze-2008.11 examples/app/rapaste/model/paste.rb
ramaze-2009.02 examples/app/rapaste/model/paste.rb
ramaze-2009.03 examples/app/rapaste/model/paste.rb