adva-static 0.0.3 → 0.0.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.
@@ -0,0 +1,85 @@
1
+ Given /^an empty import directory "([^"]+)"$/ do |name|
2
+ @import_dir = Pathname.new("/tmp/adva-static-test/import/#{name}")
3
+ import_dir.mkpath
4
+ end
5
+
6
+ Given /^an empty export directory$/ do
7
+ @export_dir = Pathname.new("/tmp/adva-static-test/export")
8
+ export_dir.mkpath
9
+ end
10
+
11
+ Given /^a source file "([^\"]*)"$/ do |filename|
12
+ setup_files([filename, '']) unless filename.blank?
13
+ end
14
+
15
+ Given /^a source file "([^\"]*)" with the following values:$/ do |filename, table|
16
+ setup_files([filename, YAML.dump(table.rows_hash)]) unless filename.blank?
17
+ end
18
+
19
+ Given /^the following source files:$/ do |table|
20
+ table.hashes.each do |hash|
21
+ setup_files([hash.delete('file'), YAML.dump(hash)])
22
+ end
23
+ end
24
+
25
+ Given /^a watcher has started$/ do
26
+ @watch ||= begin
27
+ Adva::Static::Rack::Watch.any_instance.stubs(:run!)
28
+ Adva::Static::Rack::Watch.new(Adva::Static::Rack::Export.new(Rails.application, :target => export_dir), :dir => import_dir)
29
+ end
30
+ end
31
+
32
+ When /^I run the import task$/ do
33
+ Adva::Static::Import.new(:source => import_dir).run
34
+ end
35
+
36
+ When /^I create the file "([^"]*)" with the following values triggering the watcher:$/ do |filename, table|
37
+ setup_files([filename, YAML.dump(table.rows_hash)]) unless filename.blank?
38
+ @watch.send(:handler).trigger
39
+ end
40
+
41
+ When /^I update the file "([^"]*)" with the following values triggering the watcher:$/ do |filename, table|
42
+ setup_files([filename, YAML.dump(table.rows_hash)])
43
+ file = import_dir.join(filename)
44
+ file.utime(file.atime, future)
45
+ @watch.send(:handler).trigger
46
+ end
47
+
48
+ When /^I delete the file "([^"]*)" triggering the watcher$/ do |filename|
49
+ import_dir.join(filename).unlink
50
+ @watch.send(:handler).trigger
51
+ end
52
+
53
+ Then /^the watcher should "([^\"]*)" the following "([^\"]*)" params for the file "([^\"]*)":$/ do |method, key, file, table|
54
+ import = Adva::Static::Import.new(:source => import_dir)
55
+ request = import.request_for(file)
56
+ params = request.params
57
+ method.downcase!
58
+
59
+ # model = import.send(:recognize, file).first
60
+ # debugger
61
+
62
+ case method
63
+ when 'put', 'delete'
64
+ assert_equal method, params['_method'].try(:downcase)
65
+ when 'post'
66
+ assert !params.key?('_method')
67
+ end
68
+
69
+ expected = table.rows_hash.symbolize_keys
70
+ actual = request.params[key.to_sym].slice(*expected.keys)
71
+ assert_equal expected, actual
72
+ end
73
+
74
+ Then /^there should be an export file "([^"]*)" containing "([^"]*)"$/ do |filename, text|
75
+ file = export_dir.join(filename)
76
+ assert file.exist?, "expected #{file.to_s.inspect} to exist"
77
+ file = File.read(file)
78
+ assert file.include?(text), "expected #{file.inspect} to include #{text.inspect} "
79
+ end
80
+
81
+ Then /^there should not be an export file "([^"]*)"$/ do |filename|
82
+ file = export_dir.join(filename)
83
+ assert !file.exist?, "expected #{file.to_s.inspect} not to exist"
84
+ end
85
+
@@ -0,0 +1,133 @@
1
+ module TestHelper
2
+ module Static
3
+ def setup
4
+ setup_import_directory
5
+ super
6
+ end
7
+
8
+ def teardown_import_directory
9
+ import_dir.rmtree rescue nil
10
+ end
11
+
12
+ def teardown_export_directory
13
+ export_dir.rmtree rescue nil
14
+ end
15
+
16
+ def import_dir
17
+ @import_dir ||= Pathname.new('/tmp/adva-static-test/import/ruby-i18n.org')
18
+ end
19
+
20
+ def export_dir
21
+ @export_dir ||= Pathname.new('/tmp/adva-static-test/export')
22
+ end
23
+
24
+ def teardown
25
+ teardown_import_directory
26
+ super
27
+ end
28
+
29
+ def request(path)
30
+ Adva::Static::Import.new(:source => import_dir).request_for(path)
31
+ end
32
+
33
+ def source(path)
34
+ Adva::Static::Import::Source.new(path, import_dir)
35
+ end
36
+
37
+ def setup_site_record
38
+ Factory(:site, :host => 'ruby-i18n.org')
39
+ end
40
+
41
+ def setup_root_page_record
42
+ setup_site_record
43
+ end
44
+
45
+ def setup_non_root_page_record
46
+ site = setup_site_record
47
+ site.pages.create!(:name => 'Contact')
48
+ end
49
+
50
+ def setup_root_blog_record
51
+ site = setup_site_record
52
+ site.pages.first.destroy
53
+
54
+ site.blogs.create!(:name => 'Home', :posts_attributes => [
55
+ { :title => 'Welcome to the future of I18n in Ruby on Rails', :body => 'Welcome to the future!', :published_at => '2008-07-31' }
56
+ ])
57
+ end
58
+
59
+ def setup_non_root_blog_record
60
+ site = setup_site_record
61
+ site.blogs.create!(:name => 'Blog', :posts_attributes => [
62
+ { :title => 'Welcome to the future of I18n in Ruby on Rails', :body => 'Welcome to the future!', :published_at => '2008-07-31' }
63
+ ])
64
+ end
65
+
66
+ def setup_import_directory
67
+ import_dir.mkpath
68
+ setup_dirs(%w(images javascripts stylesheets))
69
+ setup_files(['config.ru', 'foo'], ['site.yml', YAML.dump(:host => 'ruby-i18n.org', :name => 'Ruby I18n', :title => 'Ruby I18n')])
70
+ end
71
+
72
+ def setup_root_blog
73
+ setup_files(
74
+ ['2008/07/31/welcome-to-the-future-of-i18n-in-ruby-on-rails.yml', YAML.dump(:body => 'Welcome to the future')],
75
+ ['2009/07/12/ruby-i18n-gem-hits-0-2-0.yml', YAML.dump(:body => 'Ruby I18n hits 0.2.0')]
76
+ )
77
+ end
78
+
79
+ def setup_non_root_blog
80
+ setup_files(
81
+ ['blog/2008/07/31/welcome-to-the-future-of-i18n-in-ruby-on-rails.yml', YAML.dump(:body => 'Welcome to the future')],
82
+ ['blog/2009/07/12/ruby-i18n-gem-hits-0-2-0.yml', YAML.dump(:body => 'Ruby I18n hits 0.2.0')]
83
+ )
84
+ end
85
+
86
+ def setup_root_page
87
+ setup_files(
88
+ ['index.yml', YAML.dump(:name => 'Home', :body => 'home')]
89
+ )
90
+ end
91
+
92
+ def setup_root_nested_page
93
+ setup_files(
94
+ ['home/nested.yml', YAML.dump(:body => 'nested under home')]
95
+ )
96
+ end
97
+
98
+ def setup_non_root_page
99
+ setup_files(
100
+ ['contact.yml', YAML.dump(:body => 'contact')]
101
+ )
102
+ end
103
+
104
+ def setup_non_root_nested_page
105
+ setup_files(
106
+ ['contact/nested.yml', YAML.dump(:body => 'nested under contact')]
107
+ )
108
+ end
109
+
110
+ def setup_nested_page
111
+ setup_files(
112
+ ['contact/mailer.yml', YAML.dump(:body => 'contact mailer')]
113
+ )
114
+ end
115
+
116
+ def setup_dirs(paths)
117
+ paths.each do |path|
118
+ FileUtils.mkdir_p(import_dir.join(path))
119
+ end
120
+ end
121
+
122
+ def setup_files(*files)
123
+ files.each do |path, content|
124
+ import_dir.join(File.dirname(path)).mkpath
125
+ File.open(import_dir.join(path), 'w') { |f| f.write(content) }
126
+ end
127
+ end
128
+
129
+ def future
130
+ Time.local(Time.now.year + 1, Time.now.month, Time.now.day)
131
+ end
132
+ end
133
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: adva-static
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 3
10
- version: 0.0.3
9
+ - 4
10
+ version: 0.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Sven Fuchs
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-11-19 00:00:00 +01:00
18
+ date: 2010-12-03 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -83,7 +83,37 @@ extensions: []
83
83
  extra_rdoc_files: []
84
84
 
85
85
  files:
86
- - lib/bundler/repository.rb
86
+ - lib/adva_static/version.rb
87
+ - lib/adva-static.rb
88
+ - lib/adva/tasks/static.rb
89
+ - lib/adva/static/setup.rb
90
+ - lib/adva/static/export.rb
91
+ - lib/adva/static/import/format.rb
92
+ - lib/adva/static/import/source.rb
93
+ - lib/adva/static/import/model.rb
94
+ - lib/adva/static/import/model/page.rb
95
+ - lib/adva/static/import/model/site.rb
96
+ - lib/adva/static/import/model/post.rb
97
+ - lib/adva/static/import/model/section.rb
98
+ - lib/adva/static/import/model/base.rb
99
+ - lib/adva/static/import/model/blog.rb
100
+ - lib/adva/static/import/request.rb
101
+ - lib/adva/static/watch.rb
102
+ - lib/adva/static/export/page.rb
103
+ - lib/adva/static/export/templates/config.ru
104
+ - lib/adva/static/export/path.rb
105
+ - lib/adva/static/export/store.rb
106
+ - lib/adva/static/export/queue.rb
107
+ - lib/adva/static/rack/export.rb
108
+ - lib/adva/static/rack/watch.rb
109
+ - lib/adva/static/rack/static.rb
110
+ - lib/adva/static/rack/request.rb
111
+ - lib/adva/static/rack.rb
112
+ - lib/adva/static/watch/handler.rb
113
+ - lib/adva/static/import.rb
114
+ - lib/adva/static.rb
115
+ - lib/testing/test_helper.rb
116
+ - lib/testing/step_definitions.rb
87
117
  has_rdoc: true
88
118
  homepage: http://github.com/svenfuchs/adva-cms2
89
119
  licenses: []
@@ -1,118 +0,0 @@
1
- require 'pathname'
2
-
3
- # Bundler gemfile support for local/remote workspaces/repositories for work in
4
- # development teams.
5
- #
6
- # Usage:
7
- #
8
- # # define paths to be searched for repositories:
9
- # workspace '~/.projects ~/Development/{projects,work}'
10
- #
11
- # # define developer preferences for using local or remote repositories (uses ENV['user']):
12
- # developer :sven, :prefer => :local
13
- #
14
- # # define repositories to be used for particular gems:
15
- # adva_cms = repository('adva-cms2', :git => 'git@github.com:svenfuchs/adva-cms2.git', :ref => 'c2af0de')
16
- # adva_shop = repository('adva-shop', :source => :local)
17
- #
18
- # # now use repositories to define gems:
19
- # adva_cms.gem 'adva-core'
20
- # adva_shop.gem 'adva-catalog'
21
- #
22
- # # The gem definition will now be proxied to Bundler with arguments according
23
- # # to the setup defined earlier. E.g. as:
24
- #
25
- # gem 'adva-core', :path => 'Development/projects/adva-cms2/adva-core' # for developer 'sven'
26
- # gem 'adva-core', :git => 'git@github.com:svenfuchs/adva-cms2.git', :ref => 'c2af0de' # for other developers
27
- # gem 'adva-catalog', :path => 'Development/projects/adva-shop/adva-catalog' # for all developers
28
- #
29
- # One can also set an environment variable FORCE_REMOTE which will force remote
30
- # repositories to be used *except* when a repository was defined with :source => :local
31
- # which always forces the local repository to be used.
32
- #
33
- class Repository
34
- class << self
35
- def paths
36
- @paths ||= []
37
- end
38
-
39
- def path(*paths)
40
- paths.join(' ').split(' ').each do |path|
41
- self.paths.concat(Pathname.glob(File.expand_path(path)))
42
- end
43
- end
44
-
45
- def developer(name, preferences)
46
- developers[name] = preferences
47
- workspaces(preferences[:workspace])
48
- end
49
-
50
- def current_developer
51
- developers[ENV['USER'].to_sym] || {}
52
- end
53
-
54
- def developers(developers = nil)
55
- @developers ||= {}
56
- end
57
- end
58
-
59
- class Gem < Array
60
- def initialize(name, repository)
61
- if repository.local?
62
- sub_path = repository.path.join(name)
63
- super([name, { :path => sub_path.exist? ? sub_path.to_s : repository.path.to_s }])
64
- else
65
- super([name, repository.options.dup])
66
- end
67
- end
68
- end
69
-
70
- attr_reader :bundler, :name, :options, :source
71
-
72
- def initialize(bundler, name, options)
73
- @bundler = bundler
74
- @name = name
75
- @source = options.delete(:source)
76
- @options = options
77
- end
78
-
79
- def gem(name)
80
- bundler.gem(*Gem.new(name, self))
81
- end
82
-
83
- def local?
84
- source == :local # && path
85
- end
86
-
87
- def source
88
- @source ||= forced_source || preferred_source || :remote
89
- end
90
-
91
- def forced_source
92
- :remote if ENV['FORCE_REMOTE']
93
- end
94
-
95
- def preferred_source
96
- self.class.current_developer[:prefer] || self.class.current_developer[name.to_sym]
97
- end
98
-
99
- def path
100
- @path ||= begin
101
- path = self.class.paths.detect { |path| path.join(name).exist? }
102
- path ? path.join(name) : Pathname.new('.')
103
- end
104
- end
105
- end
106
-
107
- def workspace(*paths)
108
- Repository.path(*paths)
109
- end
110
- alias :workspaces :workspace
111
-
112
- def developer(name, preferences)
113
- Repository.developer(name, preferences)
114
- end
115
-
116
- def repository(*args)
117
- Repository.new(self, *args)
118
- end