dandify 0.0.1

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 (46) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +22 -0
  3. data/README.md +52 -0
  4. data/Rakefile +15 -0
  5. data/app/assets/javascripts/spree/backend/dandify.js +0 -0
  6. data/app/assets/javascripts/spree/frontend/dandify.js +0 -0
  7. data/app/assets/stylesheets/spree/backend/dandify.css +42 -0
  8. data/app/assets/stylesheets/spree/frontend/dandify.css +0 -0
  9. data/app/controllers/spree/admin/stylesheets_controller.rb +58 -0
  10. data/app/controllers/spree/stylesheets_controller.rb +15 -0
  11. data/app/helpers/spree/admin/navigation_helper_decorator.rb +9 -0
  12. data/app/helpers/spree/admin/stylesheet_helper.rb +9 -0
  13. data/app/models/spree/blank_stylesheet.rb +7 -0
  14. data/app/models/spree/stylesheet.rb +30 -0
  15. data/app/models/spree/stylesheet_version.rb +5 -0
  16. data/app/models/spree/user_decorator.rb +5 -0
  17. data/app/overrides/spree/admin/shared/_configuration_menu/add_dandify_to_admin_configuration_sidebar.html.erb.deface +2 -0
  18. data/app/overrides/spree/shared/_head/add_dandystyles_link.html.erb.deface +2 -0
  19. data/app/views/spree/admin/stylesheets/_form.html.erb +11 -0
  20. data/app/views/spree/admin/stylesheets/_versions.html.erb +32 -0
  21. data/app/views/spree/admin/stylesheets/edit.html.erb +19 -0
  22. data/app/views/spree/admin/stylesheets/new.html.erb +19 -0
  23. data/app/views/spree/admin/stylesheets/show.html.erb +23 -0
  24. data/app/views/spree/stylesheets/show.css.erb +1 -0
  25. data/config/locales/en.yml +37 -0
  26. data/config/routes.rb +9 -0
  27. data/config/spring.rb +1 -0
  28. data/db/migrate/20140616202617_create_spree_stylesheets.rb +10 -0
  29. data/db/migrate/20140617221725_add_paper_trail_versions.rb +13 -0
  30. data/lib/dandify.rb +7 -0
  31. data/lib/dandify/engine.rb +18 -0
  32. data/lib/dandify/version.rb +3 -0
  33. data/lib/generators/dandify/install/install_generator.rb +24 -0
  34. data/lib/tasks/dandify_tasks.rake +4 -0
  35. data/spec/controllers/spree/admin/stylesheets_controller_spec.rb +71 -0
  36. data/spec/controllers/spree/stylesheets_controller_spec.rb +36 -0
  37. data/spec/factories/stylesheet_factory.rb +5 -0
  38. data/spec/features/dandy_style_spec.rb +10 -0
  39. data/spec/features/managing_stylsheet_spec.rb +80 -0
  40. data/spec/features/sidebar_spec.rb +41 -0
  41. data/spec/features/viewing_admin_spec.rb +49 -0
  42. data/spec/helpers/admin/navigation_helper_spec.rb +14 -0
  43. data/spec/models/spree/blank_stylesheet_spec.rb +7 -0
  44. data/spec/models/spree/stylesheet_spec.rb +102 -0
  45. data/spec/spec_helper.rb +59 -0
  46. metadata +296 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 730fbffc3ec3adf78538bd7eb1b4230dedac95d2
4
+ data.tar.gz: 2bbdc174a33199b642b76acb2425d525c4384142
5
+ SHA512:
6
+ metadata.gz: 37c676843579698efc0f98cac2623a4fd3bc0270d0e6bda298ea625670d55002f3495ccb490c851eec0f096ff645fd48d36c3733d556ddf2ecc4791f9289aa8c
7
+ data.tar.gz: ec7ae8bef9ccef09f630b5303d539dca25e60bbf8188b0837152900960afcc1f9c86264de6fd632daf184439aed6e3b4285828b12bfd44d5091b4ea947f0c581
data/MIT-LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 ground(ctrl)
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,52 @@
1
+ # Dandify
2
+
3
+ [![Code Climate](https://codeclimate.com/github/groundctrl/dandify.png)](https://codeclimate.com/github/groundctrl/dandify)
4
+
5
+ Dandify is not a theme. It is a theme helper that allows you to quickly apply versioned frontend style changes from the Spree admin. Dandify only works with stylesheets. Dandify is best used in conjunction with [Shopping Mall](https://github.com/groundctrl/shopping_mall).
6
+
7
+
8
+ ## Installation
9
+
10
+ #### Gem
11
+
12
+ Add this line to your Spree application's Gemfile:
13
+
14
+ gem 'dandify', github: 'groundctrl/dandify'
15
+
16
+ #### Bleeding edge
17
+
18
+ Add this line to your Spree application's Gemfile:
19
+
20
+ gem 'dandify', github: 'groundctrl/dandify', branch: 'master'
21
+
22
+ > Note: The master branch is not guaranteed to be in a fully functioning state. It is unwise to use this branch in a production system.
23
+
24
+ #### Generators
25
+
26
+ Run the bundle command to install it:
27
+
28
+ bundle install
29
+
30
+ After installing Dandify you'll need to run the generator:
31
+
32
+ bundle exec rails g dandify:install
33
+
34
+
35
+ ## Testing
36
+
37
+ Generate a dummy application
38
+
39
+ bundle exec rake test_app
40
+
41
+ Running tests
42
+
43
+ bundle exec rake spec
44
+
45
+
46
+ ## Contributing
47
+
48
+ 1. Fork it ( https://github.com/groundctrl/dandify/fork )
49
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
50
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
51
+ 4. Push to the branch (`git push origin my-new-feature`)
52
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,15 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rspec/core/rake_task'
5
+ require 'spree/testing_support/common_rake'
6
+
7
+ RSpec::Core::RakeTask.new
8
+
9
+ task default: [:spec]
10
+
11
+ desc 'Generates a dummy app for testing'
12
+ task :test_app do
13
+ ENV['LIB_NAME'] = 'dandify'
14
+ Rake::Task['common:test_app'].invoke 'Spree::User'
15
+ end
File without changes
File without changes
@@ -0,0 +1,42 @@
1
+ /* Icon rollover - Restore */
2
+ table th.actions .fa-history:hover,
3
+ table td.actions .fa-history:hover {
4
+ background-color: #9fc820;
5
+ color: #ffffff;
6
+ }
7
+
8
+ table tbody tr.highlight.action-restore td {
9
+ background-color: #f8fceb;
10
+ border-color: #e0f1a9;
11
+ }
12
+
13
+ table tbody tr.before-highlight.action-restore td {
14
+ border-bottom-color: #e0f1a9;
15
+ }
16
+
17
+ /* PowerTip - Restore */
18
+ #powerTip.restore {
19
+ background-color: #9fc820;
20
+ }
21
+
22
+ #powerTip.restore.n:before,
23
+ #powerTip.restore.ne:before,
24
+ #powerTip.restore.nw:before {
25
+ border-top-color: #9fc820;
26
+ }
27
+
28
+ #powerTip.restore.e:before,
29
+ #powerTip.restore.nw:before,
30
+ #powerTip.restore.sw:before {
31
+ border-right-color: #9fc820;
32
+ }
33
+
34
+ #powerTip.restore.s:before,
35
+ #powerTip.restore.se:before,
36
+ #powerTip.restore.sw:before {
37
+ border-bottom-color: #9fc820;
38
+ }
39
+
40
+ #powerTip.restore.w:before {
41
+ border-left-color: #9fc820;
42
+ }
File without changes
@@ -0,0 +1,58 @@
1
+ module Spree
2
+ module Admin
3
+ class StylesheetsController < BaseController
4
+ helper Spree::Admin::StylesheetHelper
5
+
6
+ respond_to :html
7
+
8
+ before_action :set_style
9
+
10
+ def create
11
+ update_action :new
12
+ end
13
+
14
+ def update
15
+ update_action :edit
16
+ end
17
+
18
+ def restore
19
+ response = rollback_version
20
+
21
+ redirect_to admin_stylesheets_path, flash: {
22
+ response => Spree.t("dandify.restore.#{response}")
23
+ }
24
+ end
25
+
26
+ private
27
+
28
+ def rollback_version
29
+ @style.versions.last.reify.save!
30
+ :success
31
+ rescue
32
+ :error
33
+ end
34
+
35
+ def update_action(type)
36
+ if @style.update(style_params)
37
+ redirect_to admin_stylesheets_path, flash: {
38
+ success: Spree.t("dandify.#{type}.success")
39
+ }
40
+ else
41
+ render type
42
+ end
43
+ end
44
+
45
+ def set_style
46
+ @style = Spree::Stylesheet.first_or_initialize
47
+ end
48
+
49
+ def style_params
50
+ params.require(:stylesheet).permit(:style_raw)
51
+ end
52
+
53
+ def user_for_paper_trail
54
+ current_spree_user
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,15 @@
1
+ module Spree
2
+ class StylesheetsController < Spree::StoreController
3
+ before_filter :set_response_format
4
+
5
+ def show
6
+ @style = Spree::Stylesheet.load_style
7
+ end
8
+
9
+ private
10
+
11
+ def set_response_format
12
+ request.format = :css
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,9 @@
1
+ Spree::Admin::NavigationHelper.class_eval do
2
+ def link_to_restore_url(url, options = {})
3
+ name = options[:name] || Spree.t('dandify.restore.name')
4
+ options[:class] = 'restore-resource'
5
+ options[:data] = { confirm: Spree.t('dandify.confirm.restore'),
6
+ action: 'restore' }
7
+ link_to_with_icon('history', name, url, options)
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Spree
2
+ module Admin
3
+ module StylesheetHelper
4
+ def dandify_version_email(user)
5
+ user.nil? ? Spree.t('dandify.unknown') : user.email
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,7 @@
1
+ module Spree
2
+ class BlankStylesheet
3
+ def style_compressed
4
+ ''
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,30 @@
1
+ module Spree
2
+ class Stylesheet < ActiveRecord::Base
3
+ validates :style_raw, presence: true
4
+ validate :compilation
5
+
6
+ has_paper_trail only: [:style_raw],
7
+ class_name: 'Spree::StylesheetVersion'
8
+
9
+ def self.load_style
10
+ first || BlankStylesheet.new
11
+ end
12
+
13
+ private
14
+
15
+ def compilation
16
+ self.style_compressed = rendered_sass
17
+ end
18
+
19
+ def sass_engine
20
+ Sass::Engine.new style_raw, syntax: :scss, style: :compressed
21
+ end
22
+
23
+ def rendered_sass
24
+ sass_engine.render
25
+ rescue => err
26
+ errors.add :style_raw, err.message
27
+ nil
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,5 @@
1
+ module Spree
2
+ class StylesheetVersion < PaperTrail::Version
3
+ belongs_to :user, foreign_key: 'whodunnit'
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ Spree::User.class_eval do
2
+ has_many :editions,
3
+ foreign_key: 'whodunnit',
4
+ class_name: 'Spree::StylesheetVersion'
5
+ end
@@ -0,0 +1,2 @@
1
+ <!-- insert_bottom '[data-hook="admin_configurations_sidebar_menu"], #admin_configurations_sidebar_menu[data-hook]' -->
2
+ <%= configurations_sidebar_menu_item Spree.t('dandify.sidebar'), admin_stylesheets_path %>
@@ -0,0 +1,2 @@
1
+ <!-- insert_before 'erb:contains("csrf_meta_tags")' -->
2
+ <%= stylesheet_link_tag dandystyles_path, format: :css, media: 'screen' %>
@@ -0,0 +1,11 @@
1
+ <div data-hook="admin_style_form_fields" class="row">
2
+ <div class="alpha twelve columns">
3
+ <div data-hook="admin_stylesheet_form_style_raw" class="field">
4
+ <%= f.field_container :style_raw do %>
5
+ <%= f.label :style_raw, raw(Spree.t('dandify.form.label') + content_tag(:span, ' *', class: 'required')) %>
6
+ <%= f.text_area :style_raw, rows: '13', class: 'fullwidth style_raw' %>
7
+ <br/><span class="info"><%= Spree.t('dandify.form.notes.sass') %></span>
8
+ <% end %>
9
+ </div>
10
+ </div>
11
+ </div>
@@ -0,0 +1,32 @@
1
+ <table class="index responsive" id="listing_versions" data-hook="listing_style_versions">
2
+ <colgroup>
3
+ <col style="width: 22%;">
4
+ <col style="width: 60%;">
5
+ <col style="width: 10%;">
6
+ <col style="width: 8%;">
7
+ </colgroup>
8
+ <thead>
9
+ <tr data-hook="stylesheets_show_index_headers">
10
+ <th><%= Spree.t('dandify.show.headers.created_at') %></th>
11
+ <th><%= Spree.t('dandify.show.headers.author') %></th>
12
+ <th><%= Spree.t('dandify.show.headers.action') %></th>
13
+ <th data-hook="admin_stylesheets_show_header_actions" class="actions"></th>
14
+ </tr>
15
+ </thead>
16
+ <tbody>
17
+ <% versions.reverse.each_with_index do |version, index| %>
18
+ <tr data-hook="admin_stylesheets_show_rows" class="<%= cycle('odd', 'even') %>">
19
+ <td class="align-center"><%= version.created_at.to_date %></td>
20
+ <td><%= link_to(dandify_version_email(version.user), admin_user_path(version.whodunnit.to_i)) %></td>
21
+ <td><%= version.event.capitalize %></td>
22
+ <td class='actions align-center' data-hook="admin_stylesheets_show_row_actions">
23
+ <% if index == 0 %>
24
+ <%= link_to_edit_url edit_admin_stylesheets_path, title: 'admin_edit_stylesheet', no_text: true %>
25
+ <% elsif index == 1 %>
26
+ <%= link_to_restore_url restore_admin_stylesheets_path, title: 'admin_restore_stylesheet', no_text: true, method: :post %>
27
+ <% end %>
28
+ </td>
29
+ </tr>
30
+ <% end %>
31
+ </tbody>
32
+ </table>
@@ -0,0 +1,19 @@
1
+ <%= render 'spree/admin/shared/configuration_menu' %>
2
+
3
+ <% content_for :page_title do %>
4
+ <%= Spree.t('dandify.edit.title') %>
5
+ <% end %>
6
+
7
+ <%= render partial: 'spree/shared/error_messages', locals: {target: @style} %>
8
+
9
+ <%= form_for @style, url: admin_stylesheets_path do |f| %>
10
+ <fieldset data-hook="edit_style">
11
+ <legend align="center"><%= Spree.t('dandify.form.fieldset') %></legend>
12
+ <%= render partial: 'form', locals: {f: f} %>
13
+ <div class="form-buttons filter-actions actions" data-hook="buttons">
14
+ <%= button Spree.t('actions.update'), 'ok' %>
15
+ <span class="or"><%= Spree.t(:or) %></span>
16
+ <%= link_to_with_icon 'remove', Spree.t('actions.cancel'), admin_stylesheets_path, class: 'button' %>
17
+ </div>
18
+ </fieldset>
19
+ <% end %>
@@ -0,0 +1,19 @@
1
+ <%= render 'spree/admin/shared/configuration_menu' %>
2
+
3
+ <% content_for :page_title do %>
4
+ <%= Spree.t('dandify.new.title') %>
5
+ <% end %>
6
+
7
+ <%= render partial: 'spree/shared/error_messages', locals: {target: @style} %>
8
+
9
+ <%= form_for @style, url: admin_stylesheets_path do |f| %>
10
+ <fieldset data-hook="new_style">
11
+ <legend align="center"><%= Spree.t('dandify.form.fieldset') %></legend>
12
+ <%= render partial: 'form', locals: {f: f} %>
13
+ <div class="form-buttons filter-actions actions" data-hook="buttons">
14
+ <%= button Spree.t('actions.create'), 'ok' %>
15
+ <span class="or"><%= Spree.t(:or) %></span>
16
+ <%= link_to_with_icon 'remove', Spree.t('actions.cancel'), admin_stylesheets_path, class: 'button' %>
17
+ </div>
18
+ </fieldset>
19
+ <% end %>
@@ -0,0 +1,23 @@
1
+ <%= render 'spree/admin/shared/configuration_menu' %>
2
+
3
+ <% content_for :page_title do %>
4
+ <%= Spree.t('dandify.show.title') %>
5
+ <% end %>
6
+
7
+ <% content_for :page_actions do %>
8
+ <li>
9
+ <% if @style.persisted? %>
10
+ <%= button_link_to Spree.t('dandify.show.buttons.edit'), edit_admin_stylesheets_path, icon: 'edit', id: 'admin_edit_stylesheet_link' %>
11
+ <% else %>
12
+ <%= button_link_to Spree.t('dandify.show.buttons.new'), new_admin_stylesheets_path, icon: 'plus', id: 'admin_new_stylesheet_link' %>
13
+ <% end %>
14
+ </li>
15
+ <% end %>
16
+
17
+ <p class="notice"><%= notice %></p>
18
+
19
+ <% if @style.persisted? %>
20
+ <%= render partial: 'versions', locals: { versions: @style.versions } %>
21
+ <% else %>
22
+ <%= Spree.t('dandify.show.none') %>
23
+ <% end %>
@@ -0,0 +1 @@
1
+ <%= raw @style.style_compressed %>
@@ -0,0 +1,37 @@
1
+ ---
2
+ en:
3
+ activerecord:
4
+ attributes:
5
+ spree/stylesheet:
6
+ style_raw: Styles
7
+ spree:
8
+ dandify:
9
+ unknown: Unknown
10
+ sidebar: Store Stylesheet
11
+ show:
12
+ title: Custom Styles
13
+ buttons:
14
+ new: Create stylesheet
15
+ edit: Edit stylesheet
16
+ none: No custom style yet! Let's get dandy!
17
+ headers:
18
+ created_at: Created
19
+ author: Author
20
+ action: Action
21
+ new:
22
+ title: Creating Custom Styles
23
+ success: New stylesheet has been created.
24
+ edit:
25
+ title: Editing Custom Styles
26
+ success: Stylesheet has been updated. A new revision has been created.
27
+ restore:
28
+ name: Restore
29
+ success: Stylesheet has been restored. A new revision has been created.
30
+ error: Unable to restore stylesheet.
31
+ form:
32
+ fieldset: Stylesheet
33
+ label: Styles
34
+ notes:
35
+ sass: Stylesheets are compiled and minified using a CSS preprocessor. Valid SCSS can be used here.
36
+ confirm:
37
+ restore: Are you sure you want to restore this version of the stylesheet?