Class: Mdpreview::Translator

Inherits:
Object
  • Object
show all
Defined in:
lib/mdpreview/translator.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source_file_path) ⇒ Translator

Returns a new instance of Translator.



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/mdpreview/translator.rb', line 5

def initialize(source_file_path) 
  #源文件路径
  @source_file_path = source_file_path    
  #gem跟目录                          
  @gem_root_path = File.expand_path('../', @source_file_path)   
  #editor path
  @editor_path =  Pathname.new(File.expand_path('../../../vendor/examples', __FILE__)).realpath.to_s  
  
  p "@gem root_path:::"+@gem_root_path  
  p "@src file_path:::"+@source_file_path
  p "@editor  path :::"+@editor_path
  
end

Class Method Details

.create_json_file(data) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/mdpreview/translator.rb', line 39

def self.create_json_file(data)
  #gem跟目录                          
  gem_root_path = File.expand_path('../', @source_file_path)   
  f=File.new(File.join(gem_root_path,"data.json"), "w+")
  f.puts("#{data}")
  
  editor_path =  Pathname.new(File.expand_path('../../../vendor/examples', __FILE__)).realpath.to_s  
  
  f=File.new(File.join(editor_path,"meta.js"), "w+")
  f.puts("#{gem_root_path}/data.json")
  
  f.close
  p "#{data}"
  c=File.new(File.join(editor_path,"cur.file"), "w+")
  c.puts("#{data}")
  c.close
  
  p `open #{editor_path}/03_switch_mode.html`
  
end

Instance Method Details

#cp_source_file_to_cur_fileObject



34
35
36
37
# File 'lib/mdpreview/translator.rb', line 34

def cp_source_file_to_cur_file
  f=File.new(File.join(@editor_path,"cur.file"), "w+")
  FileUtils.cp @source_file_path,f
end

#generate_meta_jsObject



29
30
31
32
# File 'lib/mdpreview/translator.rb', line 29

def generate_meta_js
  f=File.new(File.join(@editor_path,"meta.js"), "w+")
  f.puts("#{@source_file_path}")
end

#hiObject



19
20
21
22
23
# File 'lib/mdpreview/translator.rb', line 19

def hi
    generate_meta_js
    cp_source_file_to_cur_file
    open_in_browser
end

#open_in_browserObject



25
26
27
# File 'lib/mdpreview/translator.rb', line 25

def open_in_browser
  p `open #{@editor_path}/03_switch_mode.html`
end