ymdp 0.1.4 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (94) hide show
  1. data/Rakefile +1 -0
  2. data/VERSION +1 -1
  3. data/lib/ymdp/application.rb +22 -0
  4. data/lib/ymdp/application_view.rb +312 -0
  5. data/lib/ymdp/base.rb +119 -0
  6. data/lib/ymdp/commands/build.rb +0 -6
  7. data/lib/ymdp/compiler/base.rb +12 -10
  8. data/lib/ymdp/compiler/domains.rb +8 -34
  9. data/lib/ymdp/compiler/template.rb +58 -85
  10. data/lib/ymdp/configuration/config.rb +70 -28
  11. data/lib/ymdp/configuration/constants.rb +17 -3
  12. data/lib/ymdp/processor/form_post.rb +5 -1
  13. data/lib/ymdp/support/file.rb +29 -11
  14. data/lib/ymdp/tasks/keys.rake +13 -13
  15. data/lib/ymdp/tasks/ymdp.rake +4 -4
  16. data/spec/application_spec.rb +29 -0
  17. data/spec/application_view_spec.rb +5 -0
  18. data/spec/compiler_spec.rb +3 -3
  19. data/spec/compiler_template_spec.rb +26 -54
  20. data/spec/data/app/views/layouts/application.html.haml +2 -0
  21. data/spec/data/config/config.yml +1 -0
  22. data/spec/data/config/constants.rb +3 -7
  23. data/spec/data/script/destroy +2 -2
  24. data/spec/data/script/langs +1 -3
  25. data/spec/default_settings.rb +42 -0
  26. data/spec/domains_spec.rb +3 -22
  27. data/spec/spec_helper.rb +3 -0
  28. data/spec/stubs.rb +11 -0
  29. data/spec/ymdp_base_spec.rb +125 -0
  30. data/test.rb +46 -0
  31. data/ymdp.gemspec +15 -65
  32. metadata +14 -64
  33. data/lib/new_application/.base +0 -11
  34. data/lib/new_application/Gemfile +0 -13
  35. data/lib/new_application/Rakefile +0 -3
  36. data/lib/new_application/app/.gitignore +0 -1
  37. data/lib/new_application/app/assets/images/lightbox/lightbox_bg.png +0 -0
  38. data/lib/new_application/app/assets/javascripts/OpenMailIntl.js +0 -291
  39. data/lib/new_application/app/assets/javascripts/controls.js +0 -965
  40. data/lib/new_application/app/assets/javascripts/date.js +0 -104
  41. data/lib/new_application/app/assets/javascripts/dragdrop.js +0 -974
  42. data/lib/new_application/app/assets/javascripts/effects.js +0 -1123
  43. data/lib/new_application/app/assets/javascripts/lowpro.js +0 -320
  44. data/lib/new_application/app/assets/javascripts/prototype.js +0 -4874
  45. data/lib/new_application/app/assets/javascripts/scriptaculous.js +0 -68
  46. data/lib/new_application/app/assets/yrb/en-US/application_en-US.pres +0 -7
  47. data/lib/new_application/app/helpers/application_helper.rb +0 -3
  48. data/lib/new_application/app/javascripts/application.js +0 -580
  49. data/lib/new_application/app/javascripts/debug.js +0 -138
  50. data/lib/new_application/app/javascripts/flash.js +0 -96
  51. data/lib/new_application/app/javascripts/header.js +0 -13
  52. data/lib/new_application/app/javascripts/help.js +0 -76
  53. data/lib/new_application/app/javascripts/i18n.js +0 -235
  54. data/lib/new_application/app/javascripts/launcher.js +0 -159
  55. data/lib/new_application/app/javascripts/logger.js +0 -61
  56. data/lib/new_application/app/javascripts/tag_helper.js +0 -178
  57. data/lib/new_application/app/stylesheets/application.css +0 -0
  58. data/lib/new_application/app/stylesheets/ie.css +0 -0
  59. data/lib/new_application/app/stylesheets/ie6.css +0 -0
  60. data/lib/new_application/app/stylesheets/ie7.css +0 -0
  61. data/lib/new_application/app/stylesheets/ie8.css +0 -0
  62. data/lib/new_application/app/stylesheets/lightbox.css +0 -30
  63. data/lib/new_application/app/stylesheets/non_ie.css +0 -0
  64. data/lib/new_application/app/views/layouts/application.html.haml +0 -35
  65. data/lib/new_application/app/views/shared/_error.html.haml +0 -8
  66. data/lib/new_application/app/views/shared/_flash.html.haml +0 -2
  67. data/lib/new_application/app/views/shared/_javascripts.html.haml +0 -22
  68. data/lib/new_application/app/views/shared/_loading.html.haml +0 -13
  69. data/lib/new_application/app/views/shared/_stylesheets.html.haml +0 -23
  70. data/lib/new_application/config/categories.yml +0 -6
  71. data/lib/new_application/config/config.yml.example +0 -30
  72. data/lib/new_application/config/constants.rb +0 -54
  73. data/lib/new_application/config/servers.yml.example +0 -9
  74. data/lib/new_application/lib/init.rb +0 -13
  75. data/lib/new_application/lib/tasks/environment.rake +0 -4
  76. data/lib/new_application/lib/tasks/keys.rake +0 -3
  77. data/lib/new_application/lib/tasks/setup.rake +0 -13
  78. data/lib/new_application/lib/tasks/ymdp.rake +0 -4
  79. data/lib/new_application/script/build +0 -9
  80. data/lib/new_application/script/config +0 -13
  81. data/lib/new_application/script/destroy +0 -18
  82. data/lib/new_application/script/generate +0 -4
  83. data/lib/new_application/script/gitrm +0 -17
  84. data/lib/new_application/script/growl +0 -6
  85. data/lib/new_application/script/images +0 -48
  86. data/lib/new_application/script/jslint.js +0 -5072
  87. data/lib/new_application/script/langs +0 -31
  88. data/lib/new_application/script/translate +0 -5
  89. data/lib/new_application/script/ymdt +0 -1895
  90. data/lib/new_application/script/ymdt.old +0 -1890
  91. data/lib/new_application/script/yuicompressor-2.4.2.jar +0 -0
  92. data/lib/new_application/ymdp +0 -8
  93. data/lib/ymdp/processor/processor.rb +0 -132
  94. data/lib/ymdp/ymdp.rb +0 -208
@@ -1,5 +1,19 @@
1
- YMDP_ROOT = BASE_PATH unless defined?(YMDP_ROOT)
2
- TMP_DIR = TMP_PATH unless defined?(TMP_DIR)
3
-
4
1
  CONFIG = YMDP::Configuration::Config.new unless defined?(CONFIG)
5
2
  SERVERS = YMDP::Configuration::Servers.new unless defined?(SERVERS)
3
+
4
+ @content_variables = YAML.load_file("#{CONFIG_PATH}/content.yml")
5
+
6
+ YMDP::Base.configure do |config|
7
+ config.username = CONFIG["username"]
8
+ config.password = CONFIG["password"]
9
+ config.default_server = CONFIG["default_server"]
10
+ config.growl = CONFIG["growl"]
11
+ config.verbose = CONFIG["verbose"]
12
+ config.compress = CONFIG["compress"]
13
+ config.validate = CONFIG["validate"]
14
+
15
+ config.add_path(:base_path, BASE_PATH)
16
+ config.servers = SERVERS
17
+
18
+ config.content_variables = @content_variables
19
+ end
@@ -3,7 +3,11 @@
3
3
  require 'rubygems'
4
4
  require 'mime/types'
5
5
  require 'net/http'
6
- require 'CGI'
6
+ begin
7
+ require 'CGI'
8
+ rescue StandardError => e
9
+ puts e.message
10
+ end
7
11
 
8
12
  class FormField
9
13
  attr_accessor :name, :value
@@ -1,17 +1,23 @@
1
1
  module YMDP
2
+ # Some useful methods that make working with files easier.
3
+ #
2
4
  module FileSupport
3
- # Concatenate together the contents of the input_path into the output_file.
5
+ # Concatenates together the contents of all the files in the <tt>source_path</tt>
6
+ # into the <tt>destination_path</tt>.
4
7
  #
5
- def concat_files(input_path, output_file)
6
- File.open(output_file, "a") do |output|
7
- Dir[input_path].each do |path|
8
+ def concat_files(source_path, destination_path)
9
+ File.open(destination_path, "a") do |output|
10
+ Dir[source_path].each do |path|
8
11
  File.open(path) do |f|
9
12
  output.puts f.read
10
13
  end
11
14
  end
12
- end
15
+ end
13
16
  end
14
17
 
18
+ # If the file at <tt>path</tt> exists, prompt the user to overwrite it. If the file doesn't
19
+ # exist, return true.
20
+ #
15
21
  def confirm_overwrite(path)
16
22
  if File.exists?(path)
17
23
  $stdout.puts "File exists: #{File.expand_path(path)}"
@@ -24,23 +30,29 @@ module YMDP
24
30
  end
25
31
  end
26
32
 
27
- # friendlier display of paths
33
+ # Parses out the <tt>BASE_PATH</tt> constant from filenames to display them in a
34
+ # friendlier way.
35
+ #
36
+ # TODO: Refactor this so it doesn't use a constant.
37
+ #
28
38
  def display_path(path)
29
39
  path = File.expand_path(path)
30
40
  path.gsub(BASE_PATH, "")
31
41
  end
32
42
 
33
- # saves the output string to the filename given
43
+ # Saves the <tt>output</tt> string to the <tt>destination_path</tt> given
34
44
  #
35
- def save_to_file(output, filename)
36
- unless File.exists?(filename)
37
- File.open(filename, "w") do |w|
45
+ def save_to_file(output, destination_path)
46
+ unless File.exists?(destination_path)
47
+ File.open(destination_path, "w") do |w|
38
48
  w.write(output)
39
49
  end
40
50
  end
41
51
  end
42
52
 
43
- # given a path and line number, returns the line and two lines previous
53
+ # Given a <tt>path</tt> and <tt>line_number</tt>, returns the line and two lines previous
54
+ #
55
+ # Used for displaying validation errors.
44
56
  #
45
57
  def get_line_from_file(path, line_number)
46
58
  line_number = line_number.to_i
@@ -65,9 +77,15 @@ module YMDP
65
77
  end
66
78
  end
67
79
 
80
+ # Provide a wrapper around system calls so they can be mocked in tests.
81
+ #
68
82
  class F
69
83
  extend YMDP::FileSupport
70
84
 
85
+ # Execute a system command. If the parameter <tt>:return</tt> is true, execute the command
86
+ # with the backtick (`) command and return the results. Otherwise, just execute the command
87
+ # and let the output go to the screen.
88
+ #
71
89
  def self.execute(command, params={})
72
90
  if params[:return]
73
91
  `#{command}`
@@ -5,7 +5,7 @@ require 'translator/base'
5
5
  @key = ENV["key"] || ""
6
6
  @key = @key.upcase
7
7
 
8
- ASSETS_ROOT = "#{YMDP_ROOT}/app/assets"
8
+ ASSETS_ROOT = "#{BASE_PATH}/app/assets"
9
9
  YRB_ROOT = "#{ASSETS_ROOT}/yrb"
10
10
 
11
11
  namespace :keys do
@@ -35,7 +35,7 @@ namespace :keys do
35
35
  end
36
36
 
37
37
  task :combine do
38
- system "rm #{TMP_DIR}/*"
38
+ system "rm #{TMP_PATH}/*"
39
39
  each_locale do |path|
40
40
  puts path
41
41
  filename = path.split("/").last
@@ -45,20 +45,20 @@ namespace :keys do
45
45
  end
46
46
 
47
47
  File.open(path, "r") do |f|
48
- File.open("#{TMP_DIR}/keys_#{lang}.pres", "a") do |tmp|
48
+ File.open("#{TMP_PATH}/keys_#{lang}.pres", "a") do |tmp|
49
49
  tmp.write(f.read)
50
50
  end
51
51
  end
52
52
  end
53
53
 
54
54
  system "rm -rf #{YRB_ROOT}/*"
55
- system "cp #{TMP_DIR}/* #{YRB_ROOT}"
55
+ system "cp #{TMP_PATH}/* #{YRB_ROOT}"
56
56
 
57
- system "rm #{TMP_DIR}/*"
57
+ system "rm #{TMP_PATH}/*"
58
58
  end
59
59
 
60
60
  task :destroy do
61
- system "rm #{TMP_DIR}/*"
61
+ system "rm #{TMP_PATH}/*"
62
62
 
63
63
  raise "Must define a key with 'key='" if @key == ""
64
64
 
@@ -72,7 +72,7 @@ namespace :keys do
72
72
  line
73
73
  end
74
74
 
75
- system "rm #{TMP_DIR}/*"
75
+ system "rm #{TMP_PATH}/*"
76
76
  end
77
77
 
78
78
  desc "Translate any new keys into non-US languages"
@@ -81,7 +81,7 @@ namespace :keys do
81
81
  end
82
82
 
83
83
  task :rename do
84
- system "rm #{TMP_DIR}/*"
84
+ system "rm #{TMP_PATH}/*"
85
85
 
86
86
  @to = ENV["to"] || ""
87
87
  @to = @to.upcase
@@ -99,7 +99,7 @@ namespace :keys do
99
99
  line
100
100
  end
101
101
 
102
- system "rm #{TMP_DIR}/*"
102
+ system "rm #{TMP_PATH}/*"
103
103
  end
104
104
 
105
105
  # task :unused do
@@ -169,14 +169,14 @@ def change_keys
169
169
  puts path
170
170
  filename = path.split("/").last
171
171
  File.open(path, "r") do |f|
172
- File.open("#{TMP_DIR}/#{filename}", "w") do |tmp|
172
+ File.open("#{TMP_PATH}/#{filename}", "w") do |tmp|
173
173
  f.readlines.each do |line|
174
174
  new_line = yield line
175
175
  tmp.write new_line
176
176
  end
177
177
  end
178
178
  end
179
- system "cp #{TMP_DIR}/#{filename} #{path}"
179
+ system "cp #{TMP_PATH}/#{filename} #{path}"
180
180
  end
181
181
  end
182
182
 
@@ -189,14 +189,14 @@ def change_keys_with_lang
189
189
  lang = $1
190
190
  end
191
191
  File.open(path, "r") do |f|
192
- File.open("#{TMP_DIR}/#{filename}", "w") do |tmp|
192
+ File.open("#{TMP_PATH}/#{filename}", "w") do |tmp|
193
193
  f.readlines.each do |line|
194
194
  new_line = yield line, lang, filename
195
195
  tmp.write new_line
196
196
  end
197
197
  end
198
198
  end
199
- system "cp #{TMP_DIR}/#{filename} #{path}"
199
+ system "cp #{TMP_PATH}/#{filename} #{path}"
200
200
  end
201
201
  end
202
202
 
@@ -8,7 +8,7 @@ rescue
8
8
  CATEGORIES = {} unless defined?(CATEGORIES)
9
9
  end
10
10
 
11
- Dir.mkdir(TMP_DIR) rescue Errno::EEXIST
11
+ Dir.mkdir(TMP_PATH) rescue Errno::EEXIST
12
12
 
13
13
  def set_application_variables(application)
14
14
  @application = application
@@ -287,8 +287,8 @@ namespace :validate do
287
287
  desc "Validates all HTML"
288
288
  task :html do
289
289
  puts "\nValidating HTML in #{@application}..."
290
- `rm -rf #{TMP_DIR}`
291
- Dir.mkdir(TMP_DIR) rescue Errno::EEXIST
290
+ `rm -rf #{TMP_PATH}`
291
+ Dir.mkdir(TMP_PATH) rescue Errno::EEXIST
292
292
  Dir["./servers/#{@application}/views/*"].each do |filename|
293
293
  YMDP::Validator::HTML.validate(filename) if filename =~ /#{@path}/
294
294
  end
@@ -491,7 +491,7 @@ def validated_embedded_js(path)
491
491
  Hpricot(f)
492
492
  }
493
493
 
494
- js_fragment_path = TMP_DIR + "/#{File.basename(path)}_js_fragment"
494
+ js_fragment_path = TMP_PATH + "/#{File.basename(path)}_js_fragment"
495
495
 
496
496
  File.open(js_fragment_path,'w') do |f|
497
497
  (doc / "script").each { |js| f.puts js.inner_html + "\n\n" }
@@ -0,0 +1,29 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe Application do
4
+ describe "set current view" do
5
+ it "should set current view" do
6
+ Application.current_view = "staging"
7
+ Application.current_view.should == "staging"
8
+ end
9
+ end
10
+
11
+ describe "current_view?" do
12
+ it "should be true" do
13
+ Application.current_view = "staging"
14
+ Application.current_view?("staging")
15
+ end
16
+
17
+ it "should be false" do
18
+ Application.current_view = "staging"
19
+ Application.current_view?("funk")
20
+ end
21
+ end
22
+
23
+ describe "return current view" do
24
+ it "should return current view" do
25
+ Application.current_view = "staging"
26
+ Application.current_view.should == "staging"
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,5 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "ApplicationView" do
4
+
5
+ end
@@ -17,7 +17,7 @@ describe "Compiler" do
17
17
  @git_hash = 'asdfh23rh2fas'
18
18
  @base_path = "."
19
19
 
20
- @compiler = YMDP::Compiler::Base.new(@domain, @git_hash, :base_path => @base_path)
20
+ @compiler = YMDP::Compiler::Base.new(@domain, @git_hash, :base_path => @base_path, :server => "staging")
21
21
  end
22
22
 
23
23
  describe "instantiation" do
@@ -36,7 +36,7 @@ describe "Compiler" do
36
36
 
37
37
  describe "process" do
38
38
  before(:each) do
39
- YMDP::Base.stub!(:supported_languages).and_return([])
39
+ YMDP::ApplicationView.stub!(:supported_languages).and_return([])
40
40
 
41
41
  @view_template = mock('view_template').as_null_object
42
42
  YMDP::Compiler::Template::View.stub!(:new).and_return(@view_template)
@@ -56,7 +56,7 @@ describe "Compiler" do
56
56
  describe "translations" do
57
57
  before(:each) do
58
58
  @supported_languages = ["en-US", "de-DE"]
59
- YMDP::Base.stub!(:supported_languages).and_return(@supported_languages)
59
+ YMDP::ApplicationView.stub!(:supported_languages).and_return(@supported_languages)
60
60
  end
61
61
 
62
62
  it "should act on the list of supported languages" do
@@ -6,62 +6,31 @@ require 'compiler/template'
6
6
 
7
7
  describe "Compiler" do
8
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
9
+ reset_constant(:YMDP_ENV, "build")
10
+ reset_constant(:CONFIG, mock('config').as_null_object)
14
11
 
15
12
  Application.stub!(:current_view=)
16
13
 
17
- stub_screen_io
18
- stub_file_io
19
- stub_file_utils
20
- stub_yaml
14
+ stub_io
21
15
  end
22
16
 
23
17
  describe "view" do
24
18
  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
- },
19
+ @domain = "staging"
20
+ @filename = "filename.html.haml"
21
+ @git_hash = "asjkhfasjkfhjk"
22
+ @message = "This is a commit message."
51
23
 
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)
24
+ @params = {
25
+ :verbose => false,
26
+ :domain => @domain,
27
+ :file => @filename,
28
+ :git_hash => @git_hash,
29
+ :message => @message
30
+ }
31
+ stub_yrb_configuration
32
+
33
+ @view_template = YMDP::Compiler::Template::View.new(@params)
65
34
  end
66
35
 
67
36
  describe "instantiation" do
@@ -78,18 +47,13 @@ describe "Compiler" do
78
47
  end
79
48
 
80
49
  it "should set server" do
81
- @view_template.server.should == @servers["server"]
50
+ @view_template.server.should == "staging"
82
51
  end
83
52
 
84
53
  it "should set file" do
85
54
  @view_template.file.should == @filename
86
55
  end
87
56
 
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
57
  it "should set content variables" do
94
58
  @view_template.instance_variable_get("@version").should == @content_variables["version"]
95
59
  @view_template.instance_variable_get("@sprint_name").should == @content_variables["sprint_name"]
@@ -100,5 +64,13 @@ describe "Compiler" do
100
64
  @view_template = YMDP::Compiler::Template::View.new(@params)
101
65
  end
102
66
  end
67
+
68
+ describe "validation" do
69
+ it "should raise an error without a server" do
70
+ lambda {
71
+ @view_template = YMDP::Compiler::Template::View.new(@params.merge({:domain => "nowhere"}))
72
+ }.should raise_error
73
+ end
74
+ end
103
75
  end
104
76
  end
@@ -6,6 +6,8 @@
6
6
  = "'#{@view}' view for #{@domain}: #{@server}"
7
7
  = "built at #{Time.now}"
8
8
  = "commit #{@hash}, '#{@message}'"
9
+
10
+ - raise "No server" unless @server
9
11
 
10
12
  %title= "#{@view} view for #{@domain}: #{@server}"
11
13
 
@@ -15,6 +15,7 @@ config:
15
15
  js_assets: true
16
16
  validate:
17
17
  html:
18
+ doctype: HTML 4.0 Transitional
18
19
  build: true
19
20
  deploy: true
20
21
  embedded_js:
@@ -26,8 +26,6 @@ SORTED_LOCALES = LOCALES.sort do |a,b|
26
26
  a[1] <=> b[1]
27
27
  end unless defined?(SORTED_LOCALES)
28
28
 
29
- YMDP_ROOT = "." unless defined?(YMDP_ROOT)
30
-
31
29
  def file_not_found(filename)
32
30
  puts
33
31
  puts "Create #{filename} with the following command:\n\n ./script/config"
@@ -36,21 +34,19 @@ def file_not_found(filename)
36
34
  raise "File not found: #{filename}"
37
35
  end
38
36
 
39
- servers = "#{YMDP_ROOT}/config/servers.yml"
40
- config = "#{YMDP_ROOT}/config/config.yml"
37
+ servers = "#{BASE_PATH}/config/servers.yml"
38
+ config = "#{BASE_PATH}/config/config.yml"
41
39
 
42
40
  if File.exists?(servers)
43
- # SERVERS = YAML.load_file("#{YMDP_ROOT}/config/servers.yml") unless defined?(SERVERS)
44
41
  SERVERS = YMDP::Configuration::Servers.new
45
42
  else
46
43
  file_not_found(servers)
47
44
  end
48
45
 
49
46
  if File.exists?(config)
50
- # CONFIG = YAML.load_file("#{YMDP_ROOT}/config/config.yml")["config"] unless defined?(CONFIG)
51
47
  CONFIG = YMDP::Configuration::Config.new
52
48
  else
53
49
  file_not_found(config)
54
50
  end
55
51
 
56
- TMP_DIR = "./tmp" unless defined?(TMP_DIR)
52
+ TMP_PATH = "./tmp" unless defined?(TMP_PATH)