spreefinery_themes 1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. data/app/assets/images/jstree/file.png +0 -0
  2. data/app/assets/images/jstree/folder.png +0 -0
  3. data/app/assets/javascripts/code_mirror_manager.coffee +105 -0
  4. data/app/assets/javascripts/editor.coffee +3 -0
  5. data/app/assets/javascripts/files_manager.coffee +41 -0
  6. data/app/assets/javascripts/jstree_manager.coffee +177 -0
  7. data/app/assets/javascripts/themes.coffee +21 -0
  8. data/app/assets/stylesheets/editor.css +40 -0
  9. data/app/assets/stylesheets/themes.css +50 -0
  10. data/app/controllers/refinery/themes/admin/editor_controller.rb +73 -0
  11. data/app/controllers/refinery/themes/admin/themes_controller.rb +60 -0
  12. data/app/controllers/refinery/themes/theme_controller.rb +12 -0
  13. data/app/decorators/action_view_decorator.rb +6 -0
  14. data/app/decorators/application_controller_decorator.rb +7 -0
  15. data/app/decorators/base_controller_decorator.rb +4 -0
  16. data/app/decorators/drops_decorator.rb +33 -0
  17. data/app/decorators/liquid_strainer_decorator.rb +23 -0
  18. data/app/decorators/refinery_admin_pages_controller_decorator.rb +6 -0
  19. data/app/decorators/refinery_pages_controller_decorator.rb +17 -0
  20. data/app/decorators/refinery_sessions_controller_decorator.rb +3 -0
  21. data/app/decorators/spree_base_controller_decorator.rb +3 -0
  22. data/app/decorators/spree_checkout_controller_decorator.rb +42 -0
  23. data/app/decorators/template_renderer_decorator.rb +25 -0
  24. data/app/helpers/refinery/themes/admin/themes_helper.rb +9 -0
  25. data/app/liquid/blocks/capture_variable.rb +36 -0
  26. data/app/liquid/blocks/content_for.rb +55 -0
  27. data/app/liquid/blocks/rss.rb +27 -0
  28. data/app/liquid/blocks/with_scope.rb +55 -0
  29. data/app/liquid/drops/address_drop.rb +5 -0
  30. data/app/liquid/drops/country_drop.rb +5 -0
  31. data/app/liquid/drops/form_builder_drop.rb +15 -0
  32. data/app/liquid/drops/image_drop.rb +5 -0
  33. data/app/liquid/drops/line_item_drop.rb +41 -0
  34. data/app/liquid/drops/menu_item_drop.rb +17 -0
  35. data/app/liquid/drops/option_type_drop.rb +5 -0
  36. data/app/liquid/drops/option_value_drop.rb +3 -0
  37. data/app/liquid/drops/order_drop.rb +19 -0
  38. data/app/liquid/drops/page_drop.rb +5 -0
  39. data/app/liquid/drops/page_part_drop.rb +18 -0
  40. data/app/liquid/drops/post_category_drop.rb +5 -0
  41. data/app/liquid/drops/post_comment_drop.rb +5 -0
  42. data/app/liquid/drops/post_drop.rb +21 -0
  43. data/app/liquid/drops/product_drop.rb +81 -0
  44. data/app/liquid/drops/product_property_drop.rb +5 -0
  45. data/app/liquid/drops/property_drop.rb +5 -0
  46. data/app/liquid/drops/role_drop.rb +5 -0
  47. data/app/liquid/drops/spree_money_drop.rb +10 -0
  48. data/app/liquid/drops/state_drop.rb +6 -0
  49. data/app/liquid/drops/taxon_drop.rb +24 -0
  50. data/app/liquid/drops/taxonomy_drop.rb +6 -0
  51. data/app/liquid/drops/user_drop.rb +22 -0
  52. data/app/liquid/drops/variant_drop.rb +24 -0
  53. data/app/liquid/filters/filters.rb +128 -0
  54. data/app/liquid/filters/protected.rb +28 -0
  55. data/app/liquid/filters/rails_filters.rb +73 -0
  56. data/app/liquid/tags/rails_tags.rb +63 -0
  57. data/app/liquid/tags/refinery_tags.rb +33 -0
  58. data/app/liquid/tags/spree_tags.rb +164 -0
  59. data/app/models/file_manager.rb +206 -0
  60. data/app/models/refinery/themes/theme.rb +79 -0
  61. data/app/views/refinery/admin/_dialog_success.html.erb +5 -0
  62. data/app/views/refinery/shared/_menu_branch.html.erb +30 -0
  63. data/app/views/refinery/shared/_pages_menu.html.erb +14 -0
  64. data/app/views/refinery/themes/admin/editor/_editor_actions.html.erb +9 -0
  65. data/app/views/refinery/themes/admin/editor/file.html.erb +50 -0
  66. data/app/views/refinery/themes/admin/editor/index.html.erb +15 -0
  67. data/app/views/refinery/themes/admin/editor/upload_file.html.erb +16 -0
  68. data/app/views/refinery/themes/admin/shared/_actions.html.erb +19 -0
  69. data/app/views/refinery/themes/admin/shared/_theme_assets.html.erb +6 -0
  70. data/app/views/refinery/themes/admin/themes/index.html.erb +58 -0
  71. data/app/views/refinery/themes/admin/themes/upload.html.erb +17 -0
  72. data/app/views/spree/products/_variants.html.erb +19 -0
  73. data/config/initializers/liquid_engine.rb +8 -0
  74. data/config/initializers/refinery/core.rb +4 -0
  75. data/config/initializers/refinery/pages.rb +9 -0
  76. data/config/locales/en.yml +14 -0
  77. data/config/routes.rb +42 -0
  78. data/lib/action_view/template/handlers/liquid.rb +88 -0
  79. data/lib/editable.rb +26 -0
  80. data/lib/hash.rb +5 -0
  81. data/lib/liquid/base_drop.rb +62 -0
  82. data/lib/spreefinery/engine.rb +46 -0
  83. data/lib/spreefinery_themes.rb +21 -0
  84. data/readme.md +27 -0
  85. metadata +178 -0
@@ -0,0 +1,6 @@
1
+ <% content_for :javascripts do %>
2
+ <%= javascript_include_tag "/assets/themes" %>
3
+ <% end %>
4
+ <% content_for :stylesheets do %>
5
+ <%= stylesheet_link_tag '/assets/themes' %>
6
+ <% end %>
@@ -0,0 +1,58 @@
1
+ <%= render :partial => "refinery/themes/admin/shared/theme_assets" %>
2
+ <%= render "refinery/themes/admin/shared/actions" %>
3
+
4
+ <div id='records'>
5
+ <% if @themes.any? %>
6
+ <% current_theme = Refinery::Themes::Theme.current_theme_config %>
7
+ <table cellpadding="1" cellspacing="1" style="width: 100%; ">
8
+ <tbody>
9
+ <tr>
10
+ <td style="width: 70%">
11
+ <%= link_to(image_tag("/themes/#{current_theme['config']['key']}/image.png",
12
+ {class: 'screenshot'}), "/themes/#{current_theme['config']['key']}/image.png",
13
+ {class: 'fancybox', title: 'Preview Theme'}) %>
14
+ </td>
15
+ <td class="theme-info">
16
+ <h1><%= current_theme['config']['name'] %><br><span>ver. <%= current_theme['config']['version'] %></span></h1>
17
+ <span>by <%= current_theme['config']['author'] %></span>
18
+
19
+ <p><%= current_theme['config']['description'] %></p>
20
+ <% if current_theme['config']['key'].eql?('default') %>
21
+ <p>
22
+ <%= link_to t('refinery.themes.admin.themes.actions.reset'), '#',
23
+ :onclick => "Themes.resetToDefaultTheme('#{refinery.reset_themes_admin_themes_path}')",
24
+ :class => 'button' %>
25
+ </p>
26
+ <% end %>
27
+ </td>
28
+ </tr>
29
+
30
+ <% @themes.reject { |i| i['config'].eql?(current_theme['config']) }.each do |theme| %>
31
+ <tr>
32
+ <td style="width: 70%">
33
+ <%= link_to(image_tag("/themes/#{theme['config']['key']}/image.png", {class: 'screenshot'}), "/themes/#{theme['config']['key']}/image.png",
34
+ {class: 'fancybox', title: 'Preview Theme'}) %>
35
+ </td>
36
+ <td class="theme-info">
37
+ <h1><%= theme['config']['name'] %><br><span>ver. <%= theme['config']['version'] %></span></h1>
38
+ <span>by <%= theme['config']['author'] %></span>
39
+ <p><%= theme['config']['description'] %></p>
40
+
41
+ <p><%= link_to "Select Theme", "/refinery/themes/select_theme?key=#{theme['config']['key']}", {class: "button select_theme_button"} %>
42
+ <%= image_tag "spinner.gif", :style => "display:none", :id => 'spinner', :class => "spinner" %>
43
+ </p>
44
+ <% if theme['config']['key'].eql?('default') %>
45
+ <p>
46
+ <%= link_to t('refinery.themes.admin.themes.actions.reset'), '#',
47
+ :onclick => "Themes.resetToDefaultTheme('#{refinery.reset_themes_admin_themes_path}')",
48
+ :class => 'button' %>
49
+ </p>
50
+ <% end %>
51
+ <!--<p><%= link_to "Preview Theme", "/themes/#{theme['config']['key']}/image.png", class: "fancybox button" %></p>-->
52
+ </td>
53
+ </tr>
54
+ <% end %>
55
+ </tbody>
56
+ </table>
57
+ <% end %>
58
+ </div>
@@ -0,0 +1,17 @@
1
+ <%= render :partial => "refinery/themes/admin/shared/theme_assets" %>
2
+ <%= render "refinery/themes/admin/shared/actions" %>
3
+
4
+ <section class="clearfix one_list" id="records">
5
+ <%= form_tag(themes_admin_themes_path, :multipart => true) do |f| %>
6
+ <div class='field'>
7
+ <label for="zip_file">ZIP File:</label>
8
+ <%= file_field_tag 'zip_file', class: 'widest' %>
9
+ </div>
10
+ <div class="form-actions">
11
+ <div class="form-actions-right"><%= submit_tag "Upload" %></div>
12
+ </div>
13
+ <% end %>
14
+ </section>
15
+
16
+
17
+
@@ -0,0 +1,19 @@
1
+ <% if @product.has_variants? %>
2
+ <% has_checked = false
3
+ @product.variants.active(current_currency).each_with_index do |v,index|
4
+ next if v.option_values.empty? || (!v.in_stock && !Spree::Config[:show_zero_stock_products])
5
+ checked = !has_checked && (v.in_stock || Spree::Config[:allow_backorders])
6
+ has_checked = true if checked %>
7
+ <li>
8
+ <%= radio_button_tag "products[#{@product.id}]", v.id, checked, :disabled => !v.in_stock && !Spree::Config[:allow_backorders], 'data-price' => v.price_in(current_currency).display_price %>
9
+ <label for="<%= ['products', @product.id, v.id].join('_') %>">
10
+ <span class="variant-description">
11
+ <%= variant_options v %>
12
+ </span>
13
+ <% if variant_price v %>
14
+ <span class="price diff"><%= variant_price v %></span>
15
+ <% end %>
16
+ </label>
17
+ </li>
18
+ <% end%>
19
+ <% end%>
@@ -0,0 +1,8 @@
1
+ require 'action_view/template/handlers/liquid'
2
+ ActionView::Template.register_template_handler :liquid, ActionView::Template::Handlers::Liquid
3
+
4
+ FileUtils.ln_sf(Refinery::Themes::Theme.theme_path, Rails.root.join('themes/current')) unless File.exist?(Rails.root.join('themes/current'))
5
+
6
+ Rails.application.config.assets.paths << Rails.root.join("themes/current/assets/javascripts")
7
+ Rails.application.config.assets.paths << Rails.root.join("themes/current/assets/stylesheets")
8
+ Rails.application.config.assets.paths << Rails.root.join("themes/current/assets/images")
@@ -0,0 +1,4 @@
1
+ # encoding: utf-8
2
+ Refinery::Core.configure do |config|
3
+ config.menu_css = { :selected => "active", :first => "first", :last => "last" }
4
+ end
@@ -0,0 +1,9 @@
1
+ # encoding: utf-8
2
+ Refinery::Pages.configure do |config|
3
+ config.default_parts = ["left_sidebar", "body", "right_sidebar"]
4
+ config.new_page_parts = true
5
+ config.use_layout_templates = true
6
+ config.use_view_templates = true
7
+ config.use_custom_slugs = true
8
+ end
9
+
@@ -0,0 +1,14 @@
1
+ en:
2
+ refinery:
3
+ plugins:
4
+ spreefinery:
5
+ title: Themes
6
+ themes:
7
+ admin:
8
+ themes:
9
+ actions:
10
+ upload: Upload New Theme
11
+ reset: Re-Install Theme
12
+ browse: Browse Themes
13
+ settings: Current Theme Settings
14
+ editor: Current Theme Editor
@@ -0,0 +1,42 @@
1
+ Rails.application.routes.prepend do
2
+ match "/themes/:key/image.png", :to => "refinery/themes/theme#sreenshot"
3
+ end
4
+
5
+ Refinery::Core::Engine.routes.prepend do
6
+ # Admin routes
7
+ namespace :themes, :path => '' do
8
+ namespace :admin, :path => 'refinery' do
9
+ scope :path => 'themes' do
10
+ root :to => "themes#index", :via => :get
11
+
12
+ resource :editor, :controller => 'editor' do
13
+ root :to => "editor#index", :via => :get
14
+
15
+ collection do
16
+ post :list
17
+ post :file
18
+ post :save_file
19
+ post :add
20
+ post :rename
21
+ post :delete
22
+ post :upload
23
+ get :upload_file
24
+ end
25
+ end
26
+
27
+ end
28
+
29
+
30
+ resources :themes, :except => [:show, :destroy, :new] do
31
+ collection do
32
+ get :upload
33
+ get :reset
34
+ get :settings
35
+ get :select_theme
36
+ end
37
+ end
38
+
39
+ end
40
+ end
41
+
42
+ end
@@ -0,0 +1,88 @@
1
+ # origianl: https://gist.github.com/4605222
2
+ # variants:
3
+ # https://gist.github.com/4605162
4
+ #
5
+ class ActionView::Template::Handlers::Liquid
6
+
7
+ PROTECTED_ASSIGNS = %w( _routes template_root response _session template_class action_name request_origin session template
8
+ _response url _request _cookies variables_added _flash params _headers request cookies
9
+ ignore_missing_templates flash _params logger before_filter_chain_aborted headers )
10
+
11
+
12
+ def self.call(template)
13
+ "ActionView::Template::Handlers::Liquid.new(self).render(#{template.source.inspect}, local_assigns)"
14
+ end
15
+
16
+ def initialize(view)
17
+ @view = view
18
+ end
19
+
20
+ def render(template, local_assigns = {})
21
+ @view.controller.headers["Content-Type"] ||= 'text/html; charset=utf-8'
22
+
23
+ assigns = @view.assigns.update('view' => @view)
24
+ assigns['site_name'] = Refinery::Core.site_name
25
+ assigns['theme_assigns'] = Refinery::Themes::Theme.current_theme_config['assigns']
26
+ assigns['theme_config'] = Refinery::Themes::Theme.current_theme_config['config']
27
+ assigns['spree_config'] = Spree::Config
28
+
29
+ #TODO
30
+ #assigns = (@view.instance_variables.map{ |i| i.to_s} - PROTECTED_INSTANCE_VARIABLES).inject({}) do |hash, var_name|
31
+ # hash[var_name.to_s.sub('@', '')] = @view.instance_eval(var_name.to_s)
32
+ # #hash[var_name[1..-1]] = @view.instance_variable_get(var_name)
33
+ # hash
34
+ #end
35
+
36
+ assigns.merge!(local_assigns.stringify_keys)
37
+
38
+ @view.controller._helpers.instance_methods.each do |method|
39
+ #@view.public_methods.each do |method|
40
+ assigns[method.to_s] = Proc.new { @view.send(method) }
41
+ end
42
+
43
+ controller = @view.controller
44
+
45
+ filters = if controller.respond_to?(:liquid_filters, true)
46
+ controller.send(:liquid_filters)
47
+ elsif controller.respond_to?(:master_helper_module)
48
+ [controller.master_helper_module]
49
+ else
50
+ [controller._helpers]
51
+ end
52
+
53
+ # TODO content_for from layout to partial
54
+ #unless assigns[:layout_prerender]
55
+ # @layout = Liquid::Template.parse(Refinery::Themes::Theme.layout_raw(assigns['page'].layout_template))
56
+ # @layout.render(assigns, :registers => {:filters => filters, :action_view => @view, :controller => @view.controller})
57
+ # assigns[:layout_prerender] = true
58
+ #end
59
+
60
+ @view.view_flow.content.each do |key, content|
61
+ assigns["content_for_#{key.to_s}"] = content
62
+ end
63
+
64
+ partials_path = Liquid::LocalFileSystem.new(Refinery::Themes::Theme.theme_path.join("views/partials"))
65
+
66
+ assigns['page'].parts.each do |part|
67
+ Liquid::Template.parse(part.body).render(assigns)
68
+ assigns["content_for_#{part.title}"] =
69
+ Liquid::Template.parse(part.body).render(assigns,
70
+ :filters => filters,
71
+ :registers => {
72
+ :file_system => partials_path,
73
+ :action_view => @view,
74
+ :controller => @view.controller
75
+ }).html_safe
76
+ end if assigns['page']
77
+
78
+ variables = assigns.reject{ |k,v| PROTECTED_ASSIGNS.include?(k) }
79
+
80
+ liquid = Liquid::Template.parse(CGI::unescape(template))
81
+ liquid.render(variables, :filters => filters, :registers => {:file_system => partials_path, :action_view => @view, :controller => @view.controller})
82
+ end
83
+
84
+ def compilable?
85
+ false
86
+ end
87
+ end
88
+
@@ -0,0 +1,26 @@
1
+ class Editable
2
+ def self.mime_for(name)
3
+ case name.to_s
4
+ when /\.(png|gif|jpg|jpeg)\Z/
5
+ "image"
6
+ when /\.css\Z/
7
+ "text/css"
8
+ when /\.js\Z/
9
+ "text/javascript"
10
+ when /\.xml\Z/
11
+ "application/xml"
12
+ when /\.yml\Z/
13
+ "text/x-yaml"
14
+ when /\.json\Z/
15
+ "application/json"
16
+ when /\.txt\Z/
17
+ "text/plain"
18
+ when /\.liquid\Z/
19
+ "liquid"
20
+ when /\.(html|htm|xhtml)\Z/
21
+ "text/html"
22
+ else
23
+ "unknown_type"
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,5 @@
1
+ class Hash
2
+ def +(other)
3
+ merge(other)
4
+ end
5
+ end
@@ -0,0 +1,62 @@
1
+ module Liquid
2
+ class BaseDrop < Liquid::Drop
3
+ class_attribute :liquid_attributes
4
+ self.liquid_attributes = []
5
+ attr_reader :source
6
+ delegate :hash, :to => :source
7
+
8
+
9
+ def initialize(source)
10
+ @source = source
11
+ @liquid = liquid_attributes.inject({}) { |h, k| h.update k.to_s => @source.send(k) }
12
+ end
13
+
14
+ def before_method(method)
15
+ @liquid[method.to_s]
16
+ end
17
+
18
+ def eql?(comparison_object)
19
+ self == (comparison_object)
20
+ end
21
+
22
+ def ==(comparison_object)
23
+ self.source == (comparison_object.is_a?(self.class) ? comparison_object.source : comparison_object)
24
+ end
25
+
26
+ # converts an array of records to an array of liquid drops, and assigns the given context to each of them
27
+ def self.liquify(current_context, *records, &block)
28
+ i = -1
29
+ records =
30
+ records.inject [] do |all, r|
31
+ i+=1
32
+ attrs = (block && block.arity == 1) ? [r] : [r, i]
33
+ all << (block ? block.call(*attrs) : r.to_liquid)
34
+ all.last.context = current_context if all.last.is_a?(Liquid::Drop)
35
+ all
36
+ end
37
+ records.compact!
38
+ records
39
+ end
40
+
41
+
42
+ def id
43
+ @source.id
44
+ end
45
+
46
+ def dropped_class
47
+ @source.class
48
+ end
49
+
50
+ def errors
51
+ @source.errors
52
+ end
53
+
54
+ def collection_label
55
+ "label field"
56
+ end
57
+
58
+ def self.method_missing(symbol, *args)
59
+ [symbol]
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,46 @@
1
+ module SpreefineryThemes
2
+ class Engine < Rails::Engine
3
+ include Refinery::Engine
4
+ isolate_namespace SpreefineryThemes::Engine
5
+
6
+ engine_name :spreefinery_themes
7
+
8
+ def self.activate
9
+ #ActionController::Base.prepend_view_path(Rails.root.join("themes/#{Refinery::Themes::Theme.current_theme_key}/views"))
10
+ ActionController::Base.prepend_view_path(Rails.root.join("themes/current/views"))
11
+
12
+ Dir.glob(File.join(File.dirname(__FILE__), "../../app/**/*_decorator*.rb")) do |c|
13
+ Rails.configuration.cache_classes ? require(c) : load(c)
14
+ end
15
+
16
+ Dir.glob(File.join(File.dirname(__FILE__), "../../app/overrides/**/*.rb")) do |c|
17
+ Rails.configuration.cache_classes ? require(c) : load(c)
18
+ end
19
+
20
+ Dir[root + 'lib/liquid/**/*.rb'].each { |f| Rails.configuration.cache_classes ? require(f) : load(f) }
21
+
22
+ %w{. tags drops filters blocks}.each do |dir|
23
+ Dir[File.join(File.dirname(__FILE__), '../../app/liquid', dir, '*.rb')].each { |lib| Rails.configuration.cache_classes ? require(lib) : load(lib) }
24
+ end
25
+
26
+ # ::ActiveRecord::Base.send(:include, Liquid::ActiveRecord::Droppable)
27
+
28
+ end
29
+
30
+ initializer "register spreefinery_themes plugin" do
31
+ Refinery::Plugin.register do |plugin|
32
+ plugin.name = "spreefinery_themes"
33
+ plugin.url = proc { Refinery::Core::Engine.routes.url_helpers.themes_admin_themes_path }
34
+ plugin.pathname = root
35
+ plugin.menu_match = /refinery\/themes\/?(settings|editor|upload)?/
36
+ end
37
+ end
38
+
39
+ config.after_initialize do
40
+ Refinery.register_extension(SpreefineryThemes::Engine)
41
+ end
42
+
43
+ config.to_prepare &method(:activate).to_proc
44
+
45
+ end
46
+ end
@@ -0,0 +1,21 @@
1
+ require 'refinerycms-core'
2
+ require 'spree_core'
3
+ require 'editable'
4
+ require 'hash'
5
+ require 'clot_engine'
6
+
7
+ module SpreefineryThemes
8
+ require 'spreefinery/engine'
9
+
10
+ class << self
11
+ attr_writer :root
12
+
13
+ def root
14
+ @root ||= Pathname.new(File.expand_path('../../../', __FILE__))
15
+ end
16
+
17
+ def factory_paths
18
+ @factory_paths ||= [ root.join('spec', 'factories').to_s ]
19
+ end
20
+ end
21
+ end