Module: BrowserAppBase

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

Defined Under Namespace

Classes: Error

Constant Summary collapse

VERSION =
"0.0.7"

Class Method Summary collapse

Class Method Details

.create(arg) ⇒ Object



34
35
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
# File 'lib/browser_app_base.rb', line 34

def self.create(arg)
  dir = arg[:dir]
  app = arg[:app]
  puts "create application base #{dir}"

  FileUtils.mkdir_p dir

  path = File.dirname(File.expand_path(__FILE__))
  Dir.glob("#{path}/template/*") do |f|
    puts "#{f} => #{dir}"
    FileUtils.cp_r f, "#{dir}/"
  end

  if app
    app_file = get_app_file(app)

    load_app = "require '\#{app_file}'\n$app = \#{get_app_name(app)}.new\n"

    File.open("#{dir}/app_load.rb", "w") do |f|
      f.write load_app
    end

    puts "create #{app_file}"
    new_file = "#{dir}/#{app_file}"
    FileUtils.cp("#{dir}/my_app_sample.rb", new_file)
    buf = File.binread(new_file)
    File.binwrite(new_file, buf.gsub(/MyApp/, get_app_name(app)))
  end
end

.get_app_file(app) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/browser_app_base.rb', line 9

def self.get_app_file(app)
  app_file_name = ""
  app.each_char do |s|
    if s =~ /[A-Z]/
      app_file_name += "_" if app_file_name.size != 0
      app_file_name += s.downcase
    else
      app_file_name += s
    end
  end
  return app_file_name + ".rb"
end

.get_app_name(app) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/browser_app_base.rb', line 22

def self.get_app_name(app)
  app_name = ""
  app.each_char do |s|
    if s =~ /[a-z]/ and app_name.size == 0
      app_name += s.upcase
    else
      app_name += s
    end
  end
  return app_name
end