Module: Xmvc::Generator

Defined in:
lib/xmvc/generator.rb,
lib/xmvc/generators/app.rb,
lib/xmvc/generators/boot.rb,
lib/xmvc/generators/view.rb,
lib/xmvc/generators/model.rb,
lib/xmvc/generators/layout.rb,
lib/xmvc/generators/scaffold.rb,
lib/xmvc/generators/controller.rb

Defined Under Namespace

Classes: App, Boot, Controller, Layout, Model, Scaffold, View

Constant Summary collapse

GENERATORS =
%w(app model controller scaffold view namespace)

Class Method Summary collapse

Class Method Details

.dispatch(generator, options, *params) ⇒ Object



16
17
18
19
20
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
51
52
53
# File 'lib/xmvc/generator.rb', line 16

def self.dispatch(generator, options, *params)
  Xmvc.public_path = File.expand_path("./public")
  
  unless GENERATORS.include?(generator)
    raise MVC::ArgumentError.new("Must use one of the following: " + GENERATORS.join(", ").downcase)
  end
  
  case generator
    when "app"
      options = options.dup
      App.start(params, options)
    when "model"
      model = Model.new([], options.dup)
      model.invoke("generate", [params.shift, *params])
    when "controller"
      name = params.shift
      controller = Controller.new([], options.dup)
      controller.invoke("generate", [name])
      if params.length
        params.each do |v|
          view = View.new([], options.dup) # why have to create new instance for each??
          view.invoke("generate", [name, v])
        end
      end
    when "scaffold"
      name = params.shift
      Xmvc.ui.warn("scaffold generation is not yet implemented")
      scaffold = Scaffold.new([], options.dup)
      scaffold.invoke("generate", [name, params])
    when "view"
      package = params.shift
      name    = params.shift
      view    = View.new([], options.dup)
      view.invoke("generate", [package, name])
    when "namespace"
      self.namespace(options)
  end
end

.namespace(namespace) ⇒ Object

overwrites all instances of ‘MyApp’ with the namespace provided



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/xmvc/generator.rb', line 56

def self.namespace(namespace)
  current = Xmvc.config["namespace"]
  
  configs = %w(
    config/environment.yml
    config/application.js
  )
  Dir["app/controllers/*.js"].each do |f|
    write_namespace(f, current, namespace)
  end
  Dir["app/views/*/*.js"].each do |f|
    write_namespace(f, current, namespace)
  end
  configs.each {|f| 
    write_namespace(f, current, namespace)
  }
  Xmvc.config.render
end

.script_tag(file) ⇒ Object



4
5
6
# File 'lib/xmvc/generators/layout.rb', line 4

def self.script_tag(file)
  '<script type="text/javascript" src="' + file + '"></script>'
end