Class: Havior::Generators::HaviorGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Defined in:
lib/generators/havior/havior_generator.rb

Constant Summary collapse

@@compiled_erb =
->(script, binding){
  file = File.expand_path("../templates/#{script}",__FILE__) 
  erb = ERB.new(open(file).read)
  erb.result(binding)
}

Instance Method Summary collapse

Instance Method Details

#append_hxmlObject



37
38
39
40
# File 'lib/generators/havior/havior_generator.rb', line 37

def append_hxml
  append_to_file @hxml_path,
    @@compiled_erb.call("haxe/havior.hxml.erb", binding)
end

#build_variablesObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/generators/havior/havior_generator.rb', line 6

def build_variables

  puts @hxml_path = "haxe/havior.hxml"
  puts @file_path = file_path
  puts @file_name = file_name
  puts @module_name = class_name
  puts @class_name = class_name.split("::").last
  puts @js_path = "javascripts/#{file_path}/#{file_name}.js"
  puts @css_path = "stylesheets/#{file_path}/#{file_name}.css"
  puts @haxe_class_full_name = file_path.camelize.gsub("::",".")
  puts @haxe_class_name = file_name.camelize
  puts @havior_root = "app/haviors/#{file_path}"
  puts @haxe_dir = "#{@havior_root}/haxe"
  puts @haxe_path = "#{@havior_root}/haxe/#{@haxe_class_name}.hx"
  puts @view_name = "#{file_name}.html.erb"
  puts @view_dir = "#{@havior_root}/views"
  puts @view_path = "#{@view_dir}/#{@view_name}"
  puts @actions = args.map{|arg|arg.split(":")}.map{|k,v| [k, v||"get"] }

end

#create_dummy_viewObject



42
43
44
# File 'lib/generators/havior/havior_generator.rb', line 42

def create_dummy_view
  create_file @view_path, "##{@class_name}"
end

#create_empty_js_cssObject



33
34
35
36
# File 'lib/generators/havior/havior_generator.rb', line 33

def create_empty_js_css
  create_file "public/#{@js_path}", ""
  create_file "public/#{@css_path}", ""
end

#create_haxeObject



45
46
47
48
# File 'lib/generators/havior/havior_generator.rb', line 45

def create_haxe
  create_file @haxe_path,
    @@compiled_erb.call("haviors/haxe/Havior.hx.erb", binding)
end

#create_rubiesObject



50
51
52
53
54
55
56
57
58
59
# File 'lib/generators/havior/havior_generator.rb', line 50

def create_rubies
  create_file "#{@havior_root}/model.rb",
    @@compiled_erb.call("haviors/model.rb.erb", binding)

  create_file "#{@havior_root}/#{@file_name}_controller.rb",
    @@compiled_erb.call("haviors/controller.rb.erb", binding)

  create_file "#{@havior_root}/routes.rb",
    @@compiled_erb.call("haviors/routes.rb.erb", binding)  
end