Module: Jdl

Defined in:
lib/jdl.rb,
lib/jdl/version.rb

Constant Summary collapse

VERSION =
"0.0.4"

Class Method Summary collapse

Class Method Details

.getfiles(path, fname, output_name, template_name) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/jdl.rb', line 21

def self.getfiles(path,fname,output_name,template_name)
  re = []
  allre = []
  Dir.foreach(path) do |f|
  	allre << f
  end
  allre.each do |f|
  	fullfilename = path + "/" + f
  	if f == "." or f == ".." 
       
    elsif File.directory?(fullfilename)
    	resub = []
  		resub = getfiles(fullfilename,fname,output_name,template_name)

  		if resub.length > 0
  			ref = {}
  			ref[f] = resub
  			re << ref
  		end
    
    elsif File.exist?(fullfilename) and (f =~ /\.#{fname}$/) # only rb file
      self.print_arr(fullfilename,output_name,template_name)
      # p  ff
    	re << f
      # p fullfilename
    end
  end
  
  return re
end

.parse(options) ⇒ Object



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

def self.parse(options)
  path = options[:path]
  file_ex = options[:file_ex]
  output_name = options[:output_name]
  template_name = options[:template_name]

  p "path = #{path}"                if(options[:debug])
  p "file_ex = #{file_ex}"          if(options[:debug])
  p "output_name = #{output_name}"  if(options[:debug])
  
  File.delete(options[:output_name]) if File.exist?(options[:output_name])
  
  self.getfiles(path,file_ex,output_name,template_name);

end


52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/jdl.rb', line 52

def self.print_arr(content,filename='jdl.js',template_name)
  f=open(filename,"a") 
  
  if(template_name)
    #如果有模板名称,则读取模板内容,替换内部的item
    t_content = ''
    IO.foreach(template_name) {|x|
      t_content << x
    }
    
    # p t_content
    f.puts(t_content.gsub(/##item##/, content)) 
  else
    f.puts("<script src='#{content}'></script>") 
  end
  
  f.close
end