trado_googlemerchant_module 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/Rakefile +34 -0
  4. data/app/controllers/trado_googlemerchant_module/feeds_controller.rb +19 -0
  5. data/app/views/admin/_product_fields.html.erb +24 -0
  6. data/app/views/feeds/rss.rss.builder +25 -0
  7. data/app/views/feeds/xml.xml.builder +25 -0
  8. data/app/views/layouts/rss.rss.erb +4 -0
  9. data/app/views/layouts/xml.xml.erb +3 -0
  10. data/config/routes.rb +5 -0
  11. data/lib/generators/templates/helper.rb +6 -0
  12. data/lib/generators/templates/migration.rb +11 -0
  13. data/lib/generators/trado_googlemerchant_module/install_generator.rb +41 -0
  14. data/lib/tasks/trado_googlemerchant_module_tasks.rake +4 -0
  15. data/lib/trado_googlemerchant_module.rb +8 -0
  16. data/lib/trado_googlemerchant_module/active_record.rb +13 -0
  17. data/lib/trado_googlemerchant_module/engine.rb +6 -0
  18. data/lib/trado_googlemerchant_module/version.rb +3 -0
  19. data/test/dummy/README.rdoc +28 -0
  20. data/test/dummy/Rakefile +6 -0
  21. data/test/dummy/app/assets/javascripts/application.js +13 -0
  22. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  23. data/test/dummy/app/controllers/application_controller.rb +5 -0
  24. data/test/dummy/app/helpers/application_helper.rb +2 -0
  25. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  26. data/test/dummy/bin/bundle +3 -0
  27. data/test/dummy/bin/rails +4 -0
  28. data/test/dummy/bin/rake +4 -0
  29. data/test/dummy/bin/setup +29 -0
  30. data/test/dummy/config.ru +4 -0
  31. data/test/dummy/config/application.rb +26 -0
  32. data/test/dummy/config/boot.rb +5 -0
  33. data/test/dummy/config/database.yml +25 -0
  34. data/test/dummy/config/environment.rb +5 -0
  35. data/test/dummy/config/environments/development.rb +41 -0
  36. data/test/dummy/config/environments/production.rb +79 -0
  37. data/test/dummy/config/environments/test.rb +42 -0
  38. data/test/dummy/config/initializers/assets.rb +11 -0
  39. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  40. data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
  41. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  42. data/test/dummy/config/initializers/inflections.rb +16 -0
  43. data/test/dummy/config/initializers/mime_types.rb +4 -0
  44. data/test/dummy/config/initializers/session_store.rb +3 -0
  45. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  46. data/test/dummy/config/locales/en.yml +23 -0
  47. data/test/dummy/config/routes.rb +56 -0
  48. data/test/dummy/config/secrets.yml +22 -0
  49. data/test/dummy/public/404.html +67 -0
  50. data/test/dummy/public/422.html +67 -0
  51. data/test/dummy/public/500.html +66 -0
  52. data/test/dummy/public/favicon.ico +0 -0
  53. data/test/test_helper.rb +20 -0
  54. data/test/trado_googlemerchant_module_test.rb +7 -0
  55. metadata +149 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b02061cb3403db9d03c091f7aaa0e76457d68ca3
4
+ data.tar.gz: 685ea3dc1bf94f65f95b6caa97d7f734422a1012
5
+ SHA512:
6
+ metadata.gz: 04da7f8ee7e84637edd39d21f9657d396d9fd3cf2e99f738e645f02945c7d9d7697d69390cce3bcab2ea206cda7df0e080038336f903ccde8aba479fbc09ef8f
7
+ data.tar.gz: fd46272f9bc0478c195c7f7404e0034ff5ce4ffe888cf63d05b4c4f8cea49d66339826de4b1352f4a9fd67195e6ea11b2f60de7b3612cd9af3213ebc43d9d608
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2016 Tom Dallimore
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,34 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'TradoGooglemerchantModule'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+
18
+
19
+
20
+
21
+
22
+ Bundler::GemHelper.install_tasks
23
+
24
+ require 'rake/testtask'
25
+
26
+ Rake::TestTask.new(:test) do |t|
27
+ t.libs << 'lib'
28
+ t.libs << 'test'
29
+ t.pattern = 'test/**/*_test.rb'
30
+ t.verbose = false
31
+ end
32
+
33
+
34
+ task default: :test
@@ -0,0 +1,19 @@
1
+ class TradoGooglemerchantModule::FeedsController < ApplicationController
2
+ skip_before_action :authenticate_user!
3
+
4
+ def rss
5
+ set_products
6
+ render 'feeds/rss', layout: 'rss'
7
+ end
8
+
9
+ def xml
10
+ set_products
11
+ render 'feeds/xml', layout: 'xml'
12
+ end
13
+
14
+ private
15
+
16
+ def set_products
17
+ @products ||= Product.includes(:skus, :category).active.published
18
+ end
19
+ end
@@ -0,0 +1,24 @@
1
+ <div class="threecol">
2
+ <h3>Google Merchant</h3>
3
+ <p>Set the product brand and category for your Google Merchant product feed.</p>
4
+ </div>
5
+ <div class="ninecol last">
6
+ <fieldset class="widget widget-content widget-last widget-dynamic-top-margin">
7
+ <div class="row">
8
+ <div class="twelvecol">
9
+ <div class="form-group">
10
+ <%= f.label 'Brand' %>
11
+ <%= f.text_field :googlemerchant_brand, :class => 'form-control' %>
12
+ </div>
13
+ </div>
14
+ </div>
15
+ <div class="row">
16
+ <div class="twelvecol">
17
+ <div class="form-group form-last">
18
+ <%= f.label 'Category' %>
19
+ <%= f.text_field :googlemerchant_category, :class => 'form-control' %>
20
+ </div>
21
+ </div>
22
+ </div>
23
+ </fieldset>
24
+ </div>
@@ -0,0 +1,25 @@
1
+ xml.channel do
2
+ xml.title "#{Store.settings.name} Google Merchant Product RSS Feed"
3
+ xml.description "#{Store.settings.name} Google Merchant Product RSS Feed"
4
+ xml.link root_url
5
+ xml.language 'en'
6
+
7
+ for product in @products
8
+ next unless (product.googlemerchant_brand.present? && product.googlemerchant_category.present?)
9
+ xml.item do
10
+ xml.tag!("g:id", product.sku)
11
+ xml.tag!("g:title", product.name)
12
+ xml.tag!("g:description", product.meta_description)
13
+ xml.tag!("g:link", category_product_url(product.category, product))
14
+ xml.tag!("g:image_link", product.attachments.first.file.large.url)
15
+ xml.tag!("g:condition", "new")
16
+ xml.tag!("g:availability", product.in_stock? ? "in stock" : "out of stock")
17
+ xml.tag!("g:price", "#{product.first_available_sku.price} #{Store.settings.currency_code}")
18
+
19
+ xml.tag!("g:mpn", product.part_number)
20
+ xml.tag!("g:brand", product.googlemerchant_brand)
21
+ xml.tag!("g:google_product_category", product.googlemerchant_category)
22
+
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,25 @@
1
+ xml.channel do
2
+ xml.title "#{Store.settings.name} Google Merchant Product RSS Feed"
3
+ xml.description "#{Store.settings.name} Google Merchant Product RSS Feed"
4
+ xml.link root_url
5
+ xml.language 'en'
6
+
7
+ for product in @products
8
+ next unless (product.googlemerchant_brand.present? && product.googlemerchant_category.present?)
9
+ xml.item do
10
+ xml.tag!("g:id", product.sku)
11
+ xml.tag!("g:title", product.name)
12
+ xml.tag!("g:description", product.meta_description)
13
+ xml.tag!("g:link", category_product_url(product.category, product))
14
+ xml.tag!("g:image_link", product.attachments.first.file.large.url)
15
+ xml.tag!("g:condition", "new")
16
+ xml.tag!("g:availability", product.in_stock? ? "in stock" : "out of stock")
17
+ xml.tag!("g:price", "#{product.first_available_sku.price} #{Store.settings.currency_code}")
18
+
19
+ xml.tag!("g:mpn", product.part_number)
20
+ xml.tag!("g:brand", product.googlemerchant_brand)
21
+ xml.tag!("g:google_product_category", product.googlemerchant_category)
22
+
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0"?>
2
+ <rss xmlns:g="http://base.google.com/ns/1.0" version="2.0">
3
+ <%= yield %>
4
+ </rss>
@@ -0,0 +1,3 @@
1
+ <xml version="1.0" xmlns:g="http://base.google.com/ns/1.0">
2
+ <%= yield %>
3
+ </xml>
data/config/routes.rb ADDED
@@ -0,0 +1,5 @@
1
+ TradoGooglemerchantModule::Engine.routes.draw do
2
+ %w( xml rss ).each do |feed_type|
3
+ get 'feed', to: "trado_googlemerchant_module/feeds##{feed_type}", format: feed_type
4
+ end
5
+ end
@@ -0,0 +1,6 @@
1
+ module GooglemerchantHelper
2
+
3
+ def googlemerchant_product_fields f
4
+ render 'admin/product_fields', format: [:html], f: f
5
+ end
6
+ end
@@ -0,0 +1,11 @@
1
+ class AddGooglemerchantAttributes < ActiveRecord::Migration
2
+ def self.up
3
+ add_column :products, :googlemerchant_brand, :string
4
+ add_column :products, :googlemerchant_category, :string
5
+ end
6
+
7
+ def self.down
8
+ remove_column :products, :googlemerchant_brand, :string
9
+ remove_column :products, :googlemerchant_category, :string
10
+ end
11
+ end
@@ -0,0 +1,41 @@
1
+ module TradoGooglemerchantModule
2
+ module Generators
3
+ class InstallGenerator < Rails::Generators::Base
4
+ source_root File.expand_path("../../templates", __FILE__)
5
+
6
+ def copy_migration
7
+ unless googlemerchant_migration_already_exists?
8
+ timestamp_number = Time.now.utc.strftime("%Y%m%d%H%M%S").to_i
9
+ copy_file "migration.rb", "db/migrate/#{timestamp_number}_add_googlemerchant_attributes.rb"
10
+ end
11
+ end
12
+
13
+ def copy_helper
14
+ template "helper.rb", "app/helpers/googlemerchant_helper.rb"
15
+ end
16
+
17
+ def setup_routes
18
+ route_content = <<-CONTENT
19
+
20
+ mount TradoGooglemerchantModule::Engine => '/google_merchant'
21
+ CONTENT
22
+ inject_into_file "config/routes.rb", route_content, after: "Trado::Application.routes.draw do"
23
+ end
24
+
25
+ def assign_model_concerns
26
+ googlemerchant_content = <<-CONTENT
27
+
28
+ has_googlemerchant
29
+ CONTENT
30
+
31
+ inject_into_file "app/models/product.rb", googlemerchant_content, after: "class Product < ActiveRecord::Base"
32
+ end
33
+
34
+ private
35
+
36
+ def googlemerchant_migration_already_exists?
37
+ Dir.glob("#{File.join(destination_root, File.join("db", "migrate"))}/[0-9]*_*.rb").grep(/\d+_add_googlemerchant_attributes.rb$/).first
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :trado_googlemerchant_module do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,8 @@
1
+ module TradoGooglemerchantModule
2
+ end
3
+
4
+ require 'trado_googlemerchant_module/engine'
5
+ require 'trado_googlemerchant_module/version'
6
+ require 'trado_googlemerchant_module/active_record'
7
+
8
+ ActiveRecord::Base.send(:include, TradoGooglemerchantModule::ActiveRecord)
@@ -0,0 +1,13 @@
1
+ module TradoGooglemerchantModule
2
+ module ActiveRecord
3
+ extend ActiveSupport::Concern
4
+
5
+ module ClassMethods
6
+ def has_googlemerchant
7
+ attr_accessible :googlemerchant_brand, :googlemerchant_category
8
+
9
+ validates :googlemerchant_category, :googlemerchant_brand, presence: true, :if => :published?
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,6 @@
1
+ require 'rails'
2
+
3
+ module TradoGooglemerchantModule
4
+ class Engine < Rails::Engine
5
+ end
6
+ end
@@ -0,0 +1,3 @@
1
+ module TradoGooglemerchantModule
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,28 @@
1
+ == README
2
+
3
+ This README would normally document whatever steps are necessary to get the
4
+ application up and running.
5
+
6
+ Things you may want to cover:
7
+
8
+ * Ruby version
9
+
10
+ * System dependencies
11
+
12
+ * Configuration
13
+
14
+ * Database creation
15
+
16
+ * Database initialization
17
+
18
+ * How to run the test suite
19
+
20
+ * Services (job queues, cache servers, search engines, etc.)
21
+
22
+ * Deployment instructions
23
+
24
+ * ...
25
+
26
+
27
+ Please feel free to use a different markup language if you do not plan to run
28
+ <tt>rake doc:app</tt>.
@@ -0,0 +1,6 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require File.expand_path('../config/application', __FILE__)
5
+
6
+ Rails.application.load_tasks
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any styles
10
+ * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
+ * file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,5 @@
1
+ class ApplicationController < ActionController::Base
2
+ # Prevent CSRF attacks by raising an exception.
3
+ # For APIs, you may want to use :null_session instead.
4
+ protect_from_forgery with: :exception
5
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Dummy</title>
5
+ <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
6
+ <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
3
+ load Gem.bin_path('bundler', 'bundle')
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
3
+ require_relative '../config/boot'
4
+ require 'rails/commands'
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative '../config/boot'
3
+ require 'rake'
4
+ Rake.application.run
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ require 'pathname'
3
+
4
+ # path to your application root.
5
+ APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
6
+
7
+ Dir.chdir APP_ROOT do
8
+ # This script is a starting point to setup your application.
9
+ # Add necessary setup steps to this file:
10
+
11
+ puts "== Installing dependencies =="
12
+ system "gem install bundler --conservative"
13
+ system "bundle check || bundle install"
14
+
15
+ # puts "\n== Copying sample files =="
16
+ # unless File.exist?("config/database.yml")
17
+ # system "cp config/database.yml.sample config/database.yml"
18
+ # end
19
+
20
+ puts "\n== Preparing database =="
21
+ system "bin/rake db:setup"
22
+
23
+ puts "\n== Removing old logs and tempfiles =="
24
+ system "rm -f log/*"
25
+ system "rm -rf tmp/cache"
26
+
27
+ puts "\n== Restarting application server =="
28
+ system "touch tmp/restart.txt"
29
+ end
@@ -0,0 +1,4 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
+ run Rails.application