spree_essentials 0.4.0.rc2 → 0.4.0.rc3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. data/.gitignore +10 -0
  2. data/.travis.yml +11 -0
  3. data/CHANGELOG.md +125 -0
  4. data/Gemfile +6 -0
  5. data/README.md +79 -112
  6. data/Versionfile +7 -0
  7. data/app/assets/javascripts/{date.js → admin/date.js} +0 -0
  8. data/app/assets/javascripts/{jquery.autodate.js → admin/jquery.autodate.js} +0 -0
  9. data/app/assets/javascripts/{jquery.markitup.js → admin/jquery.markitup.js} +1 -1
  10. data/app/assets/javascripts/{markdown.set.js → admin/markdown.set.js} +0 -0
  11. data/app/assets/javascripts/admin/spree_essentials.js +1 -0
  12. data/app/assets/stylesheets/{markitup.css.erb → admin/markitup.css.erb} +5 -0
  13. data/app/assets/stylesheets/admin/spree_essentials.css +3 -0
  14. data/app/controllers/spree/admin/markdown_controller.rb +1 -1
  15. data/app/controllers/spree/admin/uploads_controller.rb +0 -4
  16. data/app/helpers/spree/admin/spree_essentials_helper.rb +16 -10
  17. data/app/models/spree/upload.rb +5 -3
  18. data/app/overrides/admin/spree_essentials.rb +13 -0
  19. data/app/views/spree/admin/shared/_contents_sub_menu.html.erb +9 -7
  20. data/app/views/spree/admin/uploads/edit.html.erb +0 -2
  21. data/app/views/spree/admin/uploads/index.html.erb +0 -1
  22. data/app/views/spree/admin/uploads/new.html.erb +0 -2
  23. data/config/routes.rb +5 -4
  24. data/{lib/generators/templates/db/migrate/add_attachment_file_size_to_assets.rb → db/migrate/20120306185618_add_attachment_file_size_to_assets.rb} +0 -0
  25. data/lib/generators/spree_essentials/install_generator.rb +16 -6
  26. data/lib/spree_essentials.rb +5 -24
  27. data/lib/spree_essentials/engine.rb +25 -0
  28. data/lib/spree_essentials/{test_helper.rb → testing/integration_case.rb} +13 -30
  29. data/lib/spree_essentials/testing/test_helper.rb +30 -0
  30. data/lib/spree_essentials/version.rb +1 -1
  31. data/spree_essentials.gemspec +34 -0
  32. data/test/dummy_hooks/after_migrate.rb.sample +1 -0
  33. data/test/dummy_hooks/before_migrate.rb +30 -0
  34. data/test/dummy_hooks/templates/admin/all.css +3 -0
  35. data/test/dummy_hooks/templates/admin/all.js +1 -0
  36. data/test/dummy_hooks/templates/spree_user_error_fix.rb +3 -0
  37. data/test/dummy_hooks/templates/store/all.css +3 -0
  38. data/test/dummy_hooks/templates/store/all.js +1 -0
  39. data/test/dummy_hooks/templates/store/screen.css +749 -0
  40. data/test/integration/spree/admin/extension_integration_test.rb +50 -0
  41. data/test/integration/spree/admin/markdown_integration_test.rb +50 -0
  42. data/test/integration/spree/admin/upload_integration_test.rb +85 -0
  43. data/test/integration_test_helper.rb +2 -0
  44. data/test/spree_essential_example/README.md +3 -0
  45. data/test/spree_essential_example/app/controllers/spree/admin/examples_controller.rb +26 -0
  46. data/test/spree_essential_example/app/models/spree/example.rb +2 -0
  47. data/test/spree_essential_example/app/views/spree/admin/examples/_form.html.erb +21 -0
  48. data/test/spree_essential_example/app/views/spree/admin/examples/edit.html.erb +12 -0
  49. data/test/spree_essential_example/app/views/spree/admin/examples/index.html.erb +26 -0
  50. data/test/spree_essential_example/app/views/spree/admin/examples/new.html.erb +13 -0
  51. data/test/spree_essential_example/app/views/spree/admin/examples/show.html.erb +8 -0
  52. data/test/spree_essential_example/config/routes.rb +5 -0
  53. data/test/spree_essential_example/db/migrate/20120307043727_create_spree_examples.rb +12 -0
  54. data/test/spree_essential_example/lib/generators/spree_essentials/example_generator.rb +13 -0
  55. data/test/spree_essential_example/lib/spree_essential_example.rb +18 -0
  56. data/test/spree_essential_example/lib/spree_essential_example/engine.rb +21 -0
  57. data/test/spree_essential_example/lib/spree_essential_example/version.rb +3 -0
  58. data/test/spree_essential_example/spree_essential_example.gemspec +23 -0
  59. data/test/support/files/1.gif +0 -0
  60. data/test/support/files/1.jpg +0 -0
  61. data/test/support/files/1.png +0 -0
  62. data/test/support/files/2.gif +0 -0
  63. data/test/support/files/2.jpg +0 -0
  64. data/test/support/files/2.png +0 -0
  65. data/test/support/files/3.gif +0 -0
  66. data/test/support/files/3.jpg +0 -0
  67. data/test/support/files/3.png +0 -0
  68. data/test/support/files/test.pdf +0 -0
  69. data/test/support/files/test.zip +0 -0
  70. data/test/test_helper.rb +14 -0
  71. data/test/unit/spree/asset_test.rb +18 -0
  72. data/test/unit/spree/extension_test.rb +33 -0
  73. data/test/unit/spree/helpers/admin/spree_essentials_helper_test.rb +38 -0
  74. data/test/unit/spree/upload_test.rb +52 -0
  75. data/test/unit/validators/datetime_validator_test.rb +29 -0
  76. metadata +144 -47
  77. data/app/overrides/spree_essentials.rb +0 -5
  78. data/lib/generators/essentials_base.rb +0 -32
@@ -0,0 +1 @@
1
+ //= require_tree .
@@ -2,6 +2,11 @@
2
2
  // markItUp! Universal MarkUp Engine, JQuery plugin
3
3
  // By Jay Salvat - http://markitup.jaysalvat.com/
4
4
  // ------------------------------------------------------------------*/
5
+
6
+ .markdown-helper {
7
+ margin-left: 1em;
8
+ }
9
+
5
10
  .markItUp * {
6
11
  margin:0px; padding:0px;
7
12
  outline:none;
@@ -0,0 +1,3 @@
1
+ /*
2
+ *= require_tree ./
3
+ */
@@ -4,4 +4,4 @@ class Spree::Admin::MarkdownController < Spree::Admin::BaseController
4
4
  render :text => RDiscount.new(params[:data].to_s).to_html
5
5
  end
6
6
 
7
- end
7
+ end
@@ -6,10 +6,6 @@ class Spree::Admin::UploadsController < Spree::Admin::ResourceController
6
6
 
7
7
  private
8
8
 
9
- def translated_object_name
10
- I18n.t("upload.model_name")
11
- end
12
-
13
9
  def collection
14
10
  params[:search] ||= {}
15
11
  params[:search][:meta_sort] ||= "created_at.desc"
@@ -1,25 +1,31 @@
1
1
  module Spree::Admin::SpreeEssentialsHelper
2
2
 
3
+ def inside_contents_tab?
4
+ @inside_contents_tab ||= !request.fullpath.scan(Regexp.new(extension_routes.join("|"))).empty?
5
+ end
6
+
3
7
  def contents_tab
4
- routes = SpreeEssentials.essentials.map do |key, cls|
5
- route = cls.tab[:route] || "admin_#{key}"
6
- send("#{route}_path") rescue "##{key}"
7
- end
8
- routes.push admin_uploads_path
9
- cls = request.path.scan(Regexp.new(routes.join("|"))).empty? ? nil : 'selected'
10
- content_tag :li, :class => cls do
11
- link_to I18n.t('spree.admin.shared.contents_tab.content'), routes.first
8
+ content_tag :li, :class => inside_contents_tab? ? 'selected' : nil do
9
+ link_to I18n.t('spree.admin.shared.contents_tab.content'), extension_routes.first
12
10
  end
13
11
  end
14
12
 
15
13
  def markdown_helper
16
- content_tag('em', :class => 'small') do
14
+ content_tag('em', :class => 'small markdown-helper') do
17
15
  [
18
- "&nbsp;",
19
16
  t('essentials.parsed_with'),
20
17
  link_to("Markdown", "http://daringfireball.net/projects/markdown/basics", :onclick => 'window.open(this.href); return false')
21
18
  ].join(" ").html_safe
22
19
  end
23
20
  end
21
+
22
+ private
23
+
24
+ def extension_routes
25
+ @extension_routes ||= SpreeEssentials.essentials.map { |key, cls|
26
+ route = cls.tab[:route] || "admin_#{key}"
27
+ send("#{route}_path") rescue "##{key}"
28
+ }.push(spree.admin_uploads_path)
29
+ end
24
30
 
25
31
  end
@@ -5,9 +5,11 @@ class Spree::Upload < ::Spree::Asset
5
5
  validate :no_attachement_errors
6
6
 
7
7
  has_attached_file :attachment,
8
- :styles => Proc.new{ |clip| clip.instance.attachment_sizes },
9
- :default_style => :medium
10
-
8
+ :styles => Proc.new{ |clip| clip.instance.attachment_sizes },
9
+ :default_style => :medium,
10
+ :url => "/spree/uploads/:id/:style/:basename.:extension",
11
+ :path => ":rails_root/public/spree/uploads/:id/:style/:basename.:extension"
12
+
11
13
  def image_content?
12
14
  attachment_content_type.match(/\/(jpeg|png|gif|tiff|x-photoshop)/)
13
15
  end
@@ -0,0 +1,13 @@
1
+ # Adds the Content button to the admin tabs
2
+ Deface::Override.new(:virtual_path => "spree/layouts/admin",
3
+ :name => "spree_essential_admin_tabs",
4
+ :insert_bottom => "[data-hook='admin_tabs'], #admin_tabs[data-hook]",
5
+ :partial => "spree/admin/shared/contents_tab",
6
+ :disabled => false)
7
+
8
+ # Adds the contents menu. Inside the contents sub menu we ensure it's needed
9
+ Deface::Override.new(:virtual_path => "spree/layouts/admin",
10
+ :name => "spree_essential_contents_menu",
11
+ :insert_top => "#sub-menu[data-hook]",
12
+ :partial => "spree/admin/shared/contents_sub_menu",
13
+ :disabled => false)
@@ -1,8 +1,10 @@
1
- <% content_for :sub_menu do %>
2
- <ul id="sub_nav" data-hook="essentials_sub_nav">
3
- <% SpreeEssentials.essentials.each_pair do |name, cls| %>
4
- <%= tab *cls.sub_tab if defined?(cls.sub_tab) %>
5
- <% end %>
6
- <%= tab :uploads, :label => 'spree.admin.subnav.uploads' %>
7
- </ul>
1
+ <% if inside_contents_tab? %>
2
+ <% content_for :sub_menu do %>
3
+ <ul id="sub_nav" data-hook="essentials_sub_nav">
4
+ <% SpreeEssentials.essentials.each_pair do |name, cls| %>
5
+ <%= tab *cls.sub_tab if defined?(cls.sub_tab) %>
6
+ <% end %>
7
+ <%= tab :uploads, :label => 'spree.admin.subnav.uploads' %>
8
+ </ul>
9
+ <% end %>
8
10
  <% end %>
@@ -1,5 +1,3 @@
1
- <%= render :partial => "spree/admin/shared/contents_sub_menu" %>
2
-
3
1
  <h1><%= t('.edit_upload') %></h1>
4
2
 
5
3
  <% if @upload.try(:errors).present? %>
@@ -1,4 +1,3 @@
1
- <%= render :partial => "spree/admin/shared/contents_sub_menu" %>
2
1
 
3
2
  <h1><%= t('.listing_uploads') %></h1>
4
3
 
@@ -1,5 +1,3 @@
1
- <%= render :partial => "spree/admin/shared/contents_sub_menu" unless request.xhr? %>
2
-
3
1
  <h3><%= t('.new_upload') %></h3>
4
2
 
5
3
  <% if @upload.try(:errors).present? %>
@@ -1,6 +1,7 @@
1
+ #Rails.application
1
2
  Spree::Core::Engine.routes.draw do
2
- namespace :admin do
3
- post "/markdown/preview" => "markdown#preview"
4
- resources :uploads
5
- end
3
+ namespace :admin do
4
+ post "/markdown/preview" => "markdown#preview", :as => :markdown_preview
5
+ resources :uploads
6
+ end
6
7
  end
@@ -1,16 +1,26 @@
1
- require 'generators/essentials_base'
2
-
3
1
  module SpreeEssentials
4
2
  module Generators
5
- class InstallGenerator < SpreeEssentials::Generators::EssentialsBase
3
+ class InstallGenerator < Rails::Generators::Base
6
4
 
7
5
  desc "Installs required migrations for spree_essentials"
8
- source_root File.expand_path("../../templates/db/migrate", __FILE__)
6
+
7
+ class_option :add_stylesheets, :type => :boolean, :default => true, :banner => 'Append spree_essentials to admin/all.css'
8
+ class_option :add_javascripts, :type => :boolean, :default => true, :banner => 'Append spree_essentials to admin/all.js'
9
9
 
10
10
  def copy_migrations
11
- migration_template "add_attachment_file_size_to_assets.rb", "db/migrate/add_attachment_file_size_to_assets.rb"
11
+ rake "spree_essentials:install:migrations"
12
+ end
13
+
14
+ def append_stylesheets
15
+ return unless options[:add_stylesheets]
16
+ gsub_file "app/assets/stylesheets/admin/all.css", "*/", "*= require admin/spree_essentials\n*/"
17
+ end
18
+
19
+ def append_javascripts
20
+ return unless options[:add_javascripts]
21
+ append_file "app/assets/javascripts/admin/all.js", "//= require admin/spree_essentials"
12
22
  end
13
23
 
14
24
  end
15
25
  end
16
- end
26
+ end
@@ -1,5 +1,8 @@
1
- require 'spree_core'
2
- require 'rdiscount'
1
+ require "spree_core"
2
+ require "rdiscount"
3
+
4
+ require "spree_essentials/version"
5
+ require "spree_essentials/engine"
3
6
 
4
7
  module SpreeEssentials
5
8
 
@@ -22,26 +25,4 @@ module SpreeEssentials
22
25
 
23
26
  end
24
27
 
25
- class Engine < Rails::Engine
26
-
27
- config.autoload_paths += %W(#{config.root}/lib)
28
-
29
- initializer :assets do |config|
30
- Rails.application.config.assets.precompile += %w( markitup.css date.js jquery.autodate.js jquery.markitup.js markdown.set.js )
31
- end
32
-
33
- config.to_prepare do
34
- #loads application's model / class decorators
35
- Dir.glob File.expand_path("../../app/**/*_decorator.rb", __FILE__) do |c|
36
- Rails.configuration.cache_classes ? require(c) : load(c)
37
- end
38
-
39
- #loads application's deface view overrides
40
- Dir.glob File.expand_path("../../app/overrides/*.rb", __FILE__) do |c|
41
- Rails.application.config.cache_classes ? require(c) : load(c)
42
- end
43
- end
44
-
45
- end
46
-
47
28
  end
@@ -0,0 +1,25 @@
1
+ module SpreeEssentials
2
+ class Engine < Rails::Engine
3
+
4
+ engine_name "spree_essentials"
5
+
6
+ config.autoload_paths += %W(#{config.root}/lib)
7
+
8
+ initializer :assets do |config|
9
+ Rails.application.config.assets.precompile += %w( admin/markitup.css admin/date.js admin/jquery.autodate.js admin/jquery.markitup.js admin/markdown.set.js )
10
+ end
11
+
12
+ config.to_prepare do
13
+ #loads application's model / class decorators
14
+ Dir.glob File.expand_path("../../../app/**/*_decorator.rb", __FILE__) do |c|
15
+ Rails.configuration.cache_classes ? require(c) : load(c)
16
+ end
17
+
18
+ #loads application's deface view overrides
19
+ Dir.glob File.expand_path("../../../app/overrides/**/*.rb", __FILE__) do |c|
20
+ Rails.application.config.cache_classes ? require(c) : load(c)
21
+ end
22
+ end
23
+
24
+ end
25
+ end
@@ -1,37 +1,13 @@
1
- require "rails/test_help"
2
- require "shoulda"
3
- require "factory_girl"
4
- require "sqlite3"
5
-
6
- ActionMailer::Base.delivery_method = :test
7
- ActionMailer::Base.perform_deliveries = true
8
- ActionMailer::Base.default_url_options[:host] = "example.com"
9
-
10
- Rails.backtrace_cleaner.remove_silencers!
11
-
12
- # Configure capybara for integration testing
13
1
  require "capybara/rails"
14
2
  require "selenium/webdriver"
15
3
 
16
- Capybara.default_driver = :selenium
17
- Capybara.default_selector = :css
18
-
4
+ class SpreeEssentials::IntegrationCase < ActiveSupport::TestCase
19
5
 
20
- # Define a bare test case to use with Capybara
21
- class ActiveSupport::IntegrationCase < ActiveSupport::TestCase
22
-
23
6
  include Capybara::DSL
24
- include Spree::Core::Engine.routes.url_helpers
25
-
26
-
27
- # Extreme hax! wtf is this for anyways.. and why is it erroring?
28
- def testmail_admin_mail_method_url(*args)
29
- "#wtf"
30
- end
31
- alias :testmail_admin_mail_method_path :testmail_admin_mail_method_url
32
-
33
-
34
7
 
8
+ Capybara.default_driver = :selenium
9
+ Capybara.default_selector = :css
10
+
35
11
  self.use_transactional_fixtures = false
36
12
 
37
13
  # Checks for missing translations after each test
@@ -42,18 +18,25 @@ class ActiveSupport::IntegrationCase < ActiveSupport::TestCase
42
18
  end
43
19
  end
44
20
 
21
+ # By defining this we don't need to depend on spree, just spree_core since the
22
+ # included url helper lives in the spree root
23
+ def spree
24
+ Spree::Core::Engine.routes.url_helpers
25
+ end
26
+
45
27
  # An assertion for ensuring content has made it to the page.
46
28
  #
47
29
  # assert_seen "Site Title"
48
30
  # assert_seen "Peanut Butter Jelly Time", :within => ".post-title h1"
49
31
  #
50
32
  def assert_seen(text, opts={})
33
+ msg = "Should see `#{text}`"
51
34
  if opts[:within]
52
35
  within(opts[:within]) do
53
- assert has_content?(text)
36
+ assert has_content?(text), msg + " within #{opts[:within]}"
54
37
  end
55
38
  else
56
- assert has_content?(text)
39
+ assert has_content?(text), msg
57
40
  end
58
41
  end
59
42
 
@@ -0,0 +1,30 @@
1
+ RAILS_ROOT = ENV["RAILS_ROOT"]
2
+ if RAILS_ROOT.nil?
3
+ puts 'Please specify ENV["RAILS_ROOT"] before `require "spree_essentials/testing/test_helper"`'
4
+ exit
5
+ end
6
+
7
+ @env = File.join(RAILS_ROOT, "config/environment.rb")
8
+ if File.exists?(@env)
9
+ require @env
10
+ else
11
+ puts "#{@env} does not exist! Ensure that ENV[\"RAILS_ROOT\"] exists or try running `bundle exec dummier`"
12
+ exit
13
+ end
14
+
15
+ require "rails/test_help"
16
+ require "shoulda"
17
+ require "paperclip/matchers"
18
+ require "factory_girl"
19
+ require "sqlite3"
20
+ require "ffaker"
21
+
22
+ ActionMailer::Base.delivery_method = :test
23
+ ActionMailer::Base.perform_deliveries = true
24
+ ActionMailer::Base.default_url_options[:host] = "example.com"
25
+
26
+ Rails.backtrace_cleaner.remove_silencers!
27
+
28
+ class ActiveSupport::TestCase
29
+ extend Paperclip::Shoulda::Matchers
30
+ end
@@ -1,3 +1,3 @@
1
1
  module SpreeEssentials
2
- VERSION = "0.4.0.rc2"
2
+ VERSION = "0.4.0.rc3"
3
3
  end
@@ -0,0 +1,34 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "spree_essentials/version"
4
+
5
+ Gem::Specification.new do |s|
6
+
7
+ s.name = "spree_essentials"
8
+ s.version = SpreeEssentials::VERSION
9
+ s.platform = Gem::Platform::RUBY
10
+ s.authors = ["Spencer Steffen"]
11
+ s.email = ["spencer@citrusme.com"]
12
+ s.homepage = "https://github.com/citrus/spree_essentials"
13
+ s.summary = %q{Spree Essentials provides a base for several other Spree Commerce extensions. See readme for details...}
14
+ s.description = %q{Spree Essentials provides a base for several other Spree Commerce extensions. The idea is to provide other extensions with common functionality such as an asset-upload interface, a markdown editor, and a common admin-navigation tab.}
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+
19
+ s.require_paths = ["lib"]
20
+
21
+ # Spree
22
+ s.add_runtime_dependency('spree_core', '~> 1.0.0')
23
+ s.add_runtime_dependency('rdiscount', '~> 1.6.8')
24
+
25
+ # Development
26
+ s.add_development_dependency('shoulda', '~> 3.0.0')
27
+ s.add_development_dependency('dummier', '~> 0.3.0')
28
+ s.add_development_dependency('factory_girl', '~> 2.6.0')
29
+ s.add_development_dependency('capybara', '~> 1.1.2')
30
+ s.add_development_dependency('sqlite3', '~> 1.3.4')
31
+
32
+ # s.add_development_dependency('simplecov', '~> 0.6.1')
33
+
34
+ end
@@ -0,0 +1 @@
1
+ rake "db:migrate db:seed", :env => "development"
@@ -0,0 +1,30 @@
1
+ # Require spree_essential_example in config/application.rb
2
+ gsub_file "config/application.rb", 'require "spree_essentials"', %(require "spree_essentials"
3
+ require "spree_essential_example")
4
+
5
+ # Install spree's migrations
6
+ rake "spree:install:migrations"
7
+
8
+ # Mount the Spree::Core routes
9
+ insert_into_file File.join('config', 'routes.rb'), :after => "Application.routes.draw do\n" do
10
+ " # Mount Spree's routes\n mount Spree::Core::Engine, :at => '/'\n"
11
+ end
12
+
13
+ # Fix uninitialized constant Spree::User::DestroyWithOrdersError
14
+ template "spree_user_error_fix.rb", "config/initializers/spree_user_error_fix.rb"
15
+
16
+ # remove all stylesheets except core
17
+ %w(admin store).each do |ns|
18
+ template "#{ns}/all.js", "app/assets/javascripts/#{ns}/all.js", :force => true
19
+ template "#{ns}/all.css", "app/assets/stylesheets/#{ns}/all.css", :force => true
20
+ end
21
+
22
+ # Fix sass load error by using the converted css file
23
+ template "store/screen.css", "app/assets/stylesheets/store/screen.css"
24
+
25
+ # Enable forgery_protection since we need AUTH_TOKEN to be defined to avoid JS errors
26
+ gsub_file "config/environments/test.rb", "forgery_protection = false", "forgery_protection = true"
27
+
28
+ # Install spree essentials & example extension
29
+ run "bundle exec rails g spree_essentials:install"
30
+ run "bundle exec rails g spree_essentials:example"
@@ -0,0 +1,3 @@
1
+ /*
2
+ *= require admin/spree_core
3
+ */
@@ -0,0 +1 @@
1
+ //= require admin/spree_core