Module: Cyborg
- Extended by:
- Cyborg
- Included in:
- Cyborg
- Defined in:
- lib/cyborg.rb,
lib/cyborg/assets.rb,
lib/cyborg/plugin.rb,
lib/cyborg/command.rb,
lib/cyborg/version.rb,
lib/cyborg/middleware.rb,
lib/cyborg/command/npm.rb,
lib/cyborg/command/help.rb,
lib/cyborg/command/compress.rb,
lib/cyborg/command/scaffold.rb,
lib/cyborg/plugin/assets/svgs.rb,
lib/cyborg/plugin/assets/asset.rb,
lib/cyborg/helpers/asset_helpers.rb,
lib/cyborg/helpers/layout_helpers.rb,
lib/cyborg/plugin/assets/javascripts.rb,
lib/cyborg/plugin/assets/stylesheets.rb
Defined Under Namespace
Modules: Assets, Command, GZIP, Help, Helpers, NPM
Classes: Application, Plugin, Scaffold
Constant Summary
collapse
- VERSION =
"0.0.2"
Instance Attribute Summary collapse
Instance Method Summary
collapse
Instance Attribute Details
#plugin ⇒ Object
Returns the value of attribute plugin.
12
13
14
|
# File 'lib/cyborg.rb', line 12
def plugin
@plugin
end
|
Instance Method Details
#at_gem_root ⇒ Object
96
97
98
|
# File 'lib/cyborg.rb', line 96
def at_gem_root
!Dir['*.gemspec'].empty?
end
|
#at_rails_root ⇒ Object
92
93
94
|
# File 'lib/cyborg.rb', line 92
def at_rails_root
File.exist?("bin/rails")
end
|
#build ⇒ Object
39
40
41
42
|
# File 'lib/cyborg.rb', line 39
def build
puts 'Building…'
@threads.concat plugin.build
end
|
#dispatch(command) ⇒ Object
33
34
35
36
37
|
# File 'lib/cyborg.rb', line 33
def dispatch(command)
@threads = []
send(command)
@threads.each { |thr| thr.join }
end
|
#gem_path ⇒ Object
100
101
102
103
104
105
106
|
# File 'lib/cyborg.rb', line 100
def gem_path
if at_gem_root
Dir.pwd
elsif at_rails_root
"../"
end
end
|
#load_helpers ⇒ Object
82
83
84
85
86
87
88
89
90
|
# File 'lib/cyborg.rb', line 82
def load_helpers
require "cyborg/helpers/asset_helpers"
require "cyborg/helpers/layout_helpers"
Cyborg::Helpers.constants.each do |c|
helper = Cyborg::Helpers.const_get(c)
ActionView::Base.send :include, helper if defined? ActionView::Base
end
end
|
#load_rake_tasks ⇒ Object
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/cyborg.rb', line 61
def load_rake_tasks
plugin.engine.rake_tasks do
namespace :cyborg do
desc "Cyborg build task"
task :build do
Cyborg.dispatch(:build)
end
desc "Watch assets for build"
task :watch do
Cyborg.dispatch(:watch)
end
desc "Start rails and watch assets for build"
task :server do
Cyborg.dispatch(:server)
end
end
end
end
|
#patch_rails ⇒ Object
28
29
30
31
|
# File 'lib/cyborg.rb', line 28
def patch_rails
load_rake_tasks
load_helpers
end
|
#production? ⇒ Boolean
15
16
17
|
# File 'lib/cyborg.rb', line 15
def production?
ENV['CI'] || ENV['RAILS_ENV'] == 'production'
end
|
#rails_path ⇒ Object
108
109
110
111
112
113
114
115
116
117
|
# File 'lib/cyborg.rb', line 108
def rails_path
if at_rails_root
Dir.pwd
else
dir = Dir["**/bin/rails"]
if !dir.empty?
dir.first.split('/').first
end
end
end
|
#register(plugin_module, options = {}) ⇒ Object
23
24
25
26
|
# File 'lib/cyborg.rb', line 23
def register(plugin_module, options={})
@plugin = plugin_module.new(options)
patch_rails
end
|
#server ⇒ Object
56
57
58
59
|
# File 'lib/cyborg.rb', line 56
def server
@threads << Thread.new { system 'rails server' }
watch
end
|
#watch ⇒ Object
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/cyborg.rb', line 44
def watch
build
require 'listen'
trap("SIGINT") {
puts "\nCyborg watcher stopped. Have a nice day!"
exit!
}
@threads.concat plugin.watch
end
|