Class: Image

Inherits:
Object show all
Defined in:
lib/xiki/image.rb

Class Method Summary collapse

Class Method Details

.<<(file, txt = nil, options = {}) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/xiki/image.rb', line 36

def self.<< file, txt=nil, options={}
  txt ||= "@img/#{file}"

  # Copy to place with unique name, so a cached version doesn't get displayed...
  tmp_dir = "/tmp/img_tmp/"
  Dir.mkdir tmp_dir if ! File.directory? tmp_dir

  # Copy to place with unique name, so a cached version doesn't get displayed.

  unique_tmp_file = "#{tmp_dir}#{File.basename(file).sub /.+\./, "\\0#{rand(99999)}."}"

  File.copy file, unique_tmp_file

  Notes.enter_junior if options[:enter_junior]

  $el.insert_image $el.create_image(unique_tmp_file), txt
end

.>>(file, txt = nil) ⇒ Object



29
30
31
32
33
34
# File 'lib/xiki/image.rb', line 29

def self.>> file, txt=nil
  txt ||= "@img/#{file}"
  Move.to_end
  self.<< file, txt, :enter_junior=>1
  Move.backward
end


16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/xiki/image.rb', line 16

def self.menu
  %`
  .log/
  docs/
    > Show image underneath
    @image//tmp/draw_rect.gif
  api/
    > Examples
    | Insert an image:
    @Image << "/tmp/draw_rect.gif"
  `
end


6
7
8
9
10
11
12
13
14
# File 'lib/xiki/image.rb', line 6

def self.menu_before *args
  if args[-1] =~ /\.(png|gif|jpg)\/?$/
    path = args.join('/')
    Notes.enter_junior
    Image << path
    View.cursor = Line.right - 1
    return false   # Tell it to not continue to menu
  end
end