Disable barista, xml parse refactor
This commit is contained in:
parent
c076efe860
commit
7a3444d103
2
Gemfile
2
Gemfile
|
@ -10,7 +10,7 @@ gem 'sass'
|
||||||
gem 'coffee-script'
|
gem 'coffee-script'
|
||||||
|
|
||||||
gem 'therubyracer', :require => false
|
gem 'therubyracer', :require => false
|
||||||
gem 'barista'
|
# gem 'barista'
|
||||||
|
|
||||||
gem 'awesome_print', :require => 'ap'
|
gem 'awesome_print', :require => 'ap'
|
||||||
gem 'delayed_job'
|
gem 'delayed_job'
|
||||||
|
|
|
@ -39,8 +39,6 @@ GEM
|
||||||
multi_json (~> 1.0)
|
multi_json (~> 1.0)
|
||||||
arel (2.2.1)
|
arel (2.2.1)
|
||||||
awesome_print (0.4.0)
|
awesome_print (0.4.0)
|
||||||
barista (1.2.1)
|
|
||||||
coffee-script (~> 2.2)
|
|
||||||
bcrypt-ruby (3.0.1)
|
bcrypt-ruby (3.0.1)
|
||||||
bitmask_attributes (0.2.2)
|
bitmask_attributes (0.2.2)
|
||||||
activerecord (~> 3.0)
|
activerecord (~> 3.0)
|
||||||
|
@ -121,7 +119,6 @@ PLATFORMS
|
||||||
|
|
||||||
DEPENDENCIES
|
DEPENDENCIES
|
||||||
awesome_print
|
awesome_print
|
||||||
barista
|
|
||||||
bitmask_attributes
|
bitmask_attributes
|
||||||
coffee-script
|
coffee-script
|
||||||
delayed_job
|
delayed_job
|
||||||
|
|
|
@ -1,64 +1,64 @@
|
||||||
# Configure barista.
|
# # Configure barista.
|
||||||
Barista.configure do |c|
|
# Barista.configure do |c|
|
||||||
|
#
|
||||||
# Change the root to use app/scripts
|
# # Change the root to use app/scripts
|
||||||
# c.root = Rails.root.join("app", "coffeescripts")
|
# # c.root = Rails.root.join("app", "coffeescripts")
|
||||||
|
#
|
||||||
# Change the output root, causing Barista to compile into public/coffeescripts
|
# # Change the output root, causing Barista to compile into public/coffeescripts
|
||||||
# c.output_root = Rails.root.join("public", "assets", "coffee")
|
# # c.output_root = Rails.root.join("public", "assets", "coffee")
|
||||||
#
|
# #
|
||||||
# Disable auto compile, use generated file directly:
|
# # Disable auto compile, use generated file directly:
|
||||||
# c.auto_compile = false
|
# # c.auto_compile = false
|
||||||
|
#
|
||||||
# Add a new framework:
|
# # Add a new framework:
|
||||||
|
#
|
||||||
# c.register :tests, :root => Rails.root.join('test', 'coffeescript'), :output_prefix => 'test'
|
# # c.register :tests, :root => Rails.root.join('test', 'coffeescript'), :output_prefix => 'test'
|
||||||
|
#
|
||||||
# Disable wrapping in a closure:
|
# # Disable wrapping in a closure:
|
||||||
c.bare = true
|
# c.bare = true
|
||||||
# ... or ...
|
# # ... or ...
|
||||||
# c.bare!
|
# # c.bare!
|
||||||
|
#
|
||||||
# Change the output root for a framework:
|
# # Change the output root for a framework:
|
||||||
|
#
|
||||||
# c.change_output_prefix! 'framework-name', 'output-prefix'
|
# # c.change_output_prefix! 'framework-name', 'output-prefix'
|
||||||
|
#
|
||||||
# or for all frameworks...
|
# # or for all frameworks...
|
||||||
|
#
|
||||||
# c.each_framework do |framework|
|
# # c.each_framework do |framework|
|
||||||
# c.change_output_prefix! framework, "vendor/#{framework.name}"
|
# # c.change_output_prefix! framework, "vendor/#{framework.name}"
|
||||||
# end
|
# # end
|
||||||
|
#
|
||||||
# or, prefix the path for the app files:
|
# # or, prefix the path for the app files:
|
||||||
|
#
|
||||||
# c.change_output_prefix! :default, 'my-app-name'
|
# # c.change_output_prefix! :default, 'my-app-name'
|
||||||
|
#
|
||||||
# or, change the directory the framework goes into full stop:
|
# # or, change the directory the framework goes into full stop:
|
||||||
|
#
|
||||||
# c.change_output_prefix! :tests, Rails.root.join('spec', 'javascripts')
|
# # c.change_output_prefix! :tests, Rails.root.join('spec', 'javascripts')
|
||||||
|
#
|
||||||
# or, hook into the compilation:
|
# # or, hook into the compilation:
|
||||||
|
#
|
||||||
# c.before_compilation { |path| puts "Barista: Compiling #{path}" }
|
# # c.before_compilation { |path| puts "Barista: Compiling #{path}" }
|
||||||
# c.on_compilation { |path| puts "Barista: Successfully compiled #{path}" }
|
# # c.on_compilation { |path| puts "Barista: Successfully compiled #{path}" }
|
||||||
# c.on_compilation_error { |path, output| puts "Barista: Compilation of #{path} failed with:\n#{output}" }
|
# # c.on_compilation_error { |path, output| puts "Barista: Compilation of #{path} failed with:\n#{output}" }
|
||||||
# c.on_compilation_with_warning { |path, output| puts "Barista: Compilation of #{path} had a warning:\n#{output}" }
|
# # c.on_compilation_with_warning { |path, output| puts "Barista: Compilation of #{path} had a warning:\n#{output}" }
|
||||||
|
#
|
||||||
# Turn off preambles and exceptions on failure:
|
# # Turn off preambles and exceptions on failure:
|
||||||
|
#
|
||||||
# c.verbose = false
|
# # c.verbose = false
|
||||||
|
#
|
||||||
# Or, make sure it is always on
|
# # Or, make sure it is always on
|
||||||
# c.verbose!
|
# # c.verbose!
|
||||||
|
#
|
||||||
# If you want to use a custom JS file, you can as well
|
# # If you want to use a custom JS file, you can as well
|
||||||
# e.g. vendoring CoffeeScript in your application:
|
# # e.g. vendoring CoffeeScript in your application:
|
||||||
# c.js_path = Rails.root.join('public', 'javascripts', 'coffee-script.js')
|
# # c.js_path = Rails.root.join('public', 'javascripts', 'coffee-script.js')
|
||||||
|
#
|
||||||
# Make helpers and the HAML filter output coffee-script instead of the compiled JS.
|
# # Make helpers and the HAML filter output coffee-script instead of the compiled JS.
|
||||||
# Used in combination with the coffeescript_interpreter_js helper in Rails.
|
# # Used in combination with the coffeescript_interpreter_js helper in Rails.
|
||||||
# c.embedded_interpreter = true
|
# # c.embedded_interpreter = true
|
||||||
|
#
|
||||||
c.add_preamble = false
|
# c.add_preamble = false
|
||||||
|
#
|
||||||
end
|
# end
|
||||||
|
|
|
@ -1,34 +1,41 @@
|
||||||
class Discogs
|
class Discogs
|
||||||
|
|
||||||
def self.artists
|
def self.artists
|
||||||
File.open('tmp/data/discogs_artists.xml') do |file|
|
self.get_nodes('tmp/data/discogs_artists.xml', 'artist') do
|
||||||
|
artist = Artist.new(
|
||||||
|
:name => (node.css('name').first.text),
|
||||||
|
:pic_url => (node.css('images > image[type="primary"]').first.attr('uri') unless node.css('images > image[type="primary"]').empty?),
|
||||||
|
:status => 1
|
||||||
|
)
|
||||||
|
artist.save
|
||||||
|
node.css('namevariations > name, aliases > name').each do |v|
|
||||||
|
ArtistAlias.new(
|
||||||
|
:artist_id => artist.id,
|
||||||
|
:name => v.text
|
||||||
|
).save
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.releases
|
||||||
|
self.get_nodes('tmp/data/discogs_releases_test.xml', 'release') do |node|
|
||||||
|
r = {
|
||||||
|
:pic => (node.css('images > image[type="primary"]').first.attr('uri') unless node.css('images > image[type="primary"]').empty?)
|
||||||
|
}
|
||||||
|
ap r
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def self.get_nodes filename, nodename, &block
|
||||||
|
File.open(filename) do |file|
|
||||||
Nokogiri::XML::Reader.from_io(file).each do |node|
|
Nokogiri::XML::Reader.from_io(file).each do |node|
|
||||||
if node.name == 'artist' and node.node_type == Nokogiri::XML::Reader::TYPE_ELEMENT
|
if node.name == nodename and node.node_type == Nokogiri::XML::Reader::TYPE_ELEMENT
|
||||||
self.process_artist Nokogiri::XML(node.outer_xml).root
|
yield(Nokogiri::XML(node.outer_xml).root)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.process_artist node
|
|
||||||
artist = Artist.new(
|
|
||||||
:name => (node.css('name').first.text),
|
|
||||||
:pic_url => (node.css('images > image[type="primary"]').first.attr('uri') unless node.css('images > image[type="primary"]').empty?),
|
|
||||||
:status => 1
|
|
||||||
)
|
|
||||||
artist.save
|
|
||||||
node.css('namevariations > name, aliases > name').each do |v|
|
|
||||||
ArtistAlias.new(
|
|
||||||
:artist_id => artist.id,
|
|
||||||
:name => v.text
|
|
||||||
).save
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.releases
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.process_release
|
|
||||||
|
|
||||||
end
|
|
||||||
end
|
end
|
|
@ -0,0 +1,9 @@
|
||||||
|
require "discogs"
|
||||||
|
namespace :discogs do
|
||||||
|
namespace :import do
|
||||||
|
desc 'Import discogs releases xml'
|
||||||
|
task :releases => :environment do
|
||||||
|
Discogs.releases
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue