Skip to content

Commit

Permalink
Some cleanup and spec fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeff Dutil authored and Jeff Dutil committed Dec 1, 2014
1 parent 09d1fb7 commit 109180f
Show file tree
Hide file tree
Showing 16 changed files with 113 additions and 202 deletions.
65 changes: 0 additions & 65 deletions core/app/helpers/spree/base_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,6 @@ def current_spree_page?(url)
return false
end

def link_to_cart(text = nil)
text = text ? h(text) : Spree.t('cart')
css_class = nil

if simple_current_order.nil? or simple_current_order.item_count.zero?
text = "#{text}: (#{Spree.t('empty')})"
css_class = 'empty'
else
text = "#{text}: (#{simple_current_order.item_count}) <span class='amount'>#{simple_current_order.display_total.to_html}</span>"
css_class = 'full'
end

link_to text.html_safe, spree.cart_path, :class => "cart-info #{css_class}"
end

# human readable list of variant options
def variant_options(v, options={})
v.options_text
Expand Down Expand Up @@ -67,56 +52,6 @@ def logo(image_path=Spree::Config[:logo])
link_to image_tag(image_path), spree.root_path
end

def flash_messages(opts = {})
ignore_types = ["order_completed"].concat(Array(opts[:ignore_types]).map(&:to_s) || [])

flash.each do |msg_type, text|
unless ignore_types.include?(msg_type)
concat(content_tag :div, text, class: "flash #{msg_type}")
end
end
nil
end

def breadcrumbs(taxon, separator="&nbsp;&raquo;&nbsp;", breadcrumb_class="inline")
return "" if current_page?("/") || taxon.nil?

crumbs = [[Spree.t(:home), spree.root_path]]

if taxon
crumbs << [Spree.t(:products), products_path]
crumbs += taxon.ancestors.collect { |a| [a.name, spree.nested_taxons_path(a.permalink)] } unless taxon.ancestors.empty?
crumbs << [taxon.name, spree.nested_taxons_path(taxon.permalink)]
else
crumbs << [Spree.t(:products), products_path]
end

separator = raw(separator)

crumbs.map! do |crumb|
content_tag(:li, itemscope:"itemscope", itemtype:"http://data-vocabulary.org/Breadcrumb") do
link_to(crumb.last, itemprop: "url") do
content_tag(:span, crumb.first, itemprop: "title")
end + (crumb == crumbs.last ? '' : separator)
end
end

content_tag(:nav, content_tag(:ul, raw(crumbs.map(&:mb_chars).join), class: breadcrumb_class), id: 'breadcrumbs', class: 'sixteen columns')
end

def taxons_tree(root_taxon, current_taxon, max_level = 1)
return '' if max_level < 1 || root_taxon.children.empty?
content_tag :ul, class: 'taxons-list' do
root_taxon.children.map do |taxon|
css_class = (current_taxon && current_taxon.self_and_ancestors.include?(taxon)) ? 'current' : nil
content_tag :li, class: css_class do
link_to(taxon.name, seo_url(taxon)) +
taxons_tree(taxon, current_taxon, max_level - 1)
end
end.join("\n").html_safe
end
end

def available_countries
checkout_zone = Zone.find_by(name: Spree::Config[:checkout_zone])

Expand Down
32 changes: 1 addition & 31 deletions core/spec/helpers/base_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe Spree::BaseHelper, :type => :helper do
describe Spree::BaseHelper, type: :helper do
include Spree::BaseHelper

let(:current_store){ create :store }
Expand Down Expand Up @@ -69,36 +69,6 @@

end

# Regression test for #2034
context "flash_message" do
let(:flash) { {"notice" => "ok", "foo" => "foo", "bar" => "bar"} }

it "should output all flash content" do
flash_messages
html = Nokogiri::HTML(helper.output_buffer)
expect(html.css(".notice").text).to eq("ok")
expect(html.css(".foo").text).to eq("foo")
expect(html.css(".bar").text).to eq("bar")
end

it "should output flash content except one key" do
flash_messages(:ignore_types => :bar)
html = Nokogiri::HTML(helper.output_buffer)
expect(html.css(".notice").text).to eq("ok")
expect(html.css(".foo").text).to eq("foo")
expect(html.css(".bar").text).to be_empty
end

it "should output flash content except some keys" do
flash_messages(:ignore_types => [:foo, :bar])
html = Nokogiri::HTML(helper.output_buffer)
expect(html.css(".notice").text).to eq("ok")
expect(html.css(".foo").text).to be_empty
expect(html.css(".bar").text).to be_empty
expect(helper.output_buffer).to eq("<div class=\"flash notice\">ok</div>")
end
end

context "link_to_tracking" do
it "returns tracking link if available" do
a = link_to_tracking_html(shipping_method: true, tracking: '123', tracking_url: 'http://g.c/?t=123').css('a')
Expand Down
4 changes: 3 additions & 1 deletion frontend/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
## Spree 2.4.0 (unreleased) ##
## Spree 3.0.0 (unreleased) ##

Switched to Bootstrap
37 changes: 5 additions & 32 deletions frontend/README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
# Spree Bootstrap (Frontend)
# Spree Bootstrap Frontend

[![Build Status](https://api.travis-ci.org/200Creative/spree_bootstrap_frontend.png?branch=master)](https://travis-ci.org/200Creative/spree_bootstrap_frontend)
[![Code Climate](https://codeclimate.com/github/200Creative/spree_bootstrap_frontend.png)](https://codeclimate.com/github/200Creative/spree_bootstrap_frontend)

### Switches out [Spree](https://github.com/spree/spree)’s entire frontend for a bootstrap 3 powered frontend.
### Bootstrap 3 powered frontend.

This has several large advantages:

Expand Down Expand Up @@ -38,7 +35,7 @@ Installation
Add the following to your gemfile. The currently supported and updated branches are `master` (edge), `2-2-stable`, and `2-3-stable`.

```ruby
gem 'spree_bootstrap_frontend', github: '200Creative/spree_bootstrap_frontend', branch: 'master'
gem 'spree_frontend', github: 'spree/spree_frontend', branch: 'master'
```

And run
Expand All @@ -50,15 +47,15 @@ bundle install
Then copy the default stylesheets into your project

```bash
rails generate spree_bootstrap_frontend:install
rails generate spree_frontend:install
```

You'll want to select to overwrite `all.css`. Done.

Customizing
-------

Running the above `spree_bootstrap_frontend:install` command copies the stylesheet to `app/assets/stylesheets/spree/frontend/spree_bootstrap_frontend.css.scss`. Use this as your base stylesheet and edit as required.
Running the above `spree_frontend:install` command copies the stylesheet to `app/assets/stylesheets/spree/frontend/spree_frontend.css.scss`. Use this as your base stylesheet and edit as required.

To style your spree store just override the bootstrap 3 variables. The full list of bootstrap variables can be found [here](https://github.com/twbs/bootstrap-sass/blob/master/vendor/assets/stylesheets/bootstrap/_variables.scss). You can override these by simply redefining the variable before the `@import` directive.
For example:
Expand All @@ -78,18 +75,6 @@ It’s quite powerful, here are some examples created in ~10 minutes with a few
[![layout](http://i.imgur.com/kppJiFS.png)](http://i.imgur.com/m3zKV0s.png)
[![layout](http://i.imgur.com/x92TXYh.png)](http://i.imgur.com/eNyNFSg.png)

Contributing
-------

**Please fork and make a pull request.**

Spree edge templates were last synced at spree/spree@2c057cf9cb0146d07a4005ade75c73d297e77920. Feel free to patch in any newer changes and update this SHA.

**Tests.** To get this to a stage that it can be maintained moving forwards getting all tests passing is the highest priority.

- Raise bugs in github’s [issues tracker](https://github.com/200Creative/spree_bootstrap_frontend/issues).
- Further discussion can be had in the [spree google group](https://groups.google.com/forum/#!forum/spree-user).

Running tests
-------

Expand All @@ -100,15 +85,3 @@ bundle
bundle exec rake test_app
bundle exec rspec spec
```

When testing your applications integration with this extension you may use it's factories.
Simply add this require statement to your spec_helper:

```ruby
require 'spree_bootstrap_frontend/factories'
```

Licence
-------

Copyright Alex James ([200creative.com](http://200creative.com)) and released under the BSD Licence.
5 changes: 2 additions & 3 deletions frontend/app/controllers/spree/store_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ class StoreController < Spree::BaseController
skip_before_action :set_current_order, only: :cart_link

def unauthorized
render 'spree/shared/unauthorized', :layout => Spree::Config[:layout], :status => 401
render 'spree/shared/unauthorized', layout: Spree::Config[:layout], status: 401
end

def cart_link
render :partial => 'spree/shared/link_to_cart'
render partial: 'spree/shared/link_to_cart'
fresh_when(simple_current_order)
end

Expand Down Expand Up @@ -37,4 +37,3 @@ def config_locale
end
end
end

52 changes: 0 additions & 52 deletions frontend/app/helpers/spree/base_helper_decorator.rb

This file was deleted.

54 changes: 54 additions & 0 deletions frontend/app/helpers/spree/frontend_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
module Spree
module FrontendHelper
def breadcrumbs(taxon, separator="&nbsp;")
return "" if current_page?("/") || taxon.nil?
separator = raw(separator)
crumbs = [content_tag(:li, content_tag(:span, link_to(Spree.t(:home), spree.root_path, itemprop: "url") + separator, itemprop: "title"), itemscope:"itemscope", itemtype:"http://data-vocabulary.org/Breadcrumb")]
if taxon
crumbs << content_tag(:li, content_tag(:span, link_to(Spree.t(:products), products_path, itemprop: "url") + separator, itemprop: "title"), itemscope:"itemscope", itemtype:"http://data-vocabulary.org/Breadcrumb")
crumbs << taxon.ancestors.collect { |ancestor| content_tag(:li, content_tag(:span, link_to(ancestor.name , seo_url(ancestor), itemprop: "url") + separator, itemprop: "title"), itemscope:"itemscope", itemtype:"http://data-vocabulary.org/Breadcrumb") } unless taxon.ancestors.empty?
crumbs << content_tag(:li, content_tag(:span, link_to(taxon.name , seo_url(taxon), itemprop: "url"), itemprop: "title"), class: 'active', itemscope:"itemscope", itemtype:"http://data-vocabulary.org/Breadcrumb")
else
crumbs << content_tag(:li, content_tag(:span, Spree.t(:products), itemprop: "title"), class: 'active', itemscope:"itemscope", itemtype:"http://data-vocabulary.org/Breadcrumb")
end
crumb_list = content_tag(:ol, raw(crumbs.flatten.map{|li| li.mb_chars}.join), class: 'breadcrumb')
content_tag(:nav, crumb_list, id: 'breadcrumbs', class: 'col-md-12')
end

def flash_messages(opts = {})
ignore_types = ["order_completed"].concat(Array(opts[:ignore_types]).map(&:to_s) || [])

flash.each do |msg_type, text|
unless ignore_types.include?(msg_type)
concat(content_tag :div, text, class: "alert alert-#{msg_type}")
end
end
nil
end

def link_to_cart(text = nil)
text = text ? h(text) : Spree.t('cart')
css_class = nil

if simple_current_order.nil? or simple_current_order.item_count.zero?
text = "<span class='glyphicon glyphicon-shopping-cart'></span> #{text}: (#{Spree.t('empty')})"
css_class = 'empty'
else
text = "<span class='glyphicon glyphicon-shopping-cart'></span> #{text}: (#{simple_current_order.item_count}) <span class='amount'>#{simple_current_order.display_total.to_html}</span>"
css_class = 'full'
end

link_to text.html_safe, spree.cart_path, :class => "cart-info #{css_class}"
end

def taxons_tree(root_taxon, current_taxon, max_level = 1)
return '' if max_level < 1 || root_taxon.children.empty?
content_tag :div, class: 'list-group' do
root_taxon.children.map do |taxon|
css_class = (current_taxon && current_taxon.self_and_ancestors.include?(taxon)) ? 'list-group-item active' : 'list-group-item'
link_to(taxon.name, seo_url(taxon), class: css_class) + taxons_tree(taxon, current_taxon, max_level - 1)
end.join("\n").html_safe
end
end
end
end
2 changes: 1 addition & 1 deletion frontend/app/models/spree/frontend_configuration.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Spree
class FrontendConfiguration < Preferences::Configuration
preference :locale, :string, :default => Rails.application.config.i18n.default_locale
preference :locale, :string, default: Rails.application.config.i18n.default_locale
end
end
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module SpreeBootstrapFrontend
module SpreeFrontend
module Generators
class InstallGenerator < Rails::Generators::Base
source_root File.expand_path("../templates", __FILE__)
Expand Down
4 changes: 2 additions & 2 deletions frontend/spec/features/cart_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
expect(page).to have_content("Your cart is empty")

within "#link-to-cart" do
expect(page).to have_content("Empty")
expect(page).to have_content("EMPTY")
end
end

Expand All @@ -58,7 +58,7 @@
expect(page).to have_content("Your cart is empty")

within "#link-to-cart" do
expect(page).to have_content("Empty")
expect(page).to have_content("EMPTY")
end
end

Expand Down
2 changes: 1 addition & 1 deletion frontend/spec/features/checkout_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
click_button "Save and Continue"
expect(page).to_not have_content("undefined method `promotion'")
click_button "Save and Continue"
expect(page).to have_content("Shipping total $10.00")
expect(page).to have_content("Shipping total: $10.00")
end
end

Expand Down
4 changes: 2 additions & 2 deletions frontend/spec/features/taxons_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@
visit '/t/category/super-clothing/t-shirts'
end
it "should render breadcrumbs" do
page.find("#breadcrumbs").should have_link("T-Shirts")
expect(page.find("#breadcrumbs")).to have_link("T-Shirts")
end
it "should mark last breadcrumb as active" do
page.find('#breadcrumbs li.active').should have_link("T-Shirts")
expect(page.find('#breadcrumbs .active')).to have_link("T-Shirts")
end
end

Expand Down
11 changes: 0 additions & 11 deletions frontend/spec/helpers/base_helper_spec.rb

This file was deleted.

Loading

0 comments on commit 109180f

Please sign in to comment.