Module: Lazibi::Task
Instance Method Summary
collapse
#convert_path, #get_filters, #original_path, #sep_line, #skip_path?, #sort_filter
Instance Method Details
120
121
122
123
124
125
126
127
|
# File 'lib/task.rb', line 120
def get_metas
meta_files = File.join('meta', "**", "*.py.rb")
metas = {}
Dir.glob(meta_files).each do |t|
metas[t] = File.mtime t
end
metas
end
|
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/task.rb', line 36
def init_meta
real_dir = 'real'
if File.directory? real_dir
backup_dir = '.backup'
unless File.exists? backup_dir || true
puts "backup #{real_dir} to #{backup_dir}"
sep_line
FileUtils.cp_r real_dir, backup_dir
end
else
raise 'No directory named "real"'
end
meta_dir = 'meta'
FileUtils.mkdir_p meta_dir
if File.exists? meta_dir
if File.directory? meta_dir
FileUtils.rm_rf meta_dir
else
raise 'meta directory is reserved for instiki'
end
end
puts "Generating meta files:"
sep_line
Dir.glob(File.join('real', '**', '*.rb')) do |f|
if skip_path? f
puts "- #{f}"
next
end
next unless File.file? f
next if f =~ /.*[.]py[.]rb$/
py_path = convert_path f
dir_name = File.dirname py_path
puts ' ' + py_path
FileUtils.mkdir_p dir_name
make_py f, py_path
end
sep_line
end
|
#load_config ⇒ Object
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/task.rb', line 13
def load_config
@config = {}
default = {:exclude => ['^vendor'], :filters => {:optional_do => ['^spec'], :optional_end => ['']}}
config_path = File.join('real', 'config', 'lazibi_config.rb')
unless File.exists? config_path
config_dir = File.join('real', 'config')
FileUtils.mkdir_p config_dir
template_path = File.dirname(__FILE__) + '/../config/lazibi_config_template.rb'
FileUtils.cp template_path, config_path
puts 'created real/config/lazibi_config.rb'
end
puts 'loading lazibi_config.rb'
sep_line
require config_path
config = Config.new
for method in Config.instance_methods(false)
m = method.to_sym
@config[m] = config.send(m)
end
end
|
#make_py(rb_path, py_path) ⇒ Object
85
86
87
88
89
90
91
92
93
94
95
96
|
# File 'lib/task.rb', line 85
def make_py( rb_path, py_path )
rb = open(rb_path).read
py_file = open(py_path, 'w')
filters = get_filters(py_path)
engine = BeautifyEngine.new
engine.go_up(*filters)
py = engine.up rb
py_file.write(py)
py_file.close
end
|
#update_rb(meta_name, filters = {}) ⇒ Object
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
# File 'lib/task.rb', line 99
def update_rb( meta_name, filters = {} )
meta = open(meta_name)
real_name = convert_path meta_name
begin
real_path = File.dirname real_name
FileUtils.mkdir_p real_path
real_rb = open( real_name, 'w' )
filters = get_filters(meta_name).reverse
engine = BeautifyEngine.new
engine.go_down(*filters)
rb = engine.down meta.read
real_rb.write(rb)
rescue Exception => e
puts e
ensure
real_rb.close unless real_rb.nil?
end
meta.close
end
|