dandify 0.0.1 → 3.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 (41) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +7 -8
  3. data/Rakefile +2 -2
  4. data/app/assets/stylesheets/spree/backend/dandify.scss +55 -0
  5. data/app/controllers/spree/admin/stylesheets_controller.rb +17 -8
  6. data/app/controllers/spree/stylesheets_controller.rb +3 -3
  7. data/app/helpers/spree/admin/navigation_helper_decorator.rb +20 -4
  8. data/app/helpers/spree/admin/stylesheet_helper.rb +12 -2
  9. data/app/models/spree/stylesheet_version.rb +2 -1
  10. data/app/models/spree/unknown_user.rb +11 -0
  11. data/app/models/spree/user_decorator.rb +1 -1
  12. data/app/models/spree/user_identifier.rb +13 -0
  13. data/app/overrides/spree/admin/shared/{_configuration_menu → sub_menu/_configuration}/add_dandify_to_admin_configuration_sidebar.html.erb.deface +1 -1
  14. data/app/views/spree/admin/stylesheets/_form.html.erb +29 -7
  15. data/app/views/spree/admin/stylesheets/_versions.html.erb +16 -19
  16. data/app/views/spree/admin/stylesheets/edit.html.erb +4 -5
  17. data/app/views/spree/admin/stylesheets/new.html.erb +4 -5
  18. data/app/views/spree/admin/stylesheets/show.html.erb +22 -8
  19. data/config/locales/en.yml +39 -27
  20. data/config/routes.rb +1 -1
  21. data/db/migrate/20140617221725_add_paper_trail_versions.rb +5 -5
  22. data/lib/dandify.rb +0 -1
  23. data/lib/dandify/version.rb +1 -1
  24. data/lib/generators/dandify/install/install_generator.rb +10 -9
  25. data/spec/controllers/spree/admin/stylesheets_controller_spec.rb +109 -55
  26. data/spec/controllers/spree/stylesheets_controller_spec.rb +26 -22
  27. data/spec/features/buttons_spec.rb +69 -0
  28. data/spec/features/dandy_style_spec.rb +1 -0
  29. data/spec/features/managing_stylesheet_spec.rb +86 -0
  30. data/spec/features/sidebar_spec.rb +17 -9
  31. data/spec/helpers/admin/navigation_helper_spec.rb +13 -7
  32. data/spec/helpers/admin/stylesheet_helper_spec.rb +47 -0
  33. data/spec/models/spree/blank_stylesheet_spec.rb +5 -3
  34. data/spec/models/spree/stylesheet_spec.rb +73 -69
  35. data/spec/spec_helper.rb +13 -12
  36. metadata +47 -59
  37. data/app/assets/stylesheets/spree/backend/dandify.css +0 -42
  38. data/config/spring.rb +0 -1
  39. data/lib/tasks/dandify_tasks.rake +0 -4
  40. data/spec/features/managing_stylsheet_spec.rb +0 -80
  41. data/spec/features/viewing_admin_spec.rb +0 -49
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 730fbffc3ec3adf78538bd7eb1b4230dedac95d2
4
- data.tar.gz: 2bbdc174a33199b642b76acb2425d525c4384142
3
+ metadata.gz: 9988916c091150cb33eef88a2d266a68fda7b70e
4
+ data.tar.gz: af41fef4719e81b3a69425333cf64e0db326fa41
5
5
  SHA512:
6
- metadata.gz: 37c676843579698efc0f98cac2623a4fd3bc0270d0e6bda298ea625670d55002f3495ccb490c851eec0f096ff645fd48d36c3733d556ddf2ecc4791f9289aa8c
7
- data.tar.gz: ec7ae8bef9ccef09f630b5303d539dca25e60bbf8188b0837152900960afcc1f9c86264de6fd632daf184439aed6e3b4285828b12bfd44d5091b4ea947f0c581
6
+ metadata.gz: 2572fd2f9f9d52c4ef682a6f5e00aa45cce2f04de9fbbf7edf95a9ba80cf3d692da5b95237939c9a0831e9c6f81c6bcde5b3161be92b8c55694fa7196f42631b
7
+ data.tar.gz: 65f42e6a2fb2cf6f0760d70ca55bffd6d9243fe73ff0e4fe30a7bc9906dc615923d5cb72dfc62f491af04a7ef2d563255c72250a291409d73281767245b8fd71
data/README.md CHANGED
@@ -1,25 +1,23 @@
1
1
  # Dandify
2
2
 
3
3
  [![Code Climate](https://codeclimate.com/github/groundctrl/dandify.png)](https://codeclimate.com/github/groundctrl/dandify)
4
+ [![Build Status](https://travis-ci.org/groundctrl/dandify.svg?branch=master)](https://travis-ci.org/groundctrl/dandify)
4
5
 
5
6
  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
+ > More information at http://groundctrl.github.io/dandify
7
9
 
8
10
  ## Installation
9
11
 
10
12
  #### Gem
11
13
 
12
- Add this line to your Spree application's Gemfile:
14
+ Add the following to your Gemfile:
13
15
 
14
- gem 'dandify', github: 'groundctrl/dandify'
16
+ gem 'dandify', '~> 3.0.0'
15
17
 
16
- #### Bleeding edge
18
+ If you are not on the lastest version of Spree you can specify a branch
17
19
 
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.
20
+ gem 'dandify', github: 'groundctrl/dandify', branch: '2-4-stable'
23
21
 
24
22
  #### Generators
25
23
 
@@ -31,6 +29,7 @@ After installing Dandify you'll need to run the generator:
31
29
 
32
30
  bundle exec rails g dandify:install
33
31
 
32
+ This will run migrations as well as install the styles for the admin.
34
33
 
35
34
  ## Testing
36
35
 
data/Rakefile CHANGED
@@ -2,7 +2,7 @@ require 'bundler'
2
2
  Bundler::GemHelper.install_tasks
3
3
 
4
4
  require 'rspec/core/rake_task'
5
- require 'spree/testing_support/common_rake'
5
+ require "spree/testing_support/extension_rake"
6
6
 
7
7
  RSpec::Core::RakeTask.new
8
8
 
@@ -11,5 +11,5 @@ task default: [:spec]
11
11
  desc 'Generates a dummy app for testing'
12
12
  task :test_app do
13
13
  ENV['LIB_NAME'] = 'dandify'
14
- Rake::Task['common:test_app'].invoke 'Spree::User'
14
+ Rake::Task['extension:test_app'].invoke 'Spree::User'
15
15
  end
@@ -0,0 +1,55 @@
1
+ /* Icon rollover - Restore */
2
+
3
+ .spree-ace-field {
4
+ position: relative;
5
+ }
6
+ #editor {
7
+ position: absolute;
8
+ top: 24px; right: 0; left: 0; bottom: 46px;
9
+ }
10
+
11
+ table th.actions,
12
+ table td.actions {
13
+ .fa-history:hover {
14
+ background-color: #9fc820;
15
+ color: #ffffff;
16
+ }
17
+ }
18
+
19
+ table tbody tr {
20
+ &.highlight.action-restore td {
21
+ background-color: #f8fceb;
22
+ border-color: #e0f1a9;
23
+ }
24
+
25
+ &.before-highlight.action-restore td {
26
+ border-bottom-color: #e0f1a9;
27
+ }
28
+ }
29
+
30
+ /* PowerTip - Restore */
31
+ #powerTip.restore {
32
+ background-color: #9fc820;
33
+
34
+ &.n:before,
35
+ &.ne:before,
36
+ &.nw:before {
37
+ border-top-color: #9fc820;
38
+ }
39
+
40
+ &.e:before,
41
+ &.nw:before,
42
+ &.sw:before {
43
+ border-right-color: #9fc820;
44
+ }
45
+
46
+ &.s:before,
47
+ &.se:before,
48
+ &.sw:before {
49
+ border-bottom-color: #9fc820;
50
+ }
51
+
52
+ &.w:before {
53
+ border-left-color: #9fc820;
54
+ }
55
+ }
@@ -5,7 +5,7 @@ module Spree
5
5
 
6
6
  respond_to :html
7
7
 
8
- before_action :set_style
8
+ before_action :set_style, except: [:restore]
9
9
 
10
10
  def create
11
11
  update_action :new
@@ -15,18 +15,31 @@ module Spree
15
15
  update_action :edit
16
16
  end
17
17
 
18
+ def destroy
19
+ @style.destroy
20
+
21
+ redirect_to admin_stylesheets_path, flash: {
22
+ success: Spree.t('dandify.admin.flash.destroyed')
23
+ }
24
+ end
25
+
18
26
  def restore
19
27
  response = rollback_version
20
28
 
21
29
  redirect_to admin_stylesheets_path, flash: {
22
- response => Spree.t("dandify.restore.#{response}")
30
+ response => Spree.t("dandify.admin.flash.#{response}.restore")
23
31
  }
24
32
  end
25
33
 
34
+ def user_for_paper_trail
35
+ Spree::UserIdentifier.new(current_spree_user).id
36
+ end
37
+
26
38
  private
27
39
 
28
40
  def rollback_version
29
- @style.versions.last.reify.save!
41
+ @style = PaperTrail::Version.find(params[:id]).reify
42
+ @style.save!
30
43
  :success
31
44
  rescue
32
45
  :error
@@ -35,7 +48,7 @@ module Spree
35
48
  def update_action(type)
36
49
  if @style.update(style_params)
37
50
  redirect_to admin_stylesheets_path, flash: {
38
- success: Spree.t("dandify.#{type}.success")
51
+ success: Spree.t("dandify.admin.flash.success.#{type}")
39
52
  }
40
53
  else
41
54
  render type
@@ -49,10 +62,6 @@ module Spree
49
62
  def style_params
50
63
  params.require(:stylesheet).permit(:style_raw)
51
64
  end
52
-
53
- def user_for_paper_trail
54
- current_spree_user
55
- end
56
65
  end
57
66
  end
58
67
  end
@@ -8,8 +8,8 @@ module Spree
8
8
 
9
9
  private
10
10
 
11
- def set_response_format
12
- request.format = :css
13
- end
11
+ def set_response_format
12
+ request.format = :css
13
+ end
14
14
  end
15
15
  end
@@ -1,9 +1,25 @@
1
1
  Spree::Admin::NavigationHelper.class_eval do
2
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' }
3
+ name = options[:name] || Spree.t('dandify.admin.icons.restore')
4
+ options[:class] = 'restore-resource btn btn-sm btn-primary icon icon-clone'
5
+ options[:data] = { confirm: Spree.t('dandify.admin.confirm.restore'),
6
+ action: 'restore' }
7
7
  link_to_with_icon('history', name, url, options)
8
8
  end
9
+
10
+ def link_to_destroy_url
11
+ options = {
12
+ class: 'btn btn-danger',
13
+ data: {
14
+ confirm: Spree.t('dandify.admin.confirm.destroy'),
15
+ action: 'delete'
16
+ },
17
+ method: :delete
18
+ }
19
+
20
+ link_to_with_icon 'delete',
21
+ Spree.t('dandify.admin.icons.destroy'),
22
+ admin_stylesheets_path,
23
+ options
24
+ end
9
25
  end
@@ -1,8 +1,18 @@
1
1
  module Spree
2
2
  module Admin
3
3
  module StylesheetHelper
4
- def dandify_version_email(user)
5
- user.nil? ? Spree.t('dandify.unknown') : user.email
4
+ def dandify_version_email(user_id)
5
+ user = if user_id.nil? || user_id == Spree.t('dandify.admin.unknown')
6
+ UnknownUser.new
7
+ else
8
+ User.find(user_id)
9
+ end
10
+
11
+ user.email
12
+ end
13
+
14
+ def previous_versions
15
+ PaperTrail::Version.all
6
16
  end
7
17
  end
8
18
  end
@@ -1,5 +1,6 @@
1
1
  module Spree
2
2
  class StylesheetVersion < PaperTrail::Version
3
- belongs_to :user, foreign_key: 'whodunnit'
3
+ belongs_to :user,
4
+ foreign_key: 'whodunnit'
4
5
  end
5
6
  end
@@ -0,0 +1,11 @@
1
+ module Spree
2
+ class UnknownUser
3
+ def id
4
+ Spree.t('dandify.admin.unknown')
5
+ end
6
+
7
+ def email
8
+ Spree.t('dandify.admin.unknown')
9
+ end
10
+ end
11
+ end
@@ -1,5 +1,5 @@
1
1
  Spree::User.class_eval do
2
2
  has_many :editions,
3
3
  foreign_key: 'whodunnit',
4
- class_name: 'Spree::StylesheetVersion'
4
+ class_name: 'Spree::StylesheetVersion'
5
5
  end
@@ -0,0 +1,13 @@
1
+ module Spree
2
+ class UserIdentifier
3
+ delegate :id, to: :user
4
+
5
+ def initialize(user)
6
+ @user = user || UnknownUser.new
7
+ end
8
+
9
+ private
10
+
11
+ attr_reader :user
12
+ end
13
+ end
@@ -1,2 +1,2 @@
1
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 %>
2
+ <%= configurations_sidebar_menu_item Spree.t('dandify.admin.sidebar'), admin_stylesheets_path %>
@@ -1,11 +1,33 @@
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>
1
+ <% content_for :head do %>
2
+ <%= javascript_include_tag 'https://cdnjs.cloudflare.com/ajax/libs/ace/1.2.0/ace.js' %>
3
+ <%= javascript_include_tag 'https://cdnjs.cloudflare.com/ajax/libs/ace/1.2.0/mode-css.js' %>
4
+ <% end %>
5
+
6
+ <div data-hook="admin_style_form_fields" class="col-md-12">
7
+ <div class="form-group 12-row">
8
+ <div data-hook="admin_stylesheet_form_style_raw" class="form-group field spree-ace-field">
9
+ <div id="editor"></div>
10
+ <%= f.field_container :style_raw, class: ['form-group'] do %>
11
+ <%= f.label :style_raw, Spree.t('dandify.admin.labels.style_raw') %>
12
+ <%= f.text_area :style_raw, rows: '13', class: 'form-control' %>
13
+ <br/><span class="help-block"><%= Spree.t('dandify.admin.notes.sass') %></span>
8
14
  <% end %>
9
15
  </div>
10
16
  </div>
11
17
  </div>
18
+
19
+ <script>
20
+ (function() {
21
+ var cssEditor, stylesheetText = $("#stylesheet_style_raw");
22
+
23
+ $(function() {
24
+ cssEditor = ace.edit("editor");
25
+ cssEditor.getSession().setMode("ace/mode/css");
26
+ cssEditor.setValue(stylesheetText.text());
27
+ });
28
+
29
+ $('#new_stylesheet, .edit_stylesheet').submit(function(event) {
30
+ stylesheetText.text(cssEditor.getValue());
31
+ });
32
+ })();
33
+ </script>
@@ -1,30 +1,27 @@
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>
1
+ <h4>
2
+ <%= Spree.t('dandify.admin.headers.revisions') %>
3
+ </h4>
4
+ <table class="table" id="listing_versions" data-hook="listing_style_versions">
8
5
  <thead>
9
6
  <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>
7
+ <th><%= Spree.t('dandify.admin.headers.on') %></th>
8
+ <th><%= Spree.t('dandify.admin.headers.author') %></th>
9
+ <th><%= Spree.t('dandify.admin.headers.action') %></th>
13
10
  <th data-hook="admin_stylesheets_show_header_actions" class="actions"></th>
14
11
  </tr>
15
12
  </thead>
16
13
  <tbody>
17
- <% versions.reverse.each_with_index do |version, index| %>
14
+ <% versions.reverse.each_with_index do |version| %>
18
15
  <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>
16
+ <td class="align-center">
17
+ <%= version.created_at.to_date %>
18
+ </td>
19
+ <td><%= link_to(dandify_version_email(version.whodunnit), admin_user_path(version.whodunnit.to_i)) %></td>
20
+ <td>
21
+ <%= Spree.t("dandify.admin.action.#{version.event}") %>
22
+ </td>
22
23
  <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 %>
24
+ <%= link_to_restore_url restore_admin_stylesheets_path(id: version.id), title: 'admin_restore_stylesheet', no_text: true, method: :post %>
28
25
  </td>
29
26
  </tr>
30
27
  <% end %>
@@ -1,19 +1,18 @@
1
- <%= render 'spree/admin/shared/configuration_menu' %>
1
+ <%= render 'spree/admin/shared/sub_menu/configuration' %>
2
2
 
3
3
  <% content_for :page_title do %>
4
- <%= Spree.t('dandify.edit.title') %>
4
+ <%= Spree.t('dandify.admin.title.edit') %>
5
5
  <% end %>
6
6
 
7
7
  <%= render partial: 'spree/shared/error_messages', locals: {target: @style} %>
8
8
 
9
9
  <%= form_for @style, url: admin_stylesheets_path do |f| %>
10
10
  <fieldset data-hook="edit_style">
11
- <legend align="center"><%= Spree.t('dandify.form.fieldset') %></legend>
12
11
  <%= render partial: 'form', locals: {f: f} %>
13
12
  <div class="form-buttons filter-actions actions" data-hook="buttons">
14
- <%= button Spree.t('actions.update'), 'ok' %>
13
+ <%= button Spree.t('actions.update'), 'ok', 'submit', { class: 'btn-success' } %>
15
14
  <span class="or"><%= Spree.t(:or) %></span>
16
- <%= link_to_with_icon 'remove', Spree.t('actions.cancel'), admin_stylesheets_path, class: 'button' %>
15
+ <%= button_link_to Spree.t('actions.cancel'), admin_stylesheets_path, icon: 'remove' %>
17
16
  </div>
18
17
  </fieldset>
19
18
  <% end %>
@@ -1,19 +1,18 @@
1
- <%= render 'spree/admin/shared/configuration_menu' %>
1
+ <%= render 'spree/admin/shared/sub_menu/configuration' %>
2
2
 
3
3
  <% content_for :page_title do %>
4
- <%= Spree.t('dandify.new.title') %>
4
+ <%= Spree.t('dandify.admin.title.new') %>
5
5
  <% end %>
6
6
 
7
7
  <%= render partial: 'spree/shared/error_messages', locals: {target: @style} %>
8
8
 
9
9
  <%= form_for @style, url: admin_stylesheets_path do |f| %>
10
10
  <fieldset data-hook="new_style">
11
- <legend align="center"><%= Spree.t('dandify.form.fieldset') %></legend>
12
11
  <%= render partial: 'form', locals: {f: f} %>
13
12
  <div class="form-buttons filter-actions actions" data-hook="buttons">
14
- <%= button Spree.t('actions.create'), 'ok' %>
13
+ <%= button Spree.t('actions.create'), 'ok', 'submit', { class: 'btn-success' } %>
15
14
  <span class="or"><%= Spree.t(:or) %></span>
16
- <%= link_to_with_icon 'remove', Spree.t('actions.cancel'), admin_stylesheets_path, class: 'button' %>
15
+ <%= button_link_to Spree.t('actions.cancel'), admin_stylesheets_path, icon: 'remove' %>
17
16
  </div>
18
17
  </fieldset>
19
18
  <% end %>
@@ -1,23 +1,37 @@
1
- <%= render 'spree/admin/shared/configuration_menu' %>
1
+ <%= render 'spree/admin/shared/sub_menu/configuration' %>
2
2
 
3
3
  <% content_for :page_title do %>
4
- <%= Spree.t('dandify.show.title') %>
4
+ <%= Spree.t('dandify.admin.title.show') %>
5
5
  <% end %>
6
6
 
7
7
  <% content_for :page_actions do %>
8
- <li>
9
8
  <% if @style.persisted? %>
10
- <%= button_link_to Spree.t('dandify.show.buttons.edit'), edit_admin_stylesheets_path, icon: 'edit', id: 'admin_edit_stylesheet_link' %>
9
+ <%= link_to_with_icon 'edit', Spree.t('dandify.admin.buttons.edit'), edit_admin_stylesheets_path, class: 'btn btn-success' %>
10
+ <%= link_to_destroy_url %>
11
11
  <% else %>
12
- <%= button_link_to Spree.t('dandify.show.buttons.new'), new_admin_stylesheets_path, icon: 'plus', id: 'admin_new_stylesheet_link' %>
12
+ <%= link_to_with_icon 'plus', Spree.t('dandify.admin.buttons.new'), new_admin_stylesheets_path, class: 'btn btn-success' %>
13
13
  <% end %>
14
- </li>
14
+ <% end %>
15
+
16
+ <% content_for :head do %>
17
+ <%= stylesheet_link_tag 'https://cdnjs.cloudflare.com/ajax/libs/prism/0.0.1/prism.min.css' %>
18
+ <%= javascript_include_tag 'https://cdnjs.cloudflare.com/ajax/libs/prism/0.0.1/prism.min.js' %>
15
19
  <% end %>
16
20
 
17
21
  <p class="notice"><%= notice %></p>
18
22
 
19
23
  <% if @style.persisted? %>
20
- <%= render partial: 'versions', locals: { versions: @style.versions } %>
24
+ <pre><code class="language-css"><%= @style.style_raw %></code></pre>
25
+
21
26
  <% else %>
22
- <%= Spree.t('dandify.show.none') %>
27
+ <div class="no-objects-found">
28
+ <%= Spree.t('dandify.admin.no_resource_found') %>,
29
+ <%= link_to Spree.t('dandify.admin.create_one'), new_admin_stylesheets_path %>!
30
+ </div>
23
31
  <% end %>
32
+
33
+ <div class="row">
34
+ <% if PaperTrail::Version.count > 1 %>
35
+ <%= render partial: 'versions', locals: { versions: previous_versions } %>
36
+ <% end %>
37
+ </div>