ymdp 0.1.3.2 → 0.1.4
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/lib/ymdp.rb +1 -1
- data/lib/ymdp/commands/build.rb +14 -0
- data/lib/ymdp/compiler/base.rb +206 -0
- data/lib/ymdp/compiler/domains.rb +103 -0
- data/lib/ymdp/{support → compiler}/git_helper.rb +0 -0
- data/lib/ymdp/compiler/options.rb +48 -0
- data/lib/ymdp/compiler/template.rb +358 -304
- data/lib/ymdp/configuration/config.rb +39 -0
- data/lib/ymdp/{support → processor}/form_post.rb +1 -1
- data/lib/ymdp/processor/validator.rb +2 -1
- data/lib/ymdp/{support → processor}/w3c.rb +0 -0
- data/lib/ymdp/support/file.rb +25 -1
- data/spec/compiler_spec.rb +154 -0
- data/spec/compiler_template_spec.rb +104 -0
- data/spec/data/config/servers.yml +9 -8
- data/spec/data/config/servers.yml.example +9 -8
- data/spec/domains_spec.rb +101 -0
- data/spec/spec_helper.rb +3 -1
- data/spec/stubs.rb +42 -0
- data/ymdp.gemspec +17 -6
- metadata +16 -5
- data/lib/ymdp/compiler/compiler.rb +0 -278
@@ -2,6 +2,45 @@ require 'serenity'
|
|
2
2
|
|
3
3
|
module YMDP
|
4
4
|
module Configuration
|
5
|
+
module Helpers
|
6
|
+
def self.included(klass)
|
7
|
+
klass.send :extend, ClassMethods
|
8
|
+
klass.send :include, InstanceMethods
|
9
|
+
end
|
10
|
+
|
11
|
+
module ClassMethods
|
12
|
+
# Class Methods to handle global stuff like base path and server settings
|
13
|
+
|
14
|
+
def self.base_path= base_path
|
15
|
+
@@base_path = base_path
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.base_path
|
19
|
+
@@base_path
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.servers= servers
|
23
|
+
@@servers = servers
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.servers
|
27
|
+
@@servers
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
module InstanceMethods
|
32
|
+
# Instance Methods to access global stuff like base path and server settings
|
33
|
+
|
34
|
+
def servers
|
35
|
+
send :class_attribute_get, "#@@servers"
|
36
|
+
end
|
37
|
+
|
38
|
+
def base_path
|
39
|
+
@@base_path
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
5
44
|
class Base
|
6
45
|
attr_accessor :base
|
7
46
|
|
File without changes
|
data/lib/ymdp/support/file.rb
CHANGED
@@ -1,5 +1,17 @@
|
|
1
1
|
module YMDP
|
2
2
|
module FileSupport
|
3
|
+
# Concatenate together the contents of the input_path into the output_file.
|
4
|
+
#
|
5
|
+
def concat_files(input_path, output_file)
|
6
|
+
File.open(output_file, "a") do |output|
|
7
|
+
Dir[input_path].each do |path|
|
8
|
+
File.open(path) do |f|
|
9
|
+
output.puts f.read
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
3
15
|
def confirm_overwrite(path)
|
4
16
|
if File.exists?(path)
|
5
17
|
$stdout.puts "File exists: #{File.expand_path(path)}"
|
@@ -51,4 +63,16 @@ module YMDP
|
|
51
63
|
output
|
52
64
|
end
|
53
65
|
end
|
54
|
-
end
|
66
|
+
end
|
67
|
+
|
68
|
+
class F
|
69
|
+
extend YMDP::FileSupport
|
70
|
+
|
71
|
+
def self.execute(command, params={})
|
72
|
+
if params[:return]
|
73
|
+
`#{command}`
|
74
|
+
else
|
75
|
+
system command
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,154 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
require 'compiler/base'
|
4
|
+
require 'compiler/template'
|
5
|
+
|
6
|
+
YMDP_ENV = "build"
|
7
|
+
|
8
|
+
describe "Compiler" do
|
9
|
+
before(:each) do
|
10
|
+
Object.send(:remove_const, :CONFIG)
|
11
|
+
CONFIG = mock('config').as_null_object
|
12
|
+
stub_screen_io
|
13
|
+
stub_file_io
|
14
|
+
stub_file_utils
|
15
|
+
|
16
|
+
@domain = 'staging'
|
17
|
+
@git_hash = 'asdfh23rh2fas'
|
18
|
+
@base_path = "."
|
19
|
+
|
20
|
+
@compiler = YMDP::Compiler::Base.new(@domain, @git_hash, :base_path => @base_path)
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "instantiation" do
|
24
|
+
it "should instantiate" do
|
25
|
+
@compiler.should_not be_nil
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should set domain" do
|
29
|
+
@compiler.domain.should == @domain
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should set git_hash" do
|
33
|
+
@compiler.git_hash.should == @git_hash
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "process" do
|
38
|
+
before(:each) do
|
39
|
+
YMDP::Base.stub!(:supported_languages).and_return([])
|
40
|
+
|
41
|
+
@view_template = mock('view_template').as_null_object
|
42
|
+
YMDP::Compiler::Template::View.stub!(:new).and_return(@view_template)
|
43
|
+
@js_template = mock('js_template').as_null_object
|
44
|
+
YMDP::Compiler::Template::JavaScript.stub!(:new).and_return(@js_template)
|
45
|
+
@yrb_template = mock('yrb_template').as_null_object
|
46
|
+
YMDP::Compiler::Template::YRB.stub!(:new).and_return(@yrb_template)
|
47
|
+
|
48
|
+
Dir.stub!(:[]).and_return([])
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should see if server directory exists" do
|
52
|
+
File.should_receive(:exists?).with("#{@base_path}/servers/#{@domain}")
|
53
|
+
@compiler.process_all
|
54
|
+
end
|
55
|
+
|
56
|
+
describe "translations" do
|
57
|
+
before(:each) do
|
58
|
+
@supported_languages = ["en-US", "de-DE"]
|
59
|
+
YMDP::Base.stub!(:supported_languages).and_return(@supported_languages)
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should act on the list of supported languages" do
|
63
|
+
@supported_languages.each do |lang|
|
64
|
+
F.should_receive(:concat_files).with("#{@base_path}/app/assets/yrb/#{lang}/*", /keys_#{lang}\.pres/)
|
65
|
+
end
|
66
|
+
@compiler.process_all
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should instantiate a new YRB template" do
|
70
|
+
@supported_languages.each do |lang|
|
71
|
+
YMDP::Compiler::Template::YRB.should_receive(:new) do |options|
|
72
|
+
options[:file].should =~ /keys_#{lang}\.pres/
|
73
|
+
end
|
74
|
+
end
|
75
|
+
@compiler.process_all
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should build the new YRB template" do
|
79
|
+
@supported_languages.each do |lang|
|
80
|
+
@yrb_template.should_receive(:build)
|
81
|
+
end
|
82
|
+
@compiler.process_all
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should validate the new YRB template" do
|
86
|
+
CONFIG.stub!(:validate_json_assets?).and_return(true)
|
87
|
+
@supported_languages.each do |lang|
|
88
|
+
@yrb_template.should_receive(:validate)
|
89
|
+
end
|
90
|
+
@compiler.process_all
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should validate the new YRB template" do
|
94
|
+
CONFIG.stub!(:validate_json_assets?).and_return(false)
|
95
|
+
@yrb_template.should_not_receive(:validate)
|
96
|
+
@compiler.process_all
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
describe "views" do
|
101
|
+
describe "haml" do
|
102
|
+
before(:each) do
|
103
|
+
@files = ["./app/views/view.html.haml"]
|
104
|
+
Dir.stub!(:[]).with("./app/views/**/*").and_return(@files)
|
105
|
+
end
|
106
|
+
|
107
|
+
it "should run on all views in the path" do
|
108
|
+
Dir.should_receive(:[]).with("./app/views/**/*").and_return(@files)
|
109
|
+
@compiler.process_all
|
110
|
+
end
|
111
|
+
|
112
|
+
it "should create view template class for haml" do
|
113
|
+
YMDP::Compiler::Template::View.should_receive(:new).with(hash_including(:file => @files.first)).and_return(@view_template)
|
114
|
+
@compiler.process_all
|
115
|
+
end
|
116
|
+
|
117
|
+
it "should build haml template" do
|
118
|
+
YMDP::Compiler::Template::View.stub!(:new).with(hash_including(:file => @files.first)).and_return(@view_template)
|
119
|
+
@view_template.should_receive(:build)
|
120
|
+
@compiler.process_all
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
describe "erb" do
|
125
|
+
before(:each) do
|
126
|
+
@files = ["./app/views/view.html.erb"]
|
127
|
+
Dir.stub!(:[]).with("./app/views/**/*").and_return(@files)
|
128
|
+
end
|
129
|
+
|
130
|
+
it "should run on all views in the path" do
|
131
|
+
Dir.should_receive(:[]).with("./app/views/**/*").and_return(@files)
|
132
|
+
@compiler.process_all
|
133
|
+
end
|
134
|
+
|
135
|
+
it "should create view template class for haml" do
|
136
|
+
YMDP::Compiler::Template::View.should_receive(:new).with(hash_including(:file => @files.first)).and_return(@view_template)
|
137
|
+
@compiler.process_all
|
138
|
+
end
|
139
|
+
|
140
|
+
it "should build haml template" do
|
141
|
+
YMDP::Compiler::Template::View.stub!(:new).with(hash_including(:file => @files.first)).and_return(@view_template)
|
142
|
+
@view_template.should_receive(:build)
|
143
|
+
@compiler.process_all
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
it "should run on all views in the path" do
|
149
|
+
files = ["./app/assets/javascripts/view.js"]
|
150
|
+
Dir.should_receive(:[]).with("./app/assets/**/*").and_return(files)
|
151
|
+
@compiler.process_all
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
require 'compiler/base'
|
4
|
+
require 'compiler/template'
|
5
|
+
|
6
|
+
|
7
|
+
describe "Compiler" do
|
8
|
+
before(:each) do
|
9
|
+
Object.send(:remove_const, :YMDP_ENV)
|
10
|
+
YMDP_ENV = "build"
|
11
|
+
|
12
|
+
Object.send(:remove_const, :CONFIG)
|
13
|
+
CONFIG = mock('config').as_null_object
|
14
|
+
|
15
|
+
Application.stub!(:current_view=)
|
16
|
+
|
17
|
+
stub_screen_io
|
18
|
+
stub_file_io
|
19
|
+
stub_file_utils
|
20
|
+
stub_yaml
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "view" do
|
24
|
+
before(:each) do
|
25
|
+
@domain = "staging"
|
26
|
+
@filename = "filename.html.haml"
|
27
|
+
@git_hash = "asjkhfasjkfhjk"
|
28
|
+
@message = "This is a commit message."
|
29
|
+
|
30
|
+
@params = {
|
31
|
+
:verbose => false,
|
32
|
+
:domain => @domain,
|
33
|
+
:file => @filename,
|
34
|
+
:git_hash => @git_hash,
|
35
|
+
:message => @message
|
36
|
+
}
|
37
|
+
@content_variables = {
|
38
|
+
"version" => "0.1.0",
|
39
|
+
"sprint_name" => "Gorgonzola"
|
40
|
+
}
|
41
|
+
YAML.stub!(:load_file).with(/content\.yml$/).and_return(@content_variables)
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
@servers = {
|
46
|
+
"staging" => {
|
47
|
+
"server" => "staging",
|
48
|
+
"application_id" => "12345",
|
49
|
+
"assets_id" => "abcdefg_1"
|
50
|
+
},
|
51
|
+
|
52
|
+
"production" => {
|
53
|
+
"server" => "www",
|
54
|
+
"application_id" => "678910",
|
55
|
+
"assets_id" => "hijklmno_1"
|
56
|
+
}
|
57
|
+
}
|
58
|
+
@servers.stub!(:servers).and_return(@servers)
|
59
|
+
@base_path = "."
|
60
|
+
|
61
|
+
YMDP::Compiler::Template::Base.servers = @servers
|
62
|
+
YMDP::Compiler::Template::Base.base_path = @base_path
|
63
|
+
|
64
|
+
@view_template = YMDP::Compiler::Template::View.new(@params)
|
65
|
+
end
|
66
|
+
|
67
|
+
describe "instantiation" do
|
68
|
+
it "should instantiate" do
|
69
|
+
@view_template.should_not be_nil
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should set verbose" do
|
73
|
+
@view_template.verbose?.should be_false
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should set domain" do
|
77
|
+
@view_template.domain.should == @domain
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should set server" do
|
81
|
+
@view_template.server.should == @servers["server"]
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should set file" do
|
85
|
+
@view_template.file.should == @filename
|
86
|
+
end
|
87
|
+
|
88
|
+
it "should get content variables from yml file" do
|
89
|
+
YAML.should_receive(:load_file).with(/content\.yml$/)
|
90
|
+
@view_template = YMDP::Compiler::Template::View.new(@params)
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should set content variables" do
|
94
|
+
@view_template.instance_variable_get("@version").should == @content_variables["version"]
|
95
|
+
@view_template.instance_variable_get("@sprint_name").should == @content_variables["sprint_name"]
|
96
|
+
end
|
97
|
+
|
98
|
+
it "should set Application.current_view" do
|
99
|
+
Application.should_receive(:current_view=).with("filename")
|
100
|
+
@view_template = YMDP::Compiler::Template::View.new(@params)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -1,9 +1,10 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
servers:
|
2
|
+
development:
|
3
|
+
server: alpha
|
4
|
+
application_id: abcdefghijk
|
5
|
+
assets_id: abcdefghijk_1
|
5
6
|
|
6
|
-
staging:
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
staging:
|
8
|
+
server: staging
|
9
|
+
application_id: abcdefghijk
|
10
|
+
assets_id: abcdefghijk_1
|
@@ -1,9 +1,10 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
servers:
|
2
|
+
development:
|
3
|
+
server: alpha
|
4
|
+
application_id: abcdefghijk
|
5
|
+
assets_id: abcdefghijk_1
|
5
6
|
|
6
|
-
staging:
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
staging:
|
8
|
+
server: staging
|
9
|
+
application_id: abcdefghijk
|
10
|
+
assets_id: abcdefghijk_1
|
@@ -0,0 +1,101 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
require 'compiler/domains'
|
4
|
+
|
5
|
+
describe "Domains" do
|
6
|
+
before(:each) do
|
7
|
+
stub_git_helper
|
8
|
+
|
9
|
+
@servers = {
|
10
|
+
"staging" => {
|
11
|
+
"server" => "staging",
|
12
|
+
"application_id" => "12345",
|
13
|
+
"assets_id" => "abcdefg_1"
|
14
|
+
},
|
15
|
+
|
16
|
+
"production" => {
|
17
|
+
"server" => "www",
|
18
|
+
"application_id" => "678910",
|
19
|
+
"assets_id" => "hijklmno_1"
|
20
|
+
}
|
21
|
+
}
|
22
|
+
@servers.stub!(:servers).and_return(@servers)
|
23
|
+
|
24
|
+
@options = {
|
25
|
+
:commit => true,
|
26
|
+
:branch => "master",
|
27
|
+
:message => "Commit message"
|
28
|
+
}
|
29
|
+
@base_path = "."
|
30
|
+
|
31
|
+
YMDP::Compiler::Domains.base_path = @base_path
|
32
|
+
YMDP::Compiler::Domains.servers = @servers
|
33
|
+
|
34
|
+
@domains = YMDP::Compiler::Domains.new(@options)
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "instantiation" do
|
38
|
+
it "should instantiate" do
|
39
|
+
@domains.should_not be_nil
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should set options" do
|
43
|
+
@domains.options.should == @options
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should set message" do
|
47
|
+
@domains.message.should == @options[:message]
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should set servers" do
|
51
|
+
@domains.servers.should == @servers
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should set base_path" do
|
55
|
+
@domains.base_path.should == @base_path
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should set domains" do
|
59
|
+
@domains = YMDP::Compiler::Domains.new(@options.merge({:domain => "staging"}))
|
60
|
+
@domains.domains.should == ["staging"]
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should not commit" do
|
64
|
+
@git_helper.should_not_receive(:do_commit)
|
65
|
+
@domains = YMDP::Compiler::Domains.new(@options.merge({:commit => false}))
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should commit" do
|
69
|
+
@git_helper.should_receive(:do_commit).with(@options[:message])
|
70
|
+
@domains = YMDP::Compiler::Domains.new(@options)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe "compile" do
|
75
|
+
before(:each) do
|
76
|
+
stub_screen_io
|
77
|
+
stub_file_io("")
|
78
|
+
stub_erb("")
|
79
|
+
stub_timer
|
80
|
+
|
81
|
+
@compiler = mock('compiler').as_null_object
|
82
|
+
YMDP::Compiler::Base.stub!(:new).and_return(@compiler)
|
83
|
+
end
|
84
|
+
|
85
|
+
describe "process domains" do
|
86
|
+
it "should create a new compiler" do
|
87
|
+
@servers.keys.each do |server|
|
88
|
+
YMDP::Compiler::Base.should_receive(:new).with(anything, anything, anything).and_return(@compiler)
|
89
|
+
end
|
90
|
+
@domains.compile
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should process the views" do
|
94
|
+
@servers.keys.each do |server|
|
95
|
+
@compiler.should_receive(:process_all)
|
96
|
+
end
|
97
|
+
@domains.compile
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|