xmvc 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/bin/xmvc +2 -0
- data/lib/xmvc/builder.rb +2 -7
- data/lib/xmvc/cli.rb +7 -5
- data/lib/xmvc/environment.rb +89 -5
- data/lib/xmvc/generator.rb +37 -29
- data/lib/xmvc/generators/app.rb +54 -88
- data/lib/xmvc/generators/boot.rb +43 -0
- data/lib/xmvc/generators/controller.rb +18 -33
- data/lib/xmvc/generators/layout.rb +25 -0
- data/lib/xmvc/generators/model.rb +24 -33
- data/lib/xmvc/generators/scaffold.rb +10 -8
- data/lib/xmvc/generators/templates/Model.js +3 -3
- data/lib/xmvc/generators/templates/ModelSpec.js +2 -2
- data/lib/xmvc/generators/templates/app/{config → public/config}/environment.yml +0 -0
- data/lib/xmvc/generators/templates/{app/public/config/boot.js → boot.js} +9 -19
- data/lib/xmvc/generators/templates/layout.html.erb +24 -0
- data/lib/xmvc/generators/view.rb +19 -27
- data/lib/xmvc/stats.rb +1 -18
- data/lib/xmvc.rb +13 -23
- data/xmvc.gemspec +7 -9
- metadata +8 -10
- data/lib/xmvc/generators/base.rb +0 -99
- data/lib/xmvc/generators/templates/app/config/environments/development.yml +0 -0
- data/lib/xmvc/generators/templates/app/config/environments/production.yml +0 -0
- data/lib/xmvc/settings.rb +0 -134
- data/lib/xmvc/ui.rb +0 -55
@@ -1,14 +1,16 @@
|
|
1
1
|
module Xmvc
|
2
2
|
module Generator
|
3
|
-
class Scaffold <
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
3
|
+
class Scaffold < Thor
|
4
|
+
include Thor::Actions
|
5
|
+
|
6
|
+
def self.source_root
|
7
|
+
File.join(Xmvc::TEMPLATE_PATH)
|
8
8
|
end
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
|
10
|
+
desc "generate", "Generate a new Scaffold"
|
11
|
+
def generate(name, *fields)
|
12
|
+
@name = name
|
13
|
+
@fields = fields
|
12
14
|
end
|
13
15
|
end
|
14
16
|
end
|
@@ -3,7 +3,7 @@
|
|
3
3
|
* @extends ExtMVC.model.Base
|
4
4
|
*/
|
5
5
|
ExtMVC.model.define("<%= @class_name %>", {
|
6
|
-
fields:
|
7
|
-
<%= @fields %>
|
8
|
-
]
|
6
|
+
fields: [<% @fields.each do |field| %>
|
7
|
+
{"name": "<%= field[:name] %>", "type": "<%= field[:type] %>"}<% if field != @fields.last %>,<% end %>
|
8
|
+
<% end %>]
|
9
9
|
});
|
@@ -1,8 +1,8 @@
|
|
1
1
|
Screw.Unit(function() {
|
2
2
|
describe("The <%= @class_name %> class", function() {
|
3
|
-
var <%= @
|
3
|
+
var <%= @var_name %>;
|
4
4
|
before(function() {
|
5
|
-
<%= @
|
5
|
+
<%= @var_name %> = new <%= @namespace %>.models.<%= @class_name %>({
|
6
6
|
//set fields for this model here
|
7
7
|
});
|
8
8
|
});
|
File without changes
|
@@ -38,25 +38,15 @@
|
|
38
38
|
environment = params.environment;
|
39
39
|
|
40
40
|
var fileOrders = {
|
41
|
-
production : [
|
42
|
-
'
|
43
|
-
|
44
|
-
|
45
|
-
'
|
46
|
-
],
|
47
|
-
|
48
|
-
'
|
49
|
-
|
50
|
-
'/public/mvc/mvc-all-debug.js'
|
51
|
-
],
|
52
|
-
test : [
|
53
|
-
'http://extjs.cachefly.net/ext-3.1.1/adapter/ext/ext-base.js',
|
54
|
-
'http://extjs.cachefly.net/ext-3.1.1/ext-all-debug.js',
|
55
|
-
'/public/mvc/mvc-all.js',
|
56
|
-
'/public/app/app-all.js',
|
57
|
-
'../vendor/jspec/lib/jspec.js',
|
58
|
-
'../spec/TestHelper.js'
|
59
|
-
]
|
41
|
+
production : [<% @production.each do |file| %>
|
42
|
+
'<%= file %>'<% if @production.last != file %>,<% end %>
|
43
|
+
<% end %>],
|
44
|
+
development: [<% @development.each do |file| %>
|
45
|
+
'<%= file %>'<% if @development.last != file %>,<% end %>
|
46
|
+
<% end %>],
|
47
|
+
test: [<% @test.each do |file| %>
|
48
|
+
'<%= file %>'<% if @test.last != file %>,<% end %>
|
49
|
+
<% end %>]
|
60
50
|
};
|
61
51
|
|
62
52
|
var filesToLoad = fileOrders[environment];
|
@@ -0,0 +1,24 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
2
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
3
|
+
<html>
|
4
|
+
<head>
|
5
|
+
<meta content='text/html; charset=UTF-8' http-equiv='Content-Type' />
|
6
|
+
<link href="http://extjs.cachefly.net/ext-3.1.1/resources/css/ext-all.css" rel='stylesheet' type='text/css' />
|
7
|
+
<link href='/public/stylesheets/extjs-mvc-all.css' rel='stylesheet' type='text/css' />
|
8
|
+
|
9
|
+
<%= @javascripts %>
|
10
|
+
|
11
|
+
<title>Ext MVC Application</title>
|
12
|
+
</head>
|
13
|
+
<body>
|
14
|
+
<div id="loading-mask"></div>
|
15
|
+
<div id="loading">
|
16
|
+
<div class="loading-indicator">
|
17
|
+
Loading...
|
18
|
+
</div>
|
19
|
+
</div>
|
20
|
+
<!--<script type="text/javascript" src="/config/boot.js"></script>-->
|
21
|
+
|
22
|
+
|
23
|
+
</body>
|
24
|
+
</html>
|
data/lib/xmvc/generators/view.rb
CHANGED
@@ -1,33 +1,25 @@
|
|
1
1
|
module Xmvc
|
2
2
|
module Generator
|
3
|
-
class View <
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
@name = Extlib::Inflection.underscore(name)
|
9
|
-
|
10
|
-
@view_filename = "app/views/#{@package}/#{@name}.js"
|
11
|
-
|
12
|
-
@gsubs.merge!({
|
13
|
-
'name' => @name,
|
14
|
-
'namespace' => @package,
|
15
|
-
'filename' => @view_filename,
|
16
|
-
'class_name' => Extlib::Inflection.camelize(@name)
|
17
|
-
})
|
18
|
-
|
19
|
-
Xmvc::Settings.add(:views, {
|
20
|
-
:package => @package,
|
21
|
-
:filename => @name
|
22
|
-
})
|
23
|
-
|
3
|
+
class View < Thor
|
4
|
+
include Thor::Actions
|
5
|
+
|
6
|
+
def self.source_root
|
7
|
+
File.join(Xmvc::TEMPLATE_PATH)
|
24
8
|
end
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
9
|
+
|
10
|
+
desc "generate", "Generate a new View"
|
11
|
+
def generate(package, name)
|
12
|
+
@namespace = Extlib::Inflection.underscore(package)
|
13
|
+
@name = Extlib::Inflection.underscore(name)
|
14
|
+
@filename = "app/views/#{@namespace}/#{@name}.js"
|
15
|
+
|
16
|
+
unless File.exists? @filename
|
17
|
+
Xmvc.environment.add(:views, {
|
18
|
+
:package => @package,
|
19
|
+
:filename => @name
|
20
|
+
})
|
21
|
+
end
|
22
|
+
template("View.js", @filename)
|
31
23
|
end
|
32
24
|
end
|
33
25
|
end
|
data/lib/xmvc/stats.rb
CHANGED
@@ -222,24 +222,7 @@ module Xmvc
|
|
222
222
|
:class_length => file_count == 0 ? 0 : loc_count / file_count
|
223
223
|
}
|
224
224
|
end
|
225
|
-
|
226
|
-
|
227
|
-
Description goes here.
|
228
|
-
|
229
|
-
== Note on Patches/Pull Requests
|
230
|
-
|
231
|
-
* Fork the project.
|
232
|
-
* Make your feature addition or bug fix.
|
233
|
-
* Add tests for it. This is important so I don't break it in a
|
234
|
-
future version unintentionally.
|
235
|
-
* Commit, do not mess with rakefile, version, or history.
|
236
|
-
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
237
|
-
* Send me a pull request. Bonus points for topic branches.
|
238
|
-
|
239
|
-
== Copyright
|
240
|
-
|
241
|
-
Copyright (c) 2010 Christocracy. See LICENSE for details.
|
242
|
-
|
225
|
+
|
243
226
|
#calculates statistics on a given file
|
244
227
|
def file_statistics(filename)
|
245
228
|
line_count = 0; loc_count = 0;
|
data/lib/xmvc.rb
CHANGED
@@ -11,20 +11,23 @@ module Xmvc
|
|
11
11
|
|
12
12
|
ROOT = File.dirname(__FILE__)
|
13
13
|
|
14
|
+
CONFIG_PATH = "config"
|
15
|
+
|
16
|
+
TEMPLATE_PATH = File.join(ROOT, "xmvc", "generators", "templates")
|
17
|
+
|
18
|
+
PUBLIC_PATH = "public"
|
19
|
+
|
14
20
|
##
|
15
21
|
# Do autoloads here
|
16
22
|
#
|
17
|
-
require 'xmvc/settings'
|
18
23
|
require 'xmvc/builder'
|
19
24
|
|
20
|
-
autoload :UI, 'xmvc/ui'
|
25
|
+
#autoload :UI, 'xmvc/ui'
|
21
26
|
autoload :Generator, 'xmvc/generator'
|
22
27
|
autoload :Environment, 'xmvc/environment'
|
23
28
|
autoload :Plugin, 'xmvc/plugin'
|
24
29
|
autoload :Stats, 'xmvc/stats'
|
25
|
-
autoload :
|
26
|
-
autoload :Text, 'xmvc/test'
|
27
|
-
autoload :Settings, 'xmvc/settings'
|
30
|
+
autoload :Test, 'xmvc/test'
|
28
31
|
|
29
32
|
class Error < StandardError
|
30
33
|
def self.status_code(code = nil)
|
@@ -74,37 +77,24 @@ module Xmvc
|
|
74
77
|
end
|
75
78
|
end
|
76
79
|
|
77
|
-
def settings
|
78
|
-
@settings ||= Settings.load
|
79
|
-
end
|
80
|
-
|
81
80
|
##
|
82
81
|
# Ensure we're running within a rails app unless generating a new app ($ xmvc generate app foo)
|
83
82
|
#
|
84
83
|
def ensure_in_app
|
85
|
-
|
86
|
-
|
87
|
-
if File.exists?("app") && File.exists?("config") && File.exists?("config/environment.json")
|
88
|
-
|
89
|
-
FileUtils.chdir("..")
|
90
|
-
##
|
91
|
-
# For development, ensure we don't execute from installed gem code
|
92
|
-
#
|
93
|
-
$LOAD_PATH.unshift('../lib')
|
94
|
-
#
|
95
|
-
#
|
96
|
-
end
|
97
84
|
|
98
85
|
# Check for existence of arbitrary app files...see if it *looks* like we're in an Xmvc app.
|
99
86
|
unless ARGV.empty? || ARGV.first == "help" || (File.exists?("config") && File.exists?("config/environment.yml"))
|
100
87
|
raise Xmvc::AppNotFound.new("This command must be executed from the root of an xmvc application")
|
101
88
|
end
|
102
|
-
Settings.load
|
103
89
|
|
104
90
|
end
|
105
91
|
|
92
|
+
def asset_mgr(options={})
|
93
|
+
@asset_mgr ||= Jammit::CLI.new([], options)
|
94
|
+
end
|
95
|
+
|
106
96
|
def ui
|
107
|
-
@ui ||=
|
97
|
+
@ui ||= Thor::Shell::Basic
|
108
98
|
end
|
109
99
|
end
|
110
100
|
end
|
data/xmvc.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{xmvc}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Ed Spencer and Chris Scott"]
|
12
|
-
s.date = %q{2010-03-
|
12
|
+
s.date = %q{2010-03-13}
|
13
13
|
s.default_executable = %q{xmvc}
|
14
14
|
s.description = %q{A full-stack, full-stack MVC framework generator geared towards generating towards the Ext JS framework. The actual javascript framework implementation is provided by the Gem extjs-mvc. This gem contains a series of builders and erb-templates for auto-generating javascript model, view and controller class-files.}
|
15
15
|
s.email = %q{christocracy@gmail.com}
|
@@ -40,8 +40,9 @@ Gem::Specification.new do |s|
|
|
40
40
|
"lib/xmvc/environment.rb",
|
41
41
|
"lib/xmvc/generator.rb",
|
42
42
|
"lib/xmvc/generators/app.rb",
|
43
|
-
"lib/xmvc/generators/
|
43
|
+
"lib/xmvc/generators/boot.rb",
|
44
44
|
"lib/xmvc/generators/controller.rb",
|
45
|
+
"lib/xmvc/generators/layout.rb",
|
45
46
|
"lib/xmvc/generators/model.rb",
|
46
47
|
"lib/xmvc/generators/scaffold.rb",
|
47
48
|
"lib/xmvc/generators/templates/Controller.js",
|
@@ -49,18 +50,15 @@ Gem::Specification.new do |s|
|
|
49
50
|
"lib/xmvc/generators/templates/ModelSpec.js",
|
50
51
|
"lib/xmvc/generators/templates/View.js",
|
51
52
|
"lib/xmvc/generators/templates/_Action.js",
|
52
|
-
"lib/xmvc/generators/templates/app/config/environment.yml",
|
53
|
-
"lib/xmvc/generators/templates/app/config/environments/development.yml",
|
54
|
-
"lib/xmvc/generators/templates/app/config/environments/production.yml",
|
55
53
|
"lib/xmvc/generators/templates/app/public/app/App.js",
|
56
54
|
"lib/xmvc/generators/templates/app/public/app/controllers/application_controller.js",
|
57
55
|
"lib/xmvc/generators/templates/app/public/app/controllers/home_controller.js",
|
58
56
|
"lib/xmvc/generators/templates/app/public/app/views/home/index.js",
|
59
57
|
"lib/xmvc/generators/templates/app/public/app/views/layout/menu.js",
|
60
58
|
"lib/xmvc/generators/templates/app/public/config/application.js",
|
61
|
-
"lib/xmvc/generators/templates/app/public/config/boot.js",
|
62
59
|
"lib/xmvc/generators/templates/app/public/config/database.js",
|
63
60
|
"lib/xmvc/generators/templates/app/public/config/environment.json",
|
61
|
+
"lib/xmvc/generators/templates/app/public/config/environment.yml",
|
64
62
|
"lib/xmvc/generators/templates/app/public/config/environments/development.json",
|
65
63
|
"lib/xmvc/generators/templates/app/public/config/environments/production.json",
|
66
64
|
"lib/xmvc/generators/templates/app/public/config/routes.js",
|
@@ -86,14 +84,14 @@ Gem::Specification.new do |s|
|
|
86
84
|
"lib/xmvc/generators/templates/app/public/vendor/screw-unit/spec/print_spec.js",
|
87
85
|
"lib/xmvc/generators/templates/app/public/vendor/screw-unit/spec/spec_helper.js",
|
88
86
|
"lib/xmvc/generators/templates/app/public/vendor/screw-unit/spec/suite.html",
|
87
|
+
"lib/xmvc/generators/templates/boot.js",
|
88
|
+
"lib/xmvc/generators/templates/layout.html.erb",
|
89
89
|
"lib/xmvc/generators/templates/scaffold/ScaffoldController.js",
|
90
90
|
"lib/xmvc/generators/view.rb",
|
91
91
|
"lib/xmvc/plugin.rb",
|
92
|
-
"lib/xmvc/settings.rb",
|
93
92
|
"lib/xmvc/stats.rb",
|
94
93
|
"lib/xmvc/test.rb",
|
95
94
|
"lib/xmvc/testserver.ru",
|
96
|
-
"lib/xmvc/ui.rb",
|
97
95
|
"lib/xmvc/update.rb",
|
98
96
|
"test/helper.rb",
|
99
97
|
"test/test_extjs-core.rb",
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 3
|
9
|
+
version: 0.1.3
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Ed Spencer and Chris Scott
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-03-
|
17
|
+
date: 2010-03-13 00:00:00 -05:00
|
18
18
|
default_executable: xmvc
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -145,8 +145,9 @@ files:
|
|
145
145
|
- lib/xmvc/environment.rb
|
146
146
|
- lib/xmvc/generator.rb
|
147
147
|
- lib/xmvc/generators/app.rb
|
148
|
-
- lib/xmvc/generators/
|
148
|
+
- lib/xmvc/generators/boot.rb
|
149
149
|
- lib/xmvc/generators/controller.rb
|
150
|
+
- lib/xmvc/generators/layout.rb
|
150
151
|
- lib/xmvc/generators/model.rb
|
151
152
|
- lib/xmvc/generators/scaffold.rb
|
152
153
|
- lib/xmvc/generators/templates/Controller.js
|
@@ -154,18 +155,15 @@ files:
|
|
154
155
|
- lib/xmvc/generators/templates/ModelSpec.js
|
155
156
|
- lib/xmvc/generators/templates/View.js
|
156
157
|
- lib/xmvc/generators/templates/_Action.js
|
157
|
-
- lib/xmvc/generators/templates/app/config/environment.yml
|
158
|
-
- lib/xmvc/generators/templates/app/config/environments/development.yml
|
159
|
-
- lib/xmvc/generators/templates/app/config/environments/production.yml
|
160
158
|
- lib/xmvc/generators/templates/app/public/app/App.js
|
161
159
|
- lib/xmvc/generators/templates/app/public/app/controllers/application_controller.js
|
162
160
|
- lib/xmvc/generators/templates/app/public/app/controllers/home_controller.js
|
163
161
|
- lib/xmvc/generators/templates/app/public/app/views/home/index.js
|
164
162
|
- lib/xmvc/generators/templates/app/public/app/views/layout/menu.js
|
165
163
|
- lib/xmvc/generators/templates/app/public/config/application.js
|
166
|
-
- lib/xmvc/generators/templates/app/public/config/boot.js
|
167
164
|
- lib/xmvc/generators/templates/app/public/config/database.js
|
168
165
|
- lib/xmvc/generators/templates/app/public/config/environment.json
|
166
|
+
- lib/xmvc/generators/templates/app/public/config/environment.yml
|
169
167
|
- lib/xmvc/generators/templates/app/public/config/environments/development.json
|
170
168
|
- lib/xmvc/generators/templates/app/public/config/environments/production.json
|
171
169
|
- lib/xmvc/generators/templates/app/public/config/routes.js
|
@@ -191,14 +189,14 @@ files:
|
|
191
189
|
- lib/xmvc/generators/templates/app/public/vendor/screw-unit/spec/print_spec.js
|
192
190
|
- lib/xmvc/generators/templates/app/public/vendor/screw-unit/spec/spec_helper.js
|
193
191
|
- lib/xmvc/generators/templates/app/public/vendor/screw-unit/spec/suite.html
|
192
|
+
- lib/xmvc/generators/templates/boot.js
|
193
|
+
- lib/xmvc/generators/templates/layout.html.erb
|
194
194
|
- lib/xmvc/generators/templates/scaffold/ScaffoldController.js
|
195
195
|
- lib/xmvc/generators/view.rb
|
196
196
|
- lib/xmvc/plugin.rb
|
197
|
-
- lib/xmvc/settings.rb
|
198
197
|
- lib/xmvc/stats.rb
|
199
198
|
- lib/xmvc/test.rb
|
200
199
|
- lib/xmvc/testserver.ru
|
201
|
-
- lib/xmvc/ui.rb
|
202
200
|
- lib/xmvc/update.rb
|
203
201
|
- test/helper.rb
|
204
202
|
- test/test_extjs-core.rb
|
data/lib/xmvc/generators/base.rb
DELETED
@@ -1,99 +0,0 @@
|
|
1
|
-
module Xmvc
|
2
|
-
module Generator
|
3
|
-
|
4
|
-
class EnvironmentError < Xmvc::Error; status_code(11) ; end
|
5
|
-
|
6
|
-
class Base
|
7
|
-
|
8
|
-
TEMPLATE_PATH = "#{File.dirname(__FILE__)}/templates"
|
9
|
-
|
10
|
-
def initialize *args
|
11
|
-
@gsubs ||= {}
|
12
|
-
@gsubs['namespace'] = "development" #Xmvc.environment['namespace']
|
13
|
-
end
|
14
|
-
|
15
|
-
protected
|
16
|
-
def ensure_directories_present! *args
|
17
|
-
args.each do |a|
|
18
|
-
path = public_path(a)
|
19
|
-
Dir.mkdir(path) unless File.exists?(path)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def ensure_no_overwrite! *args
|
24
|
-
args.each do |a|
|
25
|
-
path = public_path(a)
|
26
|
-
if File.exists?(path) && !ARGV.include?("--force")
|
27
|
-
raise Xmvc::FileExists.new("File already exists: #{a}")
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
def template(template_filename, destination_filename)
|
33
|
-
#write the file
|
34
|
-
File.open(public_path(destination_filename), 'w') {|f| f.puts(render_template(template_filename))}
|
35
|
-
|
36
|
-
Xmvc.ui.confirm(" Created #{destination_filename}")
|
37
|
-
end
|
38
|
-
|
39
|
-
def render_template(template_filename, gsubs = @gsubs)
|
40
|
-
#grab the template file text
|
41
|
-
template_text = IO.read("#{TEMPLATE_PATH}/#{template_filename}")
|
42
|
-
|
43
|
-
#translate the template file text
|
44
|
-
gsubs.each_pair do |key, value|
|
45
|
-
template_text.gsub!(Regexp.new("<%= @#{key} %>"), value)
|
46
|
-
end
|
47
|
-
|
48
|
-
template_text
|
49
|
-
end
|
50
|
-
|
51
|
-
def include_script html_filename, script_filename, dom_id
|
52
|
-
|
53
|
-
end
|
54
|
-
|
55
|
-
private
|
56
|
-
|
57
|
-
def public_path(f)
|
58
|
-
File.join("public", f)
|
59
|
-
end
|
60
|
-
|
61
|
-
##
|
62
|
-
# write a newly generated controller, model or view to environment.json
|
63
|
-
# Unfortunately, we cannot JSON.parse the entire config/environment.json, since it contains comments
|
64
|
-
# and such. Have to RegExp, pick-out the requested key, and JSON.parse the returned chunk.
|
65
|
-
# Is this Regexp satisfactory?? Could probably be made better.
|
66
|
-
#
|
67
|
-
def to_environment(key, item)
|
68
|
-
Xmvc.ui.warn('Generator::Base#to_environment disabled')
|
69
|
-
return
|
70
|
-
|
71
|
-
re = Regexp.new("\"#{key}\"\s*\:\s*(\\[.*?\\](?!\}))", Regexp::MULTILINE)
|
72
|
-
content = File.read('config/environment.json')
|
73
|
-
m = content.match(re)
|
74
|
-
if m
|
75
|
-
begin
|
76
|
-
items = JSON.parse("#{m[1].strip}")
|
77
|
-
rescue StandardError => e
|
78
|
-
raise EnvironmentError.new("A JSON parsing error occured parsing config/environment.json. Failed to add #{key} to environment.json.")
|
79
|
-
end
|
80
|
-
|
81
|
-
if item.kind_of?(Hash) # <-- it's a view
|
82
|
-
view = items.find {|i| i[item[:package]] }
|
83
|
-
if view
|
84
|
-
view[item[:package]] << item[:filename]
|
85
|
-
else
|
86
|
-
items << { item[:package] => [item[:filename]]}
|
87
|
-
end
|
88
|
-
else
|
89
|
-
items << item unless items.include?(item)
|
90
|
-
end
|
91
|
-
File.open('config/environment.json', "w") do |file|
|
92
|
-
file << content.gsub(re, "\"#{key}\": #{items.to_json}")
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
File without changes
|
File without changes
|
data/lib/xmvc/settings.rb
DELETED
@@ -1,134 +0,0 @@
|
|
1
|
-
module Xmvc
|
2
|
-
module Settings
|
3
|
-
|
4
|
-
class << self
|
5
|
-
|
6
|
-
def dispatch(action, *params)
|
7
|
-
|
8
|
-
end
|
9
|
-
|
10
|
-
def load
|
11
|
-
@settings = YAML.load_file('config/environment.yml')
|
12
|
-
end
|
13
|
-
|
14
|
-
##
|
15
|
-
# write a newly generated controller, model or view to environment.json
|
16
|
-
# Unfortunately, we cannot JSON.parse the entire config/environment.json, since it contains comments
|
17
|
-
# and such. Have to RegExp, pick-out the requested key, and JSON.parse the returned chunk.
|
18
|
-
# Is this Regexp satisfactory?? Could probably be made better.
|
19
|
-
#
|
20
|
-
def add (key, item)
|
21
|
-
key = key.to_s
|
22
|
-
@settings[key] = [] unless @settings[key] && @settings[key].kind_of?(Array)
|
23
|
-
|
24
|
-
unless key == "views"
|
25
|
-
@settings[key] << item
|
26
|
-
else
|
27
|
-
if controller = @settings[key].find {|i| i[item[:package]]}
|
28
|
-
controller[item[:package]] << item[:filename]
|
29
|
-
else
|
30
|
-
@settings[key] << {
|
31
|
-
item[:package] => [
|
32
|
-
item[:filename]
|
33
|
-
]
|
34
|
-
}
|
35
|
-
end
|
36
|
-
end
|
37
|
-
save
|
38
|
-
end
|
39
|
-
|
40
|
-
private
|
41
|
-
|
42
|
-
def save
|
43
|
-
File.open('config/environment.yml', "w") {|file|
|
44
|
-
file << @settings.to_yaml
|
45
|
-
}
|
46
|
-
File.open('public/config/environment.json', "w") {|file|
|
47
|
-
file << @settings.to_json
|
48
|
-
}
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
|
55
|
-
##
|
56
|
-
#
|
57
|
-
# ORIGINAL CODE
|
58
|
-
#
|
59
|
-
#
|
60
|
-
module ExtJS
|
61
|
-
module MVC
|
62
|
-
|
63
|
-
# extracts settings from the config/settings.yml file
|
64
|
-
def self.settings
|
65
|
-
@config ||= YAML.load_file('config/settings.yml')
|
66
|
-
end
|
67
|
-
|
68
|
-
# returns environment settings
|
69
|
-
def self.environment
|
70
|
-
settings['environment']
|
71
|
-
end
|
72
|
-
|
73
|
-
def self.namespace
|
74
|
-
environment["namespace"]
|
75
|
-
end
|
76
|
-
|
77
|
-
def self.show_settings
|
78
|
-
puts environment.inspect
|
79
|
-
end
|
80
|
-
|
81
|
-
def self.application_files_for(environment)
|
82
|
-
files = []
|
83
|
-
|
84
|
-
[
|
85
|
-
environment["plugins"].collect {|o| "vendor/plugins/#{o}/#{o}-all.js"},
|
86
|
-
environment["overrides"].collect {|o| "config/overrides/#{o}.js"},
|
87
|
-
environment["config"].collect {|o| "#{o}.js"},
|
88
|
-
environment["models"].collect {|o| "app/models/#{o}.js"},
|
89
|
-
environment["controllers"].collect {|o| "app/controllers/#{o}Controller.js"},
|
90
|
-
environment["views"].collect {|o| o.collect {|dir, fileList| fileList.collect {|fileName| "app/views/#{dir}/#{fileName}.js"}.flatten}}.flatten
|
91
|
-
].each {|f| files.concat(f)}
|
92
|
-
|
93
|
-
files
|
94
|
-
end
|
95
|
-
|
96
|
-
def self.css_files_for(environment)
|
97
|
-
environment['stylesheets'].collect {|s| "public/stylesheets/#{s}.css"}
|
98
|
-
end
|
99
|
-
|
100
|
-
def self.mvc_development_environment
|
101
|
-
environment = {}
|
102
|
-
|
103
|
-
default = JSON::Parser.new(File.read('public/config/environment.json')).parse()
|
104
|
-
development = JSON::Parser.new(File.read('public/config/environments/development.json')).parse()
|
105
|
-
|
106
|
-
environment.merge!(default)
|
107
|
-
environment.merge!(development)
|
108
|
-
|
109
|
-
environment
|
110
|
-
end
|
111
|
-
|
112
|
-
def self.mvc_production_environment
|
113
|
-
environment = {
|
114
|
-
'pluginsDir' => '../vendor/plugins',
|
115
|
-
'libDir' => '../lib',
|
116
|
-
'configDir' => '../config',
|
117
|
-
'overridesDir' => '../config/overrides',
|
118
|
-
'appDir' => '../app',
|
119
|
-
'vendor' => ['mvc'],
|
120
|
-
'mvcFilename' => 'ext-mvc-all-min',
|
121
|
-
'config' => ['app/App', 'config/routes'],
|
122
|
-
'stylesheets' => ['ext-all']
|
123
|
-
}
|
124
|
-
|
125
|
-
default = JSON::Parser.new(File.read('public/config/environment.json')).parse()
|
126
|
-
production = JSON::Parser.new(File.read('public/config/environments/production.json')).parse()
|
127
|
-
|
128
|
-
environment.merge!(default)
|
129
|
-
environment.merge!(production)
|
130
|
-
|
131
|
-
environment
|
132
|
-
end
|
133
|
-
end
|
134
|
-
end
|