vinsol_spree_themes 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +36 -0
  3. data/.ruby-version +1 -0
  4. data/Appraisals +16 -0
  5. data/Gemfile +9 -0
  6. data/Gemfile.lock +386 -0
  7. data/LICENSE +26 -0
  8. data/README.md +250 -0
  9. data/Rakefile +21 -0
  10. data/app/assets/javascripts/spree/backend/codemirror/codemirror.js +9351 -0
  11. data/app/assets/javascripts/spree/backend/codemirror/css-hint.js +60 -0
  12. data/app/assets/javascripts/spree/backend/codemirror/fullscreen.js +41 -0
  13. data/app/assets/javascripts/spree/backend/codemirror/html-hint.js +348 -0
  14. data/app/assets/javascripts/spree/backend/codemirror/javascript-hint.js +155 -0
  15. data/app/assets/javascripts/spree/backend/codemirror/javascript.js +813 -0
  16. data/app/assets/javascripts/spree/backend/codemirror/markdown.js +796 -0
  17. data/app/assets/javascripts/spree/backend/codemirror/ruby.js +295 -0
  18. data/app/assets/javascripts/spree/backend/codemirror/show-hint.js +438 -0
  19. data/app/assets/javascripts/spree/backend/editor.js +11 -0
  20. data/app/assets/javascripts/spree/backend/jquery.treemenu.js +87 -0
  21. data/app/assets/javascripts/spree/backend/main.js +26 -0
  22. data/app/assets/javascripts/spree/backend/spree_themes.js +2 -0
  23. data/app/assets/javascripts/spree/backend/template.js +51 -0
  24. data/app/assets/javascripts/spree/backend/theme.js +17 -0
  25. data/app/assets/javascripts/spree/frontend/spree_themes.js +2 -0
  26. data/app/assets/stylesheets/spree/backend/codemirror/codemirror.css +340 -0
  27. data/app/assets/stylesheets/spree/backend/codemirror/fullscreen.css +6 -0
  28. data/app/assets/stylesheets/spree/backend/codemirror/show-hint.css +36 -0
  29. data/app/assets/stylesheets/spree/backend/editor.css +7 -0
  30. data/app/assets/stylesheets/spree/backend/jquery.treemenu.css +8 -0
  31. data/app/assets/stylesheets/spree/backend/spree_themes.css +7 -0
  32. data/app/assets/stylesheets/spree/backend/style.css +239 -0
  33. data/app/assets/stylesheets/spree/backend/template_editor.css +39 -0
  34. data/app/assets/stylesheets/spree/frontend/spree_themes.css +6 -0
  35. data/app/assets/stylesheets/spree/frontend/theme_preview.css +9 -0
  36. data/app/controllers/spree/admin/themes_controller.rb +80 -0
  37. data/app/controllers/spree/admin/themes_preview_controller.rb +30 -0
  38. data/app/controllers/spree/admin/themes_templates_controller.rb +60 -0
  39. data/app/controllers/spree/fragment_cache_controller.rb +13 -0
  40. data/app/controllers/spree/store_controller_decorator.rb +37 -0
  41. data/app/helpers/spree/base_helper_decorator.rb +45 -0
  42. data/app/models/spree/theme.rb +153 -0
  43. data/app/models/spree/themes_template.rb +67 -0
  44. data/app/models/spree/themes_template/cache_resolver.rb +37 -0
  45. data/app/overrides/spree/add_preview_bar_to_store.html.rb +6 -0
  46. data/app/overrides/spree/add_theme_meta_details_to_store.html.rb +6 -0
  47. data/app/overrides/spree/admin/add_themes_tab.html.rb +6 -0
  48. data/app/services/assets_precompiler_service.rb +86 -0
  49. data/app/services/file_generator_service.rb +29 -0
  50. data/app/services/template_generator_service.rb +101 -0
  51. data/app/services/zip_file_builder.rb +87 -0
  52. data/app/services/zip_file_extractor.rb +52 -0
  53. data/app/views/spree/admin/shared/_theme_menu_button.html.erb +5 -0
  54. data/app/views/spree/admin/themes/_themes.html.erb +44 -0
  55. data/app/views/spree/admin/themes/_upload.html.erb +17 -0
  56. data/app/views/spree/admin/themes/index.html.erb +50 -0
  57. data/app/views/spree/admin/themes_templates/_editor.html.erb +29 -0
  58. data/app/views/spree/admin/themes_templates/_template.html.erb +12 -0
  59. data/app/views/spree/admin/themes_templates/edit.html.erb +13 -0
  60. data/app/views/spree/admin/themes_templates/edit.js.erb +1 -0
  61. data/app/views/spree/admin/themes_templates/index.html.erb +27 -0
  62. data/app/views/spree/admin/themes_templates/new.html.erb +56 -0
  63. data/app/views/spree/shared/_preview_bar.html.erb +7 -0
  64. data/app/views/spree/shared/_theme_metadata.html.erb +9 -0
  65. data/bin/rails +7 -0
  66. data/config/initializers/assets.rb +24 -0
  67. data/config/initializers/sprockets.rb +85 -0
  68. data/config/locales/en.yml +52 -0
  69. data/config/routes.rb +22 -0
  70. data/db/migrate/20170628072452_vinsol_spree_themes_create_themes_and_themes_templates_table.rb +24 -0
  71. data/gemfiles/spree_3_1.gemfile +8 -0
  72. data/gemfiles/spree_3_2.gemfile +9 -0
  73. data/gemfiles/spree_master.gemfile +9 -0
  74. data/lib/generators/themes/default.zip +0 -0
  75. data/lib/generators/vinsol_spree_themes/install/install_generator.rb +50 -0
  76. data/lib/tasks/sync_templates.rake +47 -0
  77. data/lib/vinsol_spree_themes.rb +3 -0
  78. data/lib/vinsol_spree_themes/engine.rb +22 -0
  79. data/lib/vinsol_spree_themes/factories.rb +6 -0
  80. data/lib/vinsol_spree_themes/version.rb +18 -0
  81. data/spec/spec_helper.rb +93 -0
  82. data/vinsol_spree_themes.gemspec +43 -0
  83. metadata +374 -0
@@ -0,0 +1,50 @@
1
+ <% content_for :page_title do %>
2
+ <%= Spree.t(:themes) %>
3
+ <span class="badge"><%= @themes.size %></span>
4
+ <% end %>
5
+
6
+
7
+ <!-- this error partial should only be called when uploading the theme. -->
8
+ <% unless @theme.persisted? %>
9
+ <div data-hook="admin_theme_upload_form_header">
10
+ <%= render partial: 'spree/admin/shared/error_messages', locals: { target: @theme } %>
11
+ </div>
12
+ <% end %>
13
+
14
+ <% content_for :table_filter_title do %>
15
+ <%= Spree.t(:search) %>
16
+ <% end %>
17
+
18
+ <% content_for :table_filter do %>
19
+ <div data-hook="admin_theme_index_search">
20
+ <%= search_form_for [:admin, @search], url: admin_themes_path do |f| %>
21
+ <div class="row">
22
+ <div class="col-md-6">
23
+ <div class="form-group">
24
+ <%= f.label Spree.t(:name) %>
25
+ <%= f.text_field :name_cont, class: "form-control js-quick-search-target" %>
26
+ </div>
27
+ </div>
28
+
29
+ <div class="col-md-6">
30
+ <div class="form-group">
31
+ <%= label_tag Spree.t(:state) %>
32
+ <%= f.select :state_eq, Spree::Theme.state_machines[:state].states.map { |state| [Spree.t("theme_states.#{ state.name }"), state.value] }, { include_blank: true }, class: 'select2 js-filterable' %>
33
+ </div>
34
+ </div>
35
+ </div>
36
+
37
+ <div data-hook="admin_users_index_search_buttons" class="form-actions">
38
+ <%= button Spree.t(:search), 'search' %>
39
+ </div>
40
+ <% end %>
41
+ </div>
42
+ <% end %>
43
+
44
+ <div class="theme-row row">
45
+ <%= render partial: 'upload' %>
46
+ <div class="file-visible-xs visible-xs"></div>
47
+ <%= render partial: 'themes' %>
48
+ </div>
49
+
50
+ <%= javascript_include_tag 'spree/backend/theme.js' %>
@@ -0,0 +1,29 @@
1
+ <% form_path = @template.nil? ? '#' : admin_theme_template_path(@theme, @template) %>
2
+
3
+ <% if @template %>
4
+ <div data-hook="admin_theme_form_header">
5
+ <%= render partial: 'spree/admin/shared/error_messages', locals: { target: @template } %>
6
+ </div>
7
+ <% end %>
8
+
9
+ <%= form_for @template || Spree::ThemesTemplate.new, url: form_path, method: :put, html: { multipart: true }, remote: true do |f| %>
10
+ <fieldset>
11
+ <div data-hook="admin_template_form_fields" class="admin-editor-section">
12
+ <div data-hook="admin_template_form">
13
+ <div data-hook="admin_template_form_body">
14
+ <%= f.label :body, Spree.t(:body) %>
15
+ <%= f.text_area :body, class: 'form-control body', rows: '20' %>
16
+ </div>
17
+ </div>
18
+ </div>
19
+
20
+ <div class="form-actions" data-hook="buttons">
21
+ <%= button Spree.t('actions.update'), 'refresh', 'submit', { class: 'btn-success', data: { disable_with: "#{ Spree.t(:saving) }..." }} %>
22
+ <span class="or"><%= Spree.t(:or) %></span>
23
+ <%= button_link_to Spree.t('actions.cancel'), admin_themes_path, icon: 'delete' %>
24
+ </div>
25
+ </fieldset>
26
+ <% end %>
27
+
28
+ <!-- script to initialize code mirror editor on textarea -->
29
+ <%= javascript_include_tag 'spree/backend/main.js' %>
@@ -0,0 +1,12 @@
1
+ <tr id="<%= spree_dom_id template %>" data-hook="admin_templates_index_rows">
2
+ <td class='template_name'><%= link_to template.name, edit_admin_theme_template_path(@theme, template), class: 'template-name' %></td>
3
+ <td class='template_path'><%= template.path %></td>
4
+ <td class='template_format'><%= template.format %></td>
5
+ <td class='template_handler'><%= template.handler %></td>
6
+
7
+ <td data-hook="admin_template_index_row_actions" class="actions actions-2 text-right">
8
+ <%= link_to edit_admin_theme_template_path(@theme, template), class: 'btn btn-primary btn-sm with-tip action-edit no-text', title: '', 'data-original-title' => 'Edit' do %>
9
+ <span class="icon icon-edit"></span>
10
+ <% end %>
11
+ </td>
12
+ </tr>
@@ -0,0 +1,13 @@
1
+ <% content_for :page_title do %>
2
+ <%= link_to Spree.t(:templates), admin_theme_templates_path(@theme) %> /
3
+ <%= File.join(@template.path, @template.name) %>
4
+ <% end %>
5
+
6
+ <% content_for :head do %>
7
+ <%= javascript_include_tag 'spree/backend/editor' %>
8
+ <%= stylesheet_link_tag 'spree/backend/editor' %>
9
+ <% end %>
10
+
11
+ <div data-hook='template-editor'>
12
+ <%= render partial: 'editor' %>
13
+ </div>
@@ -0,0 +1 @@
1
+ $("[data-hook='template-editor']").html("<%= escape_javascript render(partial: 'editor') %>")
@@ -0,0 +1,27 @@
1
+ <% content_for :head do %>
2
+ <%= javascript_include_tag 'spree/backend/jquery.treemenu' %>
3
+ <%= stylesheet_link_tag 'spree/backend/jquery.treemenu' %>
4
+ <%= javascript_include_tag 'spree/backend/editor' %>
5
+ <%= stylesheet_link_tag 'spree/backend/editor' %>
6
+ <% end %>
7
+
8
+ <% content_for :page_title do %>
9
+ <%= link_to Spree.t(:templates), admin_themes_path %>
10
+ <% end %>
11
+
12
+ <% content_for :page_actions do %>
13
+ <%= button_link_to Spree.t(:new_template), new_admin_theme_template_url, class: "btn-success", icon: 'add', id: 'admin_new_theme_template_link' %>
14
+ <% end %>
15
+
16
+ <div class="row">
17
+ <div class="col-md-push-9 col-md-3" id="tree-menu-sidebar">
18
+ <% filepath = File.join(Rails.root, 'public', 'vinsol_spree_themes', @theme.name) %>
19
+ <%= display_filetree_structure(@theme, filepath).html_safe %>
20
+ </div>
21
+
22
+ <div data-hook='template-editor' class="col-md-pull-3 col-md-9">
23
+ <%= render partial: 'editor' %>
24
+ </div>
25
+ </div>
26
+
27
+ <%= javascript_include_tag 'spree/backend/template' %>
@@ -0,0 +1,56 @@
1
+ <% content_for :page_title do %>
2
+ <%= link_to Spree.t(:templates), admin_theme_templates_path(@theme) %> /
3
+ <%= Spree.t(:new_template) %>
4
+ <% end %>
5
+
6
+ <% content_for :head do %>
7
+ <%= javascript_include_tag 'spree/backend/editor' %>
8
+ <%= stylesheet_link_tag 'spree/backend/editor' %>
9
+ <% end %>
10
+
11
+ <div data-hook="admin_theme_form_header">
12
+ <%= render partial: 'spree/admin/shared/error_messages', locals: { target: @theme } %>
13
+ </div>
14
+
15
+ <%= form_for @template, url: admin_theme_templates_path(@theme, @template), method: :post, html: { multipart: true } do |f| %>
16
+ <fieldset>
17
+
18
+ <div class="row">
19
+ <div class="col-md-8">
20
+ <div data-hook="admin_template_form_name">
21
+ <%= f.label :name, Spree.t(:name) %>
22
+ <%= f.text_field :name, class: 'form-control' %>
23
+ </div>
24
+ </div>
25
+ </div>
26
+
27
+ <div class="row">
28
+ <div class="col-md-8">
29
+ <div data-hook="admin_template_form_path">
30
+ <%= f.label :path, Spree.t(:path) %>
31
+ <%= f.text_field :path, class: 'form-control' %>
32
+ <small><%= "(path will be appended to <b>public/themes/#{ @theme.name }/</b>)".html_safe %></small>
33
+ </div>
34
+ </div>
35
+ </div>
36
+
37
+ <div data-hook="admin_template_form_fields">
38
+ <div class="row">
39
+ <div class="col-md-8">
40
+ <div data-hook="admin_template_form_body">
41
+ <%= f.label :body, Spree.t(:body) %>
42
+ <%= f.text_area :body, class: 'form-control body', rows: '20' %>
43
+ </div>
44
+ </div>
45
+ </div>
46
+ </div>
47
+
48
+ <div class="form-actions" data-hook="buttons">
49
+ <%= button Spree.t('actions.update'), 'refresh', 'submit', { class: 'btn-success', data: { disable_with: "#{ Spree.t(:saving) }..." }} %>
50
+ <span class="or"><%= Spree.t(:or) %></span>
51
+ <%= button_link_to Spree.t('actions.cancel'), admin_theme_templates_path(@theme), icon: 'delete' %>
52
+ </div>
53
+ </fieldset>
54
+ <% end %>
55
+
56
+ <%= javascript_include_tag 'spree/backend/main.js' %>
@@ -0,0 +1,7 @@
1
+ <% if preview_mode? %>
2
+ <div class="alert alert-preview" role="alert">
3
+ <h4 class="text-center"><%= Spree.t('warnings.preview_mode_message') %>
4
+ <%= link_to 'X', admin_theme_preview_path(params[:theme]), method: :delete, class: 'pull-right' %>
5
+ </h4>
6
+ </div>
7
+ <% end %>
@@ -0,0 +1,9 @@
1
+ <% filepath = File.join(Spree::Theme::CURRENT_THEME_PATH, 'meta_info.yml') %>
2
+
3
+ <% if File.exist?(filepath) %>
4
+ <% meta_info = YAML.load_file(filepath) %>
5
+
6
+ <meta name='name' content=<%= meta_info['name'] %> charset="utf-8">
7
+ <meta name='authors' content=<%= meta_info['authors'] %> charset="utf-8">
8
+ <meta name='version' content=<%= meta_info['version'] %> charset="utf-8">
9
+ <% end %>
@@ -0,0 +1,7 @@
1
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
2
+
3
+ ENGINE_ROOT = File.expand_path('../..', __FILE__)
4
+ ENGINE_PATH = File.expand_path('../../lib/vinsol_spree_themes/engine', __FILE__)
5
+
6
+ require 'rails/all'
7
+ require 'rails/engine/commands'
@@ -0,0 +1,24 @@
1
+ # Loading assets current theme assets path.
2
+
3
+ Rails.application.config.assets.paths << Rails.root.join('public', 'vinsol_spree_themes', 'current', 'javascripts')
4
+ Rails.application.config.assets.paths << Rails.root.join('public', 'vinsol_spree_themes', 'current', 'stylesheets')
5
+ Rails.application.config.assets.paths << Rails.root.join('public', 'vinsol_spree_themes', 'current', 'fonts')
6
+ Rails.application.config.assets.paths << Rails.root.join('public', 'assets', 'vinsol_spree_theme')
7
+ Rails.application.config.assets.paths << Rails.root.join('public', 'assets', 'preview_vinsol_spree_theme')
8
+
9
+ # precompiling .js files
10
+ Rails.application.config.assets.precompile += %w( spree/backend/editor.js
11
+ spree/backend/main.js
12
+ spree/backend/template.js
13
+ spree/backend/theme.js
14
+ spree/backend/jquery.treemenu.js
15
+ *.manifest.js
16
+ )
17
+
18
+ # precompiling .css files
19
+ Rails.application.config.assets.precompile += %w( spree/backend/editor.css
20
+ spree/backend/jquery.treemenu.css
21
+ *.manifest.css
22
+ *.manifest.scss.css
23
+ *.manifest.scss
24
+ )
@@ -0,0 +1,85 @@
1
+ module Sprockets
2
+ class Railtie < ::Rails::Railtie
3
+
4
+ THEME_PUBLIC_ASSET_DIRECTORY = 'vinsol_spree_theme'
5
+ PUBLIC_THEME_PATH = File.join('assets', THEME_PUBLIC_ASSET_DIRECTORY)
6
+ PREVIEW_THEME_PUBLIC_ASSET_DIRECTORY = 'preview_vinsol_spree_theme'
7
+
8
+ def self.build_manifest(app)
9
+ config = app.config
10
+ path = File.join(config.paths['public'].first, PUBLIC_THEME_PATH)
11
+ Sprockets::Manifest.new(app.assets, path, config.assets.manifest)
12
+ end
13
+
14
+ end
15
+ end
16
+
17
+ # overriding HelperAssetResolvers by adding new theme resolver.
18
+ module Sprockets
19
+ module Rails
20
+ module HelperAssetResolvers
21
+
22
+ def self.[](name)
23
+ case name
24
+ when :manifest
25
+ Manifest
26
+ when :environment
27
+ Environment
28
+ when :theme
29
+ Theme
30
+ else
31
+ raise ArgumentError, "Unrecognized asset resolver: #{ name.inspect }. Expected :theme, :manifest or :environment"
32
+ end
33
+ end
34
+
35
+ class Theme < Manifest
36
+
37
+ def initialize(view)
38
+ @view = view
39
+ if current_theme
40
+ @manifest = AssetsPrecompilerService.new(current_theme).minify({ precompile: false })
41
+ else
42
+ super
43
+ end
44
+ raise ArgumentError, 'config.assets.resolve_with includes :theme, but app.assets_manifest is nil' unless @manifest
45
+ end
46
+
47
+ def asset_path(path, digest, allow_non_precompiled = false)
48
+ result = super
49
+ if preview_by_admin?
50
+ result.prepend("#{ Sprockets::Railtie::PREVIEW_THEME_PUBLIC_ASSET_DIRECTORY }/") if result.present?
51
+ else
52
+ result.prepend("#{ Sprockets::Railtie::THEME_PUBLIC_ASSET_DIRECTORY }/") if result.present?
53
+ end
54
+ result
55
+ end
56
+
57
+ def current_theme
58
+ if preview_by_admin?
59
+ @theme ||= Spree::Theme.find_by(name: @view.cookies[:preview])
60
+ else
61
+ @theme ||= Spree::Theme.published.first
62
+ end
63
+ end
64
+
65
+ def preview_by_admin?
66
+ @view.present? && @view.cookies[:preview].present?
67
+ end
68
+
69
+ end
70
+ end
71
+ end
72
+ end
73
+
74
+ # adding theme resolver used by sprockets.
75
+ Rails.application.config.after_initialize do |app|
76
+ config = app.config
77
+ if config.assets.resolve_with.nil?
78
+ config.assets.resolve_with = [:theme]
79
+ config.assets.resolve_with << :manifest if config.assets.digest && !config.assets.debug
80
+ config.assets.resolve_with << :environment if config.assets.compile
81
+ else
82
+ Rails.logger.info 'No resolver was there...'
83
+ config.assets.resolve_with.unshift(:theme)
84
+ end
85
+ end
@@ -0,0 +1,52 @@
1
+ # Sample localization file for English. Add more files in this directory for other locales.
2
+ # See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
3
+
4
+ en:
5
+ spree:
6
+ themes: Themes
7
+ vinsol_spree_themes: Vinsol Spree Theme
8
+ templates: Templates
9
+ path: Path
10
+ format: Format
11
+ handler: Handler
12
+ body: Body
13
+ name: Name
14
+ state: Theme State
15
+ theme_states:
16
+ compiled: Compiled
17
+ drafted: Drafted
18
+ published: Published
19
+
20
+ actions:
21
+ themes: Themes
22
+ upload: Upload
23
+ compiled: Compile
24
+ published: Publish
25
+ view_templates: Templates
26
+ new_template: New Template
27
+ download: Download
28
+ preview: Preview
29
+
30
+ models:
31
+ theme:
32
+ minimum_active_error: Atleast one theme should be published.
33
+ no_destory_error: Published theme cannot be removed.
34
+
35
+ flash:
36
+ admin:
37
+ themes:
38
+ upload:
39
+ success: "Theme %{name} successfully uploaded."
40
+ failure: "Something went wrong, theme could not be uploaded."
41
+ state_change:
42
+ success: "Theme %{name} successfully %{state}."
43
+ failure: "Something went wrong, theme %{name} could not be %{state} due to the following reason:- %{errors}"
44
+ destroy:
45
+ success: "Theme %{name} successfully removed."
46
+ failure: "Something went wrong, theme %{name} could not be removed due to following reasons:- %{errors}"
47
+ download:
48
+ failure: "Something went wrong, theme %{name} could not be downloaded due to following reason:- %{errors}"
49
+
50
+ warnings:
51
+ update_metainfo: 'Make sure you update the meta info details in file meta_info.yml once the theme is updated. You will need to download the theme and reupload it.'
52
+ preview_mode_message: Preview Mode
@@ -0,0 +1,22 @@
1
+ Spree::Core::Engine.routes.draw do
2
+
3
+ # Add your extension routes here
4
+ namespace :admin do
5
+ resources :themes, only: [:index, :destroy] do
6
+
7
+ member do
8
+ patch :state_change
9
+ patch :download
10
+ end
11
+
12
+ collection do
13
+ post :upload
14
+ end
15
+
16
+ resources :templates, controller: :themes_templates, only: [:index, :new, :create, :edit, :update]
17
+
18
+ resource :preview, controller: :themes_preview, only: [:show, :destroy]
19
+ end
20
+
21
+ end
22
+ end
@@ -0,0 +1,24 @@
1
+ class VinsolSpreeThemesCreateThemesAndThemesTemplatesTable < ActiveRecord::Migration[5.0]
2
+
3
+ def change
4
+ create_table :spree_themes do |t|
5
+ t.string :name
6
+ t.string :state
7
+ t.attachment :template_file
8
+ end
9
+
10
+ create_table :spree_themes_templates do |t|
11
+ t.string :name
12
+ t.text :body
13
+ t.string :path
14
+ t.string :format
15
+ t.string :locale
16
+ t.string :handler
17
+ t.boolean :partial, default: false
18
+ t.references :theme, index: true
19
+
20
+ t.timestamps
21
+ end
22
+ end
23
+
24
+ end
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "spree", "~> 3.1.0"
6
+ gem "spree_auth_devise", "~> 3.1.0"
7
+
8
+ gemspec :path => "../"