Class: Jekyll::Bower

Inherits:
Object
  • Object
show all
Defined in:
lib/jekyll/bower_plugin.rb,
lib/jekyll/plugin_version.rb

Constant Summary collapse

VERSION =
"1.1.5".freeze

Instance Method Summary collapse

Constructor Details

#initializeBower

Returns a new instance of Bower.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/jekyll/bower_plugin.rb', line 5

def initialize()
	puts "Checking if NPM is available\n"
	fail unless system('which npm')
	puts "Great, NPM is available\n"
	puts "Checkin if Bower is available\n"
	unless system('which bower')
		puts "Bower not available\n"
		puts "Installing bower\n"
		system('npm install -g bower')
		puts "Installation completed\n"
	else
		puts "Great, Bower is available\n"
	end
end

Instance Method Details

#resolve(site) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/jekyll/bower_plugin.rb', line 20

def resolve(site)
	if File.exists?("bower.json")
		puts "Resolving dependencies with bower\n"
		unless system('bower install')
			puts "Looks like bower is run by a sudo user\n"
			puts "Trying with --allow-root\n"
			system('bower install --allow-root')
		end
		puts "Bower dependencies resolved successfully\n"
	else
		if site.config['bower']
			puts "Resolving bower individually configured in config" + "\n"
			site.config['bower'].each do |name, library| 
				unless File.exists?('bower_components' + File::SEPARATOR + name)
					bower_command = 'bower install ' + library
					unless system(bower_command)
						puts "Trying resolving bower with allow-root" + "\n"
						system(bower_command + ' --allow-root')
					end

					if library =~ URI::regexp
						puts "Identified bower downloaded dependency is a URL" + "\n"
						puts "Performing rename activity if possible" + "\n"
						uri = URI.parse(library)
						filename = File.basename(uri.path, ".*")
						bowerOld = 'bower_components' + File::SEPARATOR + filename
						bowerNew = 'bower_components' + File::SEPARATOR + name
						unless File.exists?(bowerNew)
							File.rename(bowerOld, bowerNew)
							puts "Renamed bower ("+filename+") library to " + name + "\n"
						end
					end
					puts "Downloaded bower dependency: " + name + "\n"
				else
					puts "Bower dependency exists, skipping download\n"
				end
			end
		end
	end
end