scaffoldhub 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ .bundle
2
+ db/*.sqlite3
3
+ log/*.log
4
+ tmp/*
5
+ public/system
6
+ *.DS_Store
7
+ coverage/*
8
+ *.swp
9
+ *~
10
+ rerun.txt
11
+ tags
12
+ !.keep
13
+ tmp/bundler
14
+ .rvmrc
15
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in code_buddy.gemspec
4
+ gemspec
5
+
6
+ #group :test, :cucumber do
7
+ #gem 'rails'
8
+ #end
@@ -0,0 +1,90 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ scaffold_hub (0.0.1)
5
+ rails
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ abstract (1.0.0)
11
+ actionmailer (3.0.5)
12
+ actionpack (= 3.0.5)
13
+ mail (~> 2.2.15)
14
+ actionpack (3.0.5)
15
+ activemodel (= 3.0.5)
16
+ activesupport (= 3.0.5)
17
+ builder (~> 2.1.2)
18
+ erubis (~> 2.6.6)
19
+ i18n (~> 0.4)
20
+ rack (~> 1.2.1)
21
+ rack-mount (~> 0.6.13)
22
+ rack-test (~> 0.5.7)
23
+ tzinfo (~> 0.3.23)
24
+ activemodel (3.0.5)
25
+ activesupport (= 3.0.5)
26
+ builder (~> 2.1.2)
27
+ i18n (~> 0.4)
28
+ activerecord (3.0.5)
29
+ activemodel (= 3.0.5)
30
+ activesupport (= 3.0.5)
31
+ arel (~> 2.0.2)
32
+ tzinfo (~> 0.3.23)
33
+ activeresource (3.0.5)
34
+ activemodel (= 3.0.5)
35
+ activesupport (= 3.0.5)
36
+ activesupport (3.0.5)
37
+ arel (2.0.9)
38
+ builder (2.1.2)
39
+ diff-lcs (1.1.2)
40
+ erubis (2.6.6)
41
+ abstract (>= 1.0.0)
42
+ i18n (0.5.0)
43
+ mail (2.2.15)
44
+ activesupport (>= 2.3.6)
45
+ i18n (>= 0.4.0)
46
+ mime-types (~> 1.16)
47
+ treetop (~> 1.4.8)
48
+ mime-types (1.16)
49
+ mocha (0.9.12)
50
+ polyglot (0.3.1)
51
+ rack (1.2.1)
52
+ rack-mount (0.6.13)
53
+ rack (>= 1.0.0)
54
+ rack-test (0.5.7)
55
+ rack (>= 1.0)
56
+ rails (3.0.5)
57
+ actionmailer (= 3.0.5)
58
+ actionpack (= 3.0.5)
59
+ activerecord (= 3.0.5)
60
+ activeresource (= 3.0.5)
61
+ activesupport (= 3.0.5)
62
+ bundler (~> 1.0)
63
+ railties (= 3.0.5)
64
+ railties (3.0.5)
65
+ actionpack (= 3.0.5)
66
+ activesupport (= 3.0.5)
67
+ rake (>= 0.8.7)
68
+ thor (~> 0.14.4)
69
+ rake (0.8.7)
70
+ rspec (2.3.0)
71
+ rspec-core (~> 2.3.0)
72
+ rspec-expectations (~> 2.3.0)
73
+ rspec-mocks (~> 2.3.0)
74
+ rspec-core (2.3.1)
75
+ rspec-expectations (2.3.0)
76
+ diff-lcs (~> 1.1.2)
77
+ rspec-mocks (2.3.0)
78
+ thor (0.14.6)
79
+ treetop (1.4.9)
80
+ polyglot (>= 0.3.1)
81
+ tzinfo (0.3.24)
82
+
83
+ PLATFORMS
84
+ ruby
85
+
86
+ DEPENDENCIES
87
+ mocha (~> 0.9.10)
88
+ rake (~> 0.8.7)
89
+ rspec (~> 2.3.0)
90
+ scaffold_hub!
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,17 @@
1
+ require 'rails/generators/erb/scaffold/scaffold_generator'
2
+
3
+ module Erb
4
+ class ScaffoldhubGenerator < Erb::Generators::ScaffoldGenerator
5
+
6
+ include Scaffoldhub::Helper
7
+
8
+ class_option :scaffold, :default => 'default', :banner => "SCAFFOLD_NAME", :type => :string, :desc => "Scaffold to use"
9
+ class_option :local, :default => false, :banner => "LOCAL SCAFFOLD", :type => :boolean, :desc => "Use a local scaffold, not scaffoldhub.org"
10
+
11
+ def copy_view_files
12
+ each_template_file(:erb) do |erb_template_file|
13
+ template erb_template_file.src, File.join("app/views", controller_file_path, erb_template_file.dest)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,20 @@
1
+ require 'rails/generators/rails/scaffold_controller/scaffold_controller_generator'
2
+
3
+ module ScaffoldController
4
+ class ScaffoldhubGenerator < Rails::Generators::ScaffoldControllerGenerator
5
+
6
+ include Scaffoldhub::Helper
7
+
8
+ remove_hook_for :template_engine
9
+ hook_for :template_engine, :as => :scaffoldhub
10
+
11
+ class_option :scaffold, :default => 'default', :banner => "SCAFFOLD_NAME", :type => :string, :desc => "Scaffold to use"
12
+ class_option :local, :default => false, :banner => "LOCAL SCAFFOLD", :type => :boolean, :desc => "Use a local scaffold, not scaffoldhub.org"
13
+
14
+ def create_controller_files
15
+ each_template_file(:controller) do |controller_template_file|
16
+ template controller_template_file.src, File.join('app/controllers', class_path, controller_template_file.dest)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,18 @@
1
+ require 'rails/generators/rails/scaffold/scaffold_generator'
2
+
3
+ class ScaffoldhubGenerator < Rails::Generators::ScaffoldGenerator
4
+
5
+ include Scaffoldhub::Helper
6
+
7
+ remove_hook_for :scaffold_controller
8
+ hook_for :scaffold_controller, :as => :scaffoldhub
9
+
10
+ class_option :scaffold, :default => 'default', :banner => "SCAFFOLD_NAME", :type => :string, :desc => "Scaffold to use"
11
+ class_option :local, :default => false, :banner => "LOCAL SCAFFOLD", :type => :boolean, :desc => "Use a local scaffold, not scaffoldhub.org"
12
+
13
+ def download_and_copy_other_files
14
+ each_template_file(:other) do |other_template_file|
15
+ template other_template_file.src, other_template_file.dest
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,9 @@
1
+ require 'scaffoldhub/remote_file'
2
+ require 'scaffoldhub/spec_file'
3
+ require 'scaffoldhub/template_file'
4
+ require 'scaffoldhub/scaffold'
5
+ require 'scaffoldhub/helper'
6
+
7
+ module Scaffoldhub
8
+ VERSION = '0.0.1'
9
+ end
@@ -0,0 +1,36 @@
1
+ module Scaffoldhub
2
+ module Helper
3
+
4
+ def self.scaffold
5
+ @scaffold
6
+ end
7
+
8
+ def self.scaffold=(scaffold)
9
+ @scaffold = scaffold
10
+ end
11
+
12
+ def each_template_file(type)
13
+ begin
14
+ Scaffoldhub::Helper.scaffold ||= Scaffoldhub::Scaffold.new(options[:scaffold], options[:local], status_proc)
15
+ Scaffoldhub::SpecFile.new(status_proc).select_files(type).each do |template_file|
16
+ if options[:local]
17
+ raise Errno::ENOENT.new(template_file.src) unless File.exists?(template_file.src)
18
+ else
19
+ template_file.download
20
+ end
21
+ yield template_file
22
+ end
23
+ rescue Errno::ENOENT
24
+ say_status :error, "File not found error for #{File.expand_path(options[:scaffold])}", :red
25
+ rescue Scaffoldhub::NotFoundException => e
26
+ say_status :error, "HTTP 404 not found error for #{e.message}", :red
27
+ rescue Scaffoldhub::NetworkErrorException => e
28
+ say_status :error, "HTTP error connecting to #{e.message}", :red
29
+ end
30
+ end
31
+
32
+ def status_proc
33
+ @proc ||= lambda { |url| say_status :download, url }
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,38 @@
1
+ require 'net/http'
2
+
3
+ module Scaffoldhub
4
+
5
+ class NotFoundException < RuntimeError
6
+ end
7
+
8
+ class NetworkErrorException < RuntimeError
9
+ end
10
+
11
+ class RemoteFile
12
+
13
+ def initialize(status_proc)
14
+ @status_proc = status_proc
15
+ end
16
+
17
+ def download
18
+ begin
19
+ uri = URI.parse(url)
20
+ @status_proc.call(url)
21
+ Net::HTTP.start(uri.host, uri.port) do |http|
22
+ resp = http.get(uri.path)
23
+ if resp.code.to_i == 200
24
+ resp.body
25
+ elsif resp.code.to_i == 404
26
+ raise NotFoundException.new(url)
27
+ else
28
+ raise NetworkErrorException.new(url)
29
+ end
30
+ end
31
+ rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError, Errno::ECONNREFUSED,
32
+ Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError => e
33
+ raise NetworkErrorException.new(url)
34
+ end
35
+ end
36
+
37
+ end
38
+ end
@@ -0,0 +1,38 @@
1
+ module Scaffoldhub
2
+ class Scaffold < RemoteFile
3
+
4
+ SERVER_NAME = 'scaffoldhub.org'
5
+
6
+ def initialize(scaffold, local, status_proc)
7
+ @scaffold = scaffold
8
+ @local = local
9
+ super(status_proc)
10
+ end
11
+
12
+ def base_url
13
+ if @local
14
+ File.dirname(File.expand_path(@scaffold))
15
+ else
16
+ spec_url.split(/\/(?=[^\/]+(?: |$))/)[0]
17
+ end
18
+ end
19
+
20
+ def spec_url
21
+ @spec_url ||=
22
+ if @local
23
+ @scaffold
24
+ else
25
+ download.strip
26
+ end
27
+ end
28
+
29
+ def local
30
+ @local
31
+ end
32
+
33
+ def url
34
+ "http://#{SERVER_NAME}/scaffolds/#{@scaffold}/spec"
35
+ end
36
+
37
+ end
38
+ end
@@ -0,0 +1,42 @@
1
+ module Scaffoldhub
2
+ class SpecFile < RemoteFile
3
+
4
+ def initialize(status_proc)
5
+ @status_proc = status_proc
6
+ super(status_proc)
7
+ end
8
+
9
+ def url
10
+ Scaffoldhub::Helper.scaffold.spec_url
11
+ end
12
+
13
+ def select_files(type)
14
+ if Scaffoldhub::Helper.scaffold.local
15
+ load_local
16
+ else
17
+ load_remote
18
+ end
19
+ @spec[:files].select { |file_spec| file_spec[:type] == type.to_s }.collect do |file_spec|
20
+ TemplateFile.new file_spec[:src], file_spec[:dest], @status_proc
21
+ end
22
+ end
23
+
24
+ protected
25
+
26
+ def load_local
27
+ parse(File.new(url).read)
28
+ end
29
+
30
+ def load_remote
31
+ parse(download)
32
+ end
33
+
34
+ def parse(data)
35
+ @spec = YAML::load(data) unless data.nil?
36
+ end
37
+
38
+ #def method_missing(name, *args, &blk)
39
+ ##@spec.send(name)
40
+ #end
41
+ end
42
+ end
@@ -0,0 +1,35 @@
1
+ module Scaffoldhub
2
+ class TemplateFile < RemoteFile
3
+
4
+ def initialize(src, dest, status_proc)
5
+ @src = src
6
+ @dest = dest || ''
7
+ @base_url = Scaffoldhub::Helper.scaffold.base_url
8
+ super(status_proc)
9
+ end
10
+
11
+ def src
12
+ if Scaffoldhub::Helper.scaffold.local
13
+ File.join(@base_url, @src)
14
+ else
15
+ @local_path
16
+ end
17
+ end
18
+
19
+ def dest
20
+ File.join(@dest, File.basename(@src))
21
+ end
22
+
23
+ def download
24
+ @local_path = Tempfile.new(File.basename(@src)).path
25
+ open(@local_path, "wb") do |file|
26
+ file.write(super)
27
+ end
28
+ end
29
+
30
+ def url
31
+ "#{@base_url}/#{@src}"
32
+ end
33
+
34
+ end
35
+ end
@@ -0,0 +1,28 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+
4
+ require 'scaffoldhub'
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "scaffoldhub"
8
+ s.version = Scaffoldhub::VERSION
9
+ s.platform = Gem::Platform::RUBY
10
+ s.authors = ['Pat Shaughnessy']
11
+ s.email = ['pat@patshaughnessy.net']
12
+ s.homepage = "http://scaffoldhub.org"
13
+ s.summary = %q{Generate Rails scaffolding from scaffoldhub.org}
14
+ s.description = %q{Generate Rails scaffolding from scaffoldhub.org}
15
+
16
+ #s.rubyforge_project = "scaffoldhub"
17
+
18
+ s.files = `git ls-files`.split("\n")
19
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
20
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
21
+ s.require_paths = ["lib"]
22
+
23
+ s.add_dependency 'rails'
24
+
25
+ s.add_development_dependency 'rake', '~> 0.8.7'
26
+ s.add_development_dependency 'rspec', '~> 2.3.0'
27
+ s.add_development_dependency 'mocha', '~> 0.9.10'
28
+ end
metadata ADDED
@@ -0,0 +1,142 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: scaffoldhub
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Pat Shaughnessy
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-03-04 00:00:00 -05:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rails
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: rake
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ hash: 49
44
+ segments:
45
+ - 0
46
+ - 8
47
+ - 7
48
+ version: 0.8.7
49
+ type: :development
50
+ version_requirements: *id002
51
+ - !ruby/object:Gem::Dependency
52
+ name: rspec
53
+ prerelease: false
54
+ requirement: &id003 !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ~>
58
+ - !ruby/object:Gem::Version
59
+ hash: 3
60
+ segments:
61
+ - 2
62
+ - 3
63
+ - 0
64
+ version: 2.3.0
65
+ type: :development
66
+ version_requirements: *id003
67
+ - !ruby/object:Gem::Dependency
68
+ name: mocha
69
+ prerelease: false
70
+ requirement: &id004 !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ hash: 47
76
+ segments:
77
+ - 0
78
+ - 9
79
+ - 10
80
+ version: 0.9.10
81
+ type: :development
82
+ version_requirements: *id004
83
+ description: Generate Rails scaffolding from scaffoldhub.org
84
+ email:
85
+ - pat@patshaughnessy.net
86
+ executables: []
87
+
88
+ extensions: []
89
+
90
+ extra_rdoc_files: []
91
+
92
+ files:
93
+ - .gitignore
94
+ - Gemfile
95
+ - Gemfile.lock
96
+ - Rakefile
97
+ - lib/generators/erb/scaffoldhub_generator.rb
98
+ - lib/generators/scaffold_controller/scaffoldhub_generator.rb
99
+ - lib/generators/scaffoldhub/scaffoldhub_generator.rb
100
+ - lib/scaffoldhub.rb
101
+ - lib/scaffoldhub/helper.rb
102
+ - lib/scaffoldhub/remote_file.rb
103
+ - lib/scaffoldhub/scaffold.rb
104
+ - lib/scaffoldhub/spec_file.rb
105
+ - lib/scaffoldhub/template_file.rb
106
+ - scaffoldhub.gemspec
107
+ has_rdoc: true
108
+ homepage: http://scaffoldhub.org
109
+ licenses: []
110
+
111
+ post_install_message:
112
+ rdoc_options: []
113
+
114
+ require_paths:
115
+ - lib
116
+ required_ruby_version: !ruby/object:Gem::Requirement
117
+ none: false
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ hash: 3
122
+ segments:
123
+ - 0
124
+ version: "0"
125
+ required_rubygems_version: !ruby/object:Gem::Requirement
126
+ none: false
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ hash: 3
131
+ segments:
132
+ - 0
133
+ version: "0"
134
+ requirements: []
135
+
136
+ rubyforge_project:
137
+ rubygems_version: 1.4.2
138
+ signing_key:
139
+ specification_version: 3
140
+ summary: Generate Rails scaffolding from scaffoldhub.org
141
+ test_files: []
142
+