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.1.8"

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
66
67
68
69
70
71
# 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
  FileUtils.mkdir_p dir + "/lib/"
  FileUtils.mkdir_p dir + "/bin/"

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

  if app
    app_file = get_app_file(app)

    puts "#{path}/bin/start_sample.rb #{dir}/bin/start_#{app_file}"
    FileUtils.cp_r "#{path}/bin/start_sample.rb", "#{dir}/bin/start_#{app_file}"
    FileUtils.cp_r "#{path}/bin/start_sample.rb", "#{dir}/bin/start_#{app_file.gsub(/rb$/,"rbw")}"

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

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

    puts "create #{app_file}"
    new_file = "#{dir}/lib/#{app_file}"
    FileUtils.cp("#{dir}/lib/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