rails_component 0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +9 -0
- data/bin/rails_component +24 -0
- data/lib/rails_component.rb +92 -0
- data/rails_component.gemspec +27 -0
- metadata +67 -0
data/README.md
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
This is applying-components util for rails
|
2
|
+
|
3
|
+
gem install rails_component
|
4
|
+
|
5
|
+
rails new example_project
|
6
|
+
cd example_project
|
7
|
+
rails_component -u git@github.com:Paxa/sass_component.git
|
8
|
+
|
9
|
+
So now you have new rails project with included awesome sass mixins what can be easily edited.
|
data/bin/rails_component
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'rails_component'))
|
4
|
+
require "slop"
|
5
|
+
|
6
|
+
opts = Slop.parse do
|
7
|
+
on :u, :url, 'Apply component from url', true
|
8
|
+
on :d, :dir, 'Apply component from local directory', true
|
9
|
+
on :v, :verbose, 'Enable verbose mode'
|
10
|
+
|
11
|
+
on :h, :help, 'Print this help message', :tail => true do
|
12
|
+
puts help
|
13
|
+
exit
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
if opts[:url]
|
18
|
+
RComponent::Applier.remote(opts[:url], Dir.pwd)
|
19
|
+
elsif dir = opts[:dir]
|
20
|
+
RComponent::Applier.new(opts[:dir], Dir.pwd)
|
21
|
+
else
|
22
|
+
puts opts.help
|
23
|
+
end
|
24
|
+
|
@@ -0,0 +1,92 @@
|
|
1
|
+
require "tmpdir"
|
2
|
+
|
3
|
+
module RComponent
|
4
|
+
|
5
|
+
module Git
|
6
|
+
extend self
|
7
|
+
|
8
|
+
def clone(url, destination)
|
9
|
+
`git clone #{url} #{destination}`
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
class Applier
|
15
|
+
|
16
|
+
def self.remote(url, rails_root)
|
17
|
+
dir = Dir.mktmpdir
|
18
|
+
Git.clone(url, dir)
|
19
|
+
new(dir, rails_root)
|
20
|
+
end
|
21
|
+
|
22
|
+
def initialize(component_root, rails_root)
|
23
|
+
@rails_root = rails_root
|
24
|
+
@component_root = component_root
|
25
|
+
eval File.open(File.join(component_root, 'recept.rb'), 'r:utf-8', &:read)
|
26
|
+
|
27
|
+
print "Done!"
|
28
|
+
end
|
29
|
+
|
30
|
+
def clone_files(*list)
|
31
|
+
Dir.chdir(@component_root) do
|
32
|
+
list.each do |file|
|
33
|
+
if File.exist?(File.join(@component_root, file))
|
34
|
+
copy_file(file)
|
35
|
+
else
|
36
|
+
Dir.glob(file).each {|f| copy_file(f) }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def mkdirs(*list)
|
43
|
+
list.each do |dir|
|
44
|
+
unless File.directory?(File.join(@rails_root, dir))
|
45
|
+
exec "mkdir -p #{File.join(@rails_root, dir)}"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def print(text)
|
51
|
+
puts
|
52
|
+
puts text
|
53
|
+
puts
|
54
|
+
end
|
55
|
+
|
56
|
+
def with_file(file, &block)
|
57
|
+
File.open(File.join(@rails_root, file), 'a+:utf-8') {|f| block.call(f) }
|
58
|
+
end
|
59
|
+
|
60
|
+
def run(cmd)
|
61
|
+
Dir.chdir(@rails_root) do
|
62
|
+
exec(cmd)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def commit_changes(message)
|
67
|
+
Dir.chdir(@rails_root) do
|
68
|
+
exec "git init ." unless File.directory?(File.join(@rails_root, '.git'))
|
69
|
+
exec "git add . && git commit -m \"#{message.gsub(/"/, "\\\"")}\""
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
private
|
74
|
+
|
75
|
+
def copy_file(file)
|
76
|
+
if !File.directory?(File.dirname(File.join(@rails_root, file)))
|
77
|
+
exec "mkdir #{File.dirname(File.join(@rails_root, file))}"
|
78
|
+
end
|
79
|
+
|
80
|
+
if File.directory?(File.join(@component_root, file))
|
81
|
+
exec("mkdir -p #{File.join(@component_root, file)}")
|
82
|
+
else
|
83
|
+
exec("cp #{File.join(@component_root, file)} #{File.join(@rails_root, file)}")
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def exec(cmd)
|
88
|
+
puts "--- #{cmd}"
|
89
|
+
`#{cmd}`
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = "rails_component"
|
3
|
+
s.version = "0.1"
|
4
|
+
s.summary = "Applyng components for rails"
|
5
|
+
s.description = ""
|
6
|
+
s.author = "Pavel Evstigneev"
|
7
|
+
s.email = "pavel.evst@gmail.com"
|
8
|
+
s.homepage = "http://github.com/Paxa/rails_component"
|
9
|
+
s.has_rdoc = false
|
10
|
+
s.executables = ["rails_component"]
|
11
|
+
s.rubyforge_project = "rails_component"
|
12
|
+
s.files = [ "bin/rails_component", "README.md", "rails_component.gemspec", "lib/rails_component.rb"]
|
13
|
+
|
14
|
+
if s.respond_to? :specification_version then
|
15
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
16
|
+
s.specification_version = 3
|
17
|
+
|
18
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
19
|
+
s.add_runtime_dependency(%q<slop>, [">= 1.7"])
|
20
|
+
|
21
|
+
else
|
22
|
+
s.add_dependency(%q<slop>, [">= 1.0"])
|
23
|
+
end
|
24
|
+
else
|
25
|
+
s.add_dependency(%q<slop>, [">= 1.7"])
|
26
|
+
end
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rails_component
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: "0.1"
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Pavel Evstigneev
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-06-08 00:00:00 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: slop
|
17
|
+
prerelease: false
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "1.7"
|
24
|
+
type: :runtime
|
25
|
+
version_requirements: *id001
|
26
|
+
description: ""
|
27
|
+
email: pavel.evst@gmail.com
|
28
|
+
executables:
|
29
|
+
- rails_component
|
30
|
+
extensions: []
|
31
|
+
|
32
|
+
extra_rdoc_files: []
|
33
|
+
|
34
|
+
files:
|
35
|
+
- bin/rails_component
|
36
|
+
- README.md
|
37
|
+
- rails_component.gemspec
|
38
|
+
- lib/rails_component.rb
|
39
|
+
homepage: http://github.com/Paxa/rails_component
|
40
|
+
licenses: []
|
41
|
+
|
42
|
+
post_install_message:
|
43
|
+
rdoc_options: []
|
44
|
+
|
45
|
+
require_paths:
|
46
|
+
- lib
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
+
none: false
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: "0"
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: "0"
|
59
|
+
requirements: []
|
60
|
+
|
61
|
+
rubyforge_project: rails_component
|
62
|
+
rubygems_version: 1.8.5
|
63
|
+
signing_key:
|
64
|
+
specification_version: 3
|
65
|
+
summary: Applyng components for rails
|
66
|
+
test_files: []
|
67
|
+
|