Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allows for building specific versions #93

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
141 changes: 76 additions & 65 deletions tasks/angularjs-rails/updater.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,94 +4,105 @@
require 'pathname'
require 'tempfile'

module AngularJS::Rails
class Updater
BASE_URL = 'https://code.angularjs.org'
ROOT_PATH = Pathname.new('vendor/assets/javascripts')
# Run with `ruby -r "./tasks/angularjs-rails/updater.rb" -e "AngularJS::Rails::Updater.new.build_js('1.2.28')"`
module AngularJS
module Rails
class Updater
BASE_URL = 'https://code.angularjs.org'
ROOT_PATH = Pathname.new('vendor/assets/javascripts')

def initialize
end

def initialize
end
def base_path
ROOT_PATH
end

def base_path
ROOT_PATH
end
def update_js!
if latest_version >= current_gem_version
clean
download_files
update_version_to(latest_version)
end
end

def update_js!
if latest_version >= current_gem_version
def build_js(version)
clean
download_files
update_version_to(latest_version)
download_files(version)
update_version_to(version)
end
end

def current_gem_version
raise NotImplementedError
end
def current_gem_version
raise NotImplementedError
end

def available_versions
upstream_versions.find_all {|v| own_version(v) }
end
def available_versions
upstream_versions.find_all {|v| own_version(v) }
end

def latest_version
available_versions.last
end
def latest_version
available_versions.last
end

def version_constant_name
"VERSION"
end
def version_constant_name
"VERSION"
end

private
private

def clean
base_path.children.each do |f|
f.delete if f.file?
def clean
base_path.children.each do |f|
f.delete if f.file?
end
end
end

def update_version_to(version)
version_file = Pathname.new('lib/angularjs-rails/version.rb')
content = version_file.read
version_line = content.lines.find { |l| l =~ /^\s+#{version_constant_name}/ }
def update_version_to(version)
version_file = Pathname.new('lib/angularjs-rails/version.rb')
content = version_file.read
version_line = content.lines.find { |l| l =~ /^\s+#{version_constant_name}/ }

# version_to_convert = Versionomy.parse(version).convert(:rubygems).to_s
# version_to_convert = Versionomy.parse(version).convert(:rubygems).to_s

new_version_line = version_line.gsub(/"[^"]+"/, %Q{"#{version}"})
version_file.open('w+') do |f|
f.write content.gsub(version_line, new_version_line)
new_version_line = version_line.gsub(/"[^"]+"/, %Q{"#{version}"})
version_file.open('w+') do |f|
f.write content.gsub(version_line, new_version_line)
end
end
end

def upstream_versions
@upstream_versions ||= Nokogiri::HTML.parse(open(BASE_URL)).
css('a').map { |e| Versionomy.parse e.text[0..-2] rescue nil }.compact.sort
end
def upstream_versions
@upstream_versions ||= Nokogiri::HTML.parse(open(BASE_URL)).
css('a').map { |e| Versionomy.parse e.text[0..-2] rescue nil }.compact.sort
end

def own_version(v)
true
end
def own_version(v)
true
end

def self.update_js!
self.new.update_js!
end
def self.update_js!
self.new.update_js!
end

def download_files
url = BASE_URL + "/" + latest_version.to_s
Nokogiri::HTML.parse(open(url)).
css('a').
def download_files(version=latest_version)
url = BASE_URL + "/" + version.to_s
puts "Fetching #{url}"
Nokogiri::HTML.parse(open(url)).
css('a').

#only angular js files
map{|a| a[:href] =~ /angular[^.]*\.js/ ? a : nil }.compact.
#only angular js files
map{|a| a[:href] =~ /angular[^.]*\.js/ ? a : nil }.compact.

each do |a|
download_file(a[:href], url)
end
end
each do |a|
download_file(a[:href], url)
end
end

def download_file(file, url)
full_url = url + "/" + file
full_path = base_path.join(file)
full_path.open('w+') do |f|
f.write open(full_url).read
def download_file(file, url)
puts "Downloading #{file} from #{url}"
full_url = url + "/" + file
full_path = base_path.join(file)
full_path.open('w+') do |f|
f.write open(full_url).read
end
end
end
end
Expand Down