diff --git a/.gitignore b/.gitignore index 0a956f1..6c2b12c 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,5 @@ pkg/* *.DS_Store .rspec *.swp +*.config-store +*.config diff --git a/Gemfile.lock b/Gemfile.lock index 16baeed..ff67193 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - trackman (0.6.12) + trackman (0.6.13) json nokogiri rack @@ -17,7 +17,7 @@ GEM json (1.7.5) mime-types (1.19) multi_json (1.3.6) - nokogiri (1.5.5) + nokogiri (1.5.6) rack (1.4.1) rake (0.9.2.2) rest-client (1.6.7) diff --git a/Rakefile b/Rakefile index 8183d0e..4200f36 100644 --- a/Rakefile +++ b/Rakefile @@ -1,14 +1,13 @@ require "bundler/gem_tasks" require 'rspec/core/rake_task' - desc "creates a new app to the server and outputs the credentials" task :create_app do require 'trackman' RemoteAsset = Trackman::Assets::RemoteAsset user = ENV['HEROKU_USERNAME'] - pass = ENV['HEROKU_PASSWORD'] + pass# = ENV['HEROKU_PASSWORD'] server = RemoteAsset.class_variable_get :@@server url = "http://#{user}:#{pass}@#{server}/heroku/resources" diff --git a/lib/trackman/scaffold/content_saver.rb b/lib/trackman/scaffold/content_saver.rb index 8b6298c..e15b7d9 100644 --- a/lib/trackman/scaffold/content_saver.rb +++ b/lib/trackman/scaffold/content_saver.rb @@ -33,6 +33,15 @@ def remove selector, &predicate end protected + def remove_default_nodes doc + nodes = [] + nodes = nodes.concat doc.search('script').select{|n| n['src'] && n['src'].include?('/assets') && !n['src'].include?('application') } + nodes = nodes.concat doc.search('link').select{|n| n['href'] && n['href'].include?('/assets') && !n['href'].include?('application') } + nodes.each{|n| n.remove } + + doc + end + def remove_nodes doc self.class.nodes_to_remove.each do |selector, predicate| nodes = doc.search(selector) @@ -40,6 +49,7 @@ def remove_nodes doc unless predicate.nil? nodes = nodes.select { |n| r = predicate.call(n, i); i +=1;r } end + nodes.each{|n| n.remove } end doc @@ -62,24 +72,32 @@ def xslt @xslt ||= Nokogiri::XSLT(File.open("#{File.dirname(__FILE__)}/pretty-print.xslt")) end - def new_content + def asset_pipeline_debug_mode? + Object.const_defined?(:Rails) && + Rails.respond_to?(:application) && + Rails.application.config.assets.enabled && + Rails.application.config.assets.debug + end + + def new_content params={:keep_default_nodes => false} html = Nokogiri::HTML(response.body) edit_nodes html + remove_default_nodes html unless params[:keep_default_nodes] remove_nodes html html = xslt.apply_to(html).to_s gsub_html(html) end - - def render_content - response.body = new_content + + def render_content + response.body = new_content(:keep_default_nodes => asset_pipeline_debug_mode?) to_write = self.class.mappings[params[:action].to_sym] unless to_write.nil? path = "/public/#{to_write}.html" - File.open(Rails.root.to_s + path, 'w') { |f| f.write(response.body) } + File.open(Rails.root.to_s + path, 'w') { |f| f.write(new_content) } end end end end -end \ No newline at end of file +end diff --git a/lib/trackman/tasks/trackman.rake b/lib/trackman/tasks/trackman.rake index 92fa8a5..34a4951 100644 --- a/lib/trackman/tasks/trackman.rake +++ b/lib/trackman/tasks/trackman.rake @@ -13,3 +13,17 @@ namespace :trackman do Trackman::Utility::Configuration.new(:app => args[:app]).setup end end + +if Rake::Task.task_defined?("assets:precompile:nondigest") + Rake::Task["assets:precompile:nondigest"].enhance do + STDOUT.puts "Trackman: autosyncing..." + Trackman::Assets::Asset.autosync + STDOUT.puts "Trackman: done." +end +elsif Rake::Task.task_defined?("assets:precompile") + Rake::Task["assets:precompile"].enhance do + STDOUT.puts "Trackman: autosyncing..." + Trackman::Assets::Asset.autosync + STDOUT.puts "Trackman: done." + end +end diff --git a/lib/trackman/utility/configuration.rb b/lib/trackman/utility/configuration.rb index c7b7d15..1b7f23b 100644 --- a/lib/trackman/utility/configuration.rb +++ b/lib/trackman/utility/configuration.rb @@ -20,7 +20,6 @@ def setup raise Trackman::Errors::ConfigSetupError, "Your heroku version is too low, trackman requires '~> 2.26'." unless is_heroku_valid rename_configs add_configs - puts "Done!" end def get_version diff --git a/lib/trackman/utility/railtie.rb b/lib/trackman/utility/railtie.rb index 3f84b8d..9488ddd 100644 --- a/lib/trackman/utility/railtie.rb +++ b/lib/trackman/utility/railtie.rb @@ -4,7 +4,7 @@ if ::Rails::VERSION::STRING =~ /^2\.[1-9]/ require './config/environment' Rails.configuration.middleware.use Trackman::Middleware - elsif ::Rails::VERSION::STRING =~ /^[3-9]\.[0-9]/ + elsif ::Rails::VERSION::STRING =~ /^3\.[1-9]/ || ::Rails::VERSION::STRING =~ /^[4-9]\.[0-9]/ require 'generators/controller/controller_generator' module Trackman class Railtie < Rails::Railtie @@ -20,4 +20,4 @@ class Railtie < Rails::Railtie end end end -end +end \ No newline at end of file diff --git a/lib/trackman/version.rb b/lib/trackman/version.rb index 00002fa..eeb7a8f 100644 --- a/lib/trackman/version.rb +++ b/lib/trackman/version.rb @@ -1,3 +1,3 @@ module Trackman - VERSION = "0.6.12" + VERSION = "0.6.13" end diff --git a/rails_generators/trackman_controller/trackman_controller_generator.rb b/rails_generators/trackman_controller/trackman_controller_generator.rb index 2b11a11..5876298 100644 --- a/rails_generators/trackman_controller/trackman_controller_generator.rb +++ b/rails_generators/trackman_controller/trackman_controller_generator.rb @@ -41,4 +41,4 @@ def route_doc show_as_comments = false doc end -end \ No newline at end of file +end diff --git a/rails_generators/trackman_tasks/templates/trackman.rake b/rails_generators/trackman_tasks/templates/trackman.rake index 9bf2c4a..35a5aba 100644 --- a/rails_generators/trackman_tasks/templates/trackman.rake +++ b/rails_generators/trackman_tasks/templates/trackman.rake @@ -12,3 +12,17 @@ namespace :trackman do Trackman::Utility::Configuration.new(:app => args[:app]).setup end end + +if Rake::Task.task_defined?("assets:precompile:nondigest") + Rake::Task["assets:precompile:nondigest"].enhance do + STDOUT.puts "Trackman: autosyncing..." + Trackman::Assets::Asset.autosync + STDOUT.puts "Trackman: done." +end +elsif Rake::Task.task_defined?("assets:precompile") + Rake::Task["assets:precompile"].enhance do + STDOUT.puts "Trackman: autosyncing..." + Trackman::Assets::Asset.autosync + STDOUT.puts "Trackman: done." + end +end diff --git a/spec/helpers/app_creator.rb b/spec/helpers/app_creator.rb index 8b47fb7..18b30c0 100644 --- a/spec/helpers/app_creator.rb +++ b/spec/helpers/app_creator.rb @@ -36,4 +36,4 @@ def self.reset end end end -end \ No newline at end of file +end diff --git a/spec/scaffold_spec.rb b/spec/scaffold_spec.rb index f1ae609..3534865 100644 --- a/spec/scaffold_spec.rb +++ b/spec/scaffold_spec.rb @@ -152,4 +152,4 @@ def self.clean html.should include('bobby') html.should include('johnny') end -end \ No newline at end of file +end diff --git a/spec/test_data/application.css b/spec/test_data/application.css new file mode 100644 index 0000000..e69de29 diff --git a/spec/test_data/sample_with_link.html b/spec/test_data/sample_with_link.html new file mode 100644 index 0000000..9663dd6 --- /dev/null +++ b/spec/test_data/sample_with_link.html @@ -0,0 +1,6 @@ + + + + + +