refinerycms-variants 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,8 @@
1
+ module Admin
2
+ class VariantsController < Admin::BaseController
3
+
4
+ crudify :variant,
5
+ :title_attribute => 'name', :xhr_paging => true
6
+
7
+ end
8
+ end
@@ -0,0 +1,16 @@
1
+ class Variant < ActiveRecord::Base
2
+
3
+ acts_as_indexed :fields => [:name, :stock_code]
4
+
5
+ validates :name, :presence => true
6
+
7
+ belongs_to :image
8
+ belongs_to :product
9
+ has_many :line_items
10
+
11
+ delegate :url, :to => :image, :prefix => true
12
+
13
+ def name_and_price
14
+ name + " - R" + price.to_i.to_s
15
+ end
16
+ end
@@ -0,0 +1,28 @@
1
+ <ul>
2
+ <% if Admin::VariantsController.searchable? %>
3
+ <li>
4
+ <%= render :partial => "/shared/admin/search",
5
+ :locals => {
6
+ :url => admin_variants_path
7
+ } %>
8
+ </li>
9
+ <% end %>
10
+ <li>
11
+ <%= link_to t('.create_new'), new_admin_variant_path,
12
+ :class => "add_icon" %>
13
+ </li>
14
+ <% if !searching? and Admin::VariantsController.sortable? and Variant.count > 1 %>
15
+ <li>
16
+ <%= link_to t('.reorder', :what => "Variants"),
17
+ admin_variants_path,
18
+ :id => "reorder_action",
19
+ :class => "reorder_icon" %>
20
+
21
+ <%= link_to t('.reorder_done', :what => "Variants"),
22
+ admin_variants_path,
23
+ :id => "reorder_action_done",
24
+ :style => "display: none;",
25
+ :class => "reorder_icon" %>
26
+ </li>
27
+ <% end %>
28
+ </ul>
@@ -0,0 +1,44 @@
1
+ <%= form_for [:admin, @variant] do |f| -%>
2
+ <%= render :partial => "/shared/admin/error_messages", :locals => {
3
+ :object => @variant,
4
+ :include_object_name => true
5
+ } %>
6
+
7
+ <div class='field'>
8
+ <%= f.label :name -%>
9
+ <%= f.text_field :name, :class => 'larger widest' -%>
10
+ </div>
11
+
12
+ <div class='field'>
13
+ <%= f.label :product_id -%>
14
+ <%= f.collection_select :product_id, Product.order(:name), :id, :name, :prompt => "-- Select --" -%>
15
+ </div>
16
+
17
+ <div class='field'>
18
+ <%= f.label :image -%>
19
+ <%= render :partial => "/shared/admin/image_picker", :locals => {
20
+ :f => f,
21
+ :field => :image_id,
22
+ :image => @variant.image,
23
+ :toggle_image_display => false
24
+ } %>
25
+ </div>
26
+
27
+ <div class='field'>
28
+ <%= f.label :price -%>
29
+ <%= f.text_field :price -%>
30
+ </div>
31
+
32
+ <div class='field'>
33
+ <%= f.label :stock_code -%>
34
+ <%= f.text_field :stock_code -%>
35
+ </div>
36
+
37
+ <%= render :partial => "/shared/admin/form_actions",
38
+ :locals => {
39
+ :f => f,
40
+ :continue_editing => false,
41
+ :delete_title => t('delete', :scope => 'admin.variants.variant'),
42
+ :delete_confirmation => t('message', :scope => 'shared.admin.delete', :title => @variant.name)
43
+ } %>
44
+ <% end -%>
@@ -0,0 +1,18 @@
1
+ <% if searching? %>
2
+ <h2><%= t('results_for', :scope => 'shared.admin.search', :query => params[:search]) %></h2>
3
+ <% end %>
4
+ <% if @variants.any? %>
5
+ <div class='pagination_container'>
6
+ <%= render :partial => 'variants' %>
7
+ </div>
8
+ <% else %>
9
+ <p>
10
+ <% unless searching? %>
11
+ <strong>
12
+ <%= t('.no_items_yet') %>
13
+ </strong>
14
+ <% else %>
15
+ <%= t('no_results', :scope => 'shared.admin.search') %>
16
+ <% end %>
17
+ </p>
18
+ <% end %>
@@ -0,0 +1,7 @@
1
+ <ul id='sortable_list'>
2
+ <%= render :partial => 'variant', :collection => @variants %>
3
+ </ul>
4
+ <%= render :partial => "/shared/admin/sortable_list",
5
+ :locals => {
6
+ :continue_reordering => (local_assigns.keys.include?(:continue_reordering)) ? continue_reordering : true
7
+ } %>
@@ -0,0 +1,15 @@
1
+ <li class='clearfix record <%= cycle("on", "on-hover") %>' id="<%= dom_id(variant) -%>">
2
+ <span class='title'>
3
+ <%= variant.name %>
4
+ <span class="preview"><%= variant.product.name %></span>
5
+ </span>
6
+ <span class='actions'>
7
+ <%= link_to refinery_icon_tag("application_edit.png"), edit_admin_variant_path(variant),
8
+ :title => t('.edit') %>
9
+ <%= link_to refinery_icon_tag("delete.png"), admin_variant_path(variant),
10
+ :class => "cancel confirm-delete",
11
+ :title => t('.delete'),
12
+ :confirm => t('message', :scope => 'shared.admin.delete', :title => variant.name),
13
+ :method => :delete %>
14
+ </span>
15
+ </li>
@@ -0,0 +1,2 @@
1
+ <%= will_paginate @variants %>
2
+ <%= render :partial => "sortable_list" %>
@@ -0,0 +1 @@
1
+ <%= render :partial => "form" %>
@@ -0,0 +1,10 @@
1
+ <section id='records'>
2
+ <%= render :partial => 'records' %>
3
+ </section>
4
+ <aside id='actions'>
5
+ <%= render :partial => 'actions' %>
6
+ </aside>
7
+ <%= render :partial => '/shared/admin/make_sortable',
8
+ :locals => {
9
+ :tree => false
10
+ } if !searching? and Admin::VariantsController.sortable? and Variant.count > 1 %>
@@ -0,0 +1 @@
1
+ <%= render :partial => "form" %>
@@ -0,0 +1,25 @@
1
+ en:
2
+ shared:
3
+ admin:
4
+ image_picker:
5
+ image: image
6
+ plugins:
7
+ variants:
8
+ title: Variants
9
+ admin:
10
+ variants:
11
+ actions:
12
+ create_new: Add New Variant
13
+ reorder: Reorder Variants
14
+ reorder_done: Done Reordering Variants
15
+ records:
16
+ title: Variants
17
+ sorry_no_results: Sorry! There are no results found.
18
+ no_items_yet: There are no Variants yet. Click "Add New Variant" to add your first variant.
19
+ variant:
20
+ view_live_html: View this variant live <br/><em>(opens in a new window)</em>
21
+ edit: Edit this variant
22
+ delete: Remove this variant forever
23
+ variants:
24
+ show:
25
+ other: Other Variants
@@ -0,0 +1,25 @@
1
+ fr:
2
+ shared:
3
+ admin:
4
+ image_picker:
5
+ image: image
6
+ plugins:
7
+ variants:
8
+ title: Variants
9
+ admin:
10
+ variants:
11
+ actions:
12
+ create_new: Créer un(e) nouve(au/l/lle) Variant
13
+ reorder: Réordonner les Variants
14
+ reorder_done: Fin de réordonnancement des Variants
15
+ records:
16
+ title: Variants
17
+ sorry_no_results: "Désolé ! Aucun résultat."
18
+ no_items_yet: 'Il n''y a actuellement aucun(e) Variant. Cliquer sur "Créer un(e) nouve(au/l/lle) Variant" pour créer votre premi(er/ère) variant.'
19
+ variant:
20
+ view_live_html: Voir ce(t/tte) variant <br/><em>(Ouvre une nouvelle fenêtre)</em>
21
+ edit: Modifier ce(t/tte) variant
22
+ delete: Supprimer définitivement ce(t/tte) variant
23
+ variants:
24
+ show:
25
+ other: Autres Variants
@@ -0,0 +1,25 @@
1
+ lolcat:
2
+ shared:
3
+ admin:
4
+ image_picker:
5
+ image: IMAGE
6
+ plugins:
7
+ variants:
8
+ title: Variants
9
+ admin:
10
+ variants:
11
+ actions:
12
+ create_new: CREATE NEW Variant
13
+ reorder: REORDR Variants
14
+ reorder_done: DUN REORDERIN Variants
15
+ records:
16
+ title: Variants
17
+ sorry_no_results: SRY! THAR R NO RESULTS FINDZ.
18
+ no_items_yet: THAR R NO Variants YET. CLICK "CREATE NEW Variant" 2 ADD UR FURST variant.
19
+ variant:
20
+ view_live_html: VIEW DIS variant LIV <BR/><EM>(OPENS IN NEW WINDOW)</EM>
21
+ edit: EDIT DIS variant
22
+ delete: REMOOV DIS variant FOREVR
23
+ variants:
24
+ show:
25
+ other: OTHR Variants
@@ -0,0 +1,21 @@
1
+ nb:
2
+ plugins:
3
+ variants:
4
+ title: Variants
5
+ admin:
6
+ variants:
7
+ actions:
8
+ create_new: Lag en ny Variant
9
+ reorder: Endre rekkefølgen på Variants
10
+ reorder_done: Ferdig å endre rekkefølgen Variants
11
+ records:
12
+ title: Variants
13
+ sorry_no_results: Beklager! Vi fant ikke noen resultater.
14
+ no_items_yet: Det er ingen Variants enda. Klikk på "Lag en ny Variant" for å legge til din første variant.
15
+ variant:
16
+ view_live_html: Vis hvordan denne variant ser ut offentlig <br/><em>(åpner i et nytt vindu)</em>
17
+ edit: Rediger denne variant
18
+ delete: Fjern denne variant permanent
19
+ variants:
20
+ show:
21
+ other: Andre Variants
@@ -0,0 +1,21 @@
1
+ nl:
2
+ plugins:
3
+ variants:
4
+ title: Variants
5
+ admin:
6
+ variants:
7
+ actions:
8
+ create_new: Maak een nieuwe Variant
9
+ reorder: Wijzig de volgorde van de Variants
10
+ reorder_done: Klaar met het wijzingen van de volgorde van de Variants
11
+ records:
12
+ title: Variants
13
+ sorry_no_results: Helaas! Er zijn geen resultaten gevonden.
14
+ no_items_yet: Er zijn nog geen Variants. Druk op 'Maak een nieuwe Variant' om de eerste aan te maken.
15
+ variant:
16
+ view_live_html: Bekijk deze variant op de website <br/><em>(opent een nieuw venster)</em>
17
+ edit: Bewerk deze variant
18
+ delete: Verwijder deze variant voor eeuwig
19
+ variants:
20
+ show:
21
+ other: Andere Variants
@@ -0,0 +1,11 @@
1
+ ::Refinery::Application.routes.draw do
2
+ # resources :variants, :only => [:index, :show]
3
+
4
+ scope(:path => 'refinery', :as => 'admin', :module => 'admin') do
5
+ resources :variants, :except => :show do
6
+ collection do
7
+ post :update_positions
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,6 @@
1
+ class RefinerycmsVariants < Refinery::Generators::EngineInstaller
2
+
3
+ source_root File.expand_path('../../../', __FILE__)
4
+ engine_name "variants"
5
+
6
+ end
@@ -0,0 +1,47 @@
1
+ require 'refinerycms-base'
2
+
3
+ module Refinery
4
+ module Variants
5
+
6
+ class << self
7
+ attr_accessor :root
8
+ def root
9
+ @root ||= Pathname.new(File.expand_path('../../', __FILE__))
10
+ end
11
+ end
12
+
13
+ class Engine < Rails::Engine
14
+
15
+ # Lets inject our relationship into Product and LineItem classes
16
+ config.to_prepare do
17
+
18
+ Product.class_eval do
19
+ require 'variant'
20
+ self.has_many :variants
21
+ end
22
+
23
+ LineItem.class_eval do
24
+ require 'variant'
25
+ self.belongs_to :variant
26
+ end
27
+
28
+ end
29
+
30
+ initializer "static assets" do |app|
31
+ app.middleware.insert_after ::ActionDispatch::Static, ::ActionDispatch::Static, "#{root}/public"
32
+ end
33
+
34
+ config.after_initialize do
35
+ Refinery::Plugin.register do |plugin|
36
+ plugin.name = "variants"
37
+ plugin.pathname = root
38
+ plugin.activity = {
39
+ :class => Variant,
40
+ :title => 'name'
41
+ }
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+
@@ -0,0 +1,13 @@
1
+ namespace :refinery do
2
+
3
+ namespace :variants do
4
+
5
+ # call this task my running: rake refinery:variants:my_task
6
+ # desc "Description of my task below"
7
+ # task :my_task => :environment do
8
+ # # add your logic here
9
+ # end
10
+
11
+ end
12
+
13
+ end
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: refinerycms-variants
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 1.0.0
6
+ platform: ruby
7
+ authors:
8
+ - James Thompson
9
+ - Byron Peters
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+
14
+ date: 2012-03-20 00:00:00 Z
15
+ dependencies: []
16
+
17
+ description: Ruby on Rails Variants engine for Refinery CMS
18
+ email: james.b.thompson@gmail.com
19
+ executables: []
20
+
21
+ extensions: []
22
+
23
+ extra_rdoc_files: []
24
+
25
+ files:
26
+ - lib/generators/refinerycms_variants_generator.rb
27
+ - lib/refinerycms-variants.rb
28
+ - lib/tasks/variants.rake
29
+ - config/locales/nl.yml
30
+ - config/locales/en.yml
31
+ - config/locales/fr.yml
32
+ - config/locales/lolcat.yml
33
+ - config/locales/nb.yml
34
+ - config/routes.rb
35
+ - app/models/variant.rb
36
+ - app/views/admin/variants/edit.html.erb
37
+ - app/views/admin/variants/_variant.html.erb
38
+ - app/views/admin/variants/index.html.erb
39
+ - app/views/admin/variants/_variants.html.erb
40
+ - app/views/admin/variants/_sortable_list.html.erb
41
+ - app/views/admin/variants/_records.html.erb
42
+ - app/views/admin/variants/_actions.html.erb
43
+ - app/views/admin/variants/_form.html.erb
44
+ - app/views/admin/variants/new.html.erb
45
+ - app/controllers/admin/variants_controller.rb
46
+ homepage: https://github.com/byropig/refinerycms-variants
47
+ licenses: []
48
+
49
+ post_install_message:
50
+ rdoc_options: []
51
+
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: "0"
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: "0"
66
+ requirements: []
67
+
68
+ rubyforge_project:
69
+ rubygems_version: 1.8.15
70
+ signing_key:
71
+ specification_version: 3
72
+ summary: Variants engine for Refinery CMS
73
+ test_files: []
74
+