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,73 @@
1
+ module Refinery
2
+ module Themes
3
+ module Admin
4
+ class EditorController < ::Refinery::AdminController
5
+
6
+ def index; end
7
+
8
+ def upload_file
9
+ @path = params[:path]
10
+ end
11
+
12
+ def upload
13
+ file = params[:file]
14
+
15
+ unless FileManager.allowed_content_type?(File.extname(file.original_filename))
16
+ notice = 'File "%s" could not be uploaded' % File.extname(file.original_filename)
17
+ else
18
+ file_path = "#{params[:path]}/#{file.original_filename}"
19
+ FileManager.save_file(file_path, file.read)
20
+ notice = "A new file was successfully uploaded!"
21
+ end
22
+ @dialog_successful = true
23
+ render :nothing => true, :layout => 'refinery/admin_dialog'
24
+ #render :action => 'index'
25
+ #redirect_to(refinery.root_themes_admin_editor_path, :notice => notice)
26
+ end
27
+
28
+ def list
29
+ @parent = params[:fullpath]
30
+ file_manager = FileManager.new(Rails.root.join("themes/#{Refinery::Themes::Theme.current_theme_key}/#{@parent}"), @parent)
31
+ render :json => file_manager.dirs.concat(file_manager.files), :layout => false
32
+ end
33
+
34
+ def file
35
+ @related_path = params[:fullpath]
36
+ file = File.join(Rails.root, "themes", Refinery::Themes::Theme.current_theme_key, params[:fullpath])
37
+ render :text => 'file not found' and return unless File.exist? file
38
+ @content = File.read(file)
39
+ @content_type = Editable.mime_for file
40
+
41
+ if @content_type == 'image'
42
+ render :inline => "<%= image_tag '#{params[:fullpath]}' %>"
43
+ else
44
+ render :layout => false
45
+ end
46
+ end
47
+
48
+ def save_file
49
+ @related_path = params[:file_name]
50
+ @content = FileManager.save_file(@related_path, params[:file_content])
51
+ @content_type = Editable.mime_for @related_path
52
+ render :template => 'refinery/themes/admin/editor/file.html.erb', :layout => false
53
+ end
54
+
55
+ def add
56
+ render(:json => FileManager.create_dir(params[:fullpath], params[:title]), :layout => false) if params[:type].eql?('folder')
57
+ render(:json => FileManager.create_file(params[:fullpath], params[:title]), :layout => false) if params[:type].eql?('default')
58
+ end
59
+
60
+ def rename
61
+ render(:json => FileManager.rename_dir(params[:fullpath], params[:new_name]), :layout => false) if params[:type].eql?('folder')
62
+ render(:json => FileManager.rename_file(params[:fullpath], params[:new_name]), :layout => false) if params[:type].eql?('default')
63
+ end
64
+
65
+ def delete
66
+ render(:json => FileManager.remove_dir(params[:fullpath]), :layout => false) if params[:type].eql?('folder')
67
+ render(:json => FileManager.remove_file(params[:fullpath]), :layout => false) if params[:type].eql?('default')
68
+ end
69
+
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,60 @@
1
+ module Refinery
2
+ module Themes
3
+ module Admin
4
+ class ThemesController < ::Refinery::AdminController
5
+
6
+ def index
7
+ @themes = Refinery::Themes::Theme.all
8
+ end
9
+
10
+ def upload; end
11
+
12
+ def settings; end
13
+
14
+ def update
15
+
16
+ end
17
+
18
+ def reset
19
+ FileUtils.rm_rf(Rails.root.join('themes', 'default')) if File.exist?(Rails.root.join('themes', 'default'))
20
+ FileManager.unzip_file(File.join(SpreefineryThemes::Engine.root, "theme_template", "default.zip"))
21
+ redirect_to themes_admin_root_url, :notice =>"The default theme successfully reset!"
22
+ end
23
+
24
+ def select_theme
25
+ ::Refinery::Setting.set(:current_theme, params[:key])
26
+ @themes = Refinery::Themes::Theme.all
27
+ FileUtils.rm_rf(Rails.root.join('themes/current'))
28
+ FileUtils.ln_sf(Refinery::Themes::Theme.theme_path, Rails.root.join('themes/current'))
29
+
30
+ ::Refinery::Page.expire_page_caching
31
+ #Rails.cache.clear
32
+
33
+
34
+ # TODO remove this hack for update current layout file.
35
+ file = File.read(Rails.root.join('themes/current/views/layouts/site.liquid'))
36
+ File.open(Rails.root.join('themes/current/views/layouts/site.liquid'), 'w+b'){|f| f.write(file)}
37
+
38
+ redirect_to themes_admin_root_url
39
+ end
40
+
41
+ def create
42
+ zipf = params[:zip_file]
43
+
44
+ directory = "/tmp/uploads"
45
+ `rm -rf "#{directory}"`
46
+ `mkdir "#{directory}"`
47
+
48
+ path = File.join(directory, zipf.original_filename)
49
+ File.open(path, "wb") { |f| f.write(zipf.read) }
50
+
51
+ FileManager.unzip_file(path)
52
+ `rm #{path}`
53
+
54
+ redirect_to themes_admin_root_url, :notice =>"A new theme was successfully uploaded and installed!"
55
+ end
56
+
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,12 @@
1
+ module Refinery
2
+ module Themes
3
+ class ThemeController < ::ApplicationController
4
+
5
+ def sreenshot
6
+ send_data IO.read(File.join(Refinery::Themes::Theme.theme_path(params[:key]), "config/image.png")),
7
+ :disposition => "inline", :stream => false
8
+ end
9
+
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,6 @@
1
+ ActionView::Base.class_eval do
2
+ include Refinery::MenuHelper
3
+ include Spree::ProductsHelper
4
+ include Spree::BaseHelper
5
+ include Spree::AnalyticsHelper
6
+ end
@@ -0,0 +1,7 @@
1
+ ApplicationController.class_eval do
2
+ layout Refinery::Themes::Theme.default_layout
3
+
4
+ #include Spree::Core::ControllerHelpers::Auth
5
+ #include Spree::Core::ControllerHelpers::Common
6
+ #include Spree::Core::ControllerHelpers::Order
7
+ end
@@ -0,0 +1,4 @@
1
+ Spree::BaseController.class_eval do
2
+ layout Refinery::Themes::Theme.default_layout
3
+ end
4
+
@@ -0,0 +1,33 @@
1
+ ActionView::Helpers::FormBuilder.class_eval do
2
+ def get_drop_class(class_obj)
3
+ begin
4
+ drop_string = class_obj.to_s + "Drop"
5
+ drop_class = drop_string.constantize
6
+ drop_class
7
+ rescue
8
+ get_drop_class class_obj.superclass
9
+ end
10
+ end
11
+
12
+ def to_liquid
13
+ drop_class = get_drop_class self.class
14
+ drop_class.new self
15
+ end
16
+ end
17
+
18
+ Spree::Money.class_eval do
19
+ def get_drop_class(class_obj)
20
+ begin
21
+ drop_string = class_obj.to_s + "Drop"
22
+ drop_class = drop_string.constantize
23
+ drop_class
24
+ rescue
25
+ get_drop_class class_obj.superclass
26
+ end
27
+ end
28
+
29
+ def to_liquid
30
+ drop_class = get_drop_class self.class
31
+ drop_class.new self
32
+ end
33
+ end
@@ -0,0 +1,23 @@
1
+ Liquid::Strainer.class_eval do
2
+ include ActionView::Context
3
+ include ActionView::Helpers
4
+
5
+ def initialize(context)
6
+ @context = context
7
+ end
8
+
9
+ def controller
10
+ @controller ||= @context.registers[:controller]
11
+ end
12
+
13
+ def action_view
14
+ @action_view ||= @context.registers[:action_view]
15
+ end
16
+
17
+ delegate :request, :to => :controller
18
+ delegate :params, :to => :request
19
+ delegate :capture, :to => :action_view
20
+ delegate :spree, :to => :action_view
21
+ #delegate :link_to, :to => :action_view
22
+
23
+ end
@@ -0,0 +1,6 @@
1
+ Refinery::Admin::PagesController.class_eval do
2
+ def load_valid_templates
3
+ @valid_layout_templates = Refinery::Themes::Theme.layouts
4
+ @valid_view_templates = Refinery::Themes::Theme.templates
5
+ end
6
+ end
@@ -0,0 +1,17 @@
1
+ Refinery::PagesController.class_eval do
2
+
3
+ protected
4
+
5
+ def render_with_templates?(render_options = {})
6
+ if Refinery::Pages.use_layout_templates && page.layout_template.present?
7
+ render_options[:layout] = page.layout_template
8
+ end
9
+ if Refinery::Pages.use_view_templates && page.view_template.present?
10
+ render_options[:action] = page.view_template
11
+ end
12
+ render render_options if render_options.any?
13
+ end
14
+
15
+
16
+
17
+ end
@@ -0,0 +1,3 @@
1
+ Refinery::SessionsController.class_eval do
2
+ layout Refinery::Themes::Theme.default_layout
3
+ end
@@ -0,0 +1,3 @@
1
+ Spree::BaseController.class_eval do
2
+ layout Refinery::Themes::Theme.default_layout
3
+ end
@@ -0,0 +1,42 @@
1
+ Spree::CheckoutController.class_eval do
2
+ respond_to :html, :json
3
+
4
+ before_filter :check_registration, :except => [:registration, :update_registration]
5
+
6
+
7
+ def registration
8
+ @user = Refinery::User.new
9
+ end
10
+
11
+ def update_registration
12
+ fire_event("spree.user.signup", :order => current_order)
13
+ # hack - temporarily change the state to something other than cart so we can validate the order email address
14
+ current_order.state = 'address'
15
+ if current_order.update_attributes(params[:order])
16
+ redirect_to checkout_path
17
+ else
18
+ @user = Refinery::User.new
19
+ render 'registration'
20
+ end
21
+ end
22
+
23
+ private
24
+
25
+ def skip_state_validation?
26
+ %w(registration update_registration).include?(params[:action])
27
+ end
28
+
29
+ # Introduces a registration step whenever the +registration_step+ preference is true.
30
+ def check_registration
31
+ return unless ::Refinery::Setting.find_or_set(:registration_step, true)
32
+ return if current_refinery_user or current_order.email
33
+ redirect_to spree.checkout_registration_path
34
+ end
35
+
36
+ # Overrides the equivalent method defined in Spree::Core. This variation of the method will ensure that users
37
+ # are redirected to the tokenized order url unless authenticated as a registered user.
38
+ def completion_route
39
+ return order_path(@order) if current_refinery_user
40
+ spree.token_order_path(@order, @order.token)
41
+ end
42
+ end
@@ -0,0 +1,25 @@
1
+ ActionView::TemplateRenderer.class_eval do
2
+ =begin
3
+ def render_with_layout(path, locals) #:nodoc:
4
+ layout = path && find_layout(path, locals.keys)
5
+ content = yield(layout)
6
+
7
+ if layout
8
+ @view.view_flow.set(:layout, content)
9
+ if layout.virtual_path.to_s.eql?("layouts/refinery/admin")
10
+ layout.render(@view, locals){ |*name| @view._layout_for(*name) }
11
+ else
12
+ liquid_render layout.render(@view, locals){ |*name| @view._layout_for(*name) }
13
+ end
14
+ else
15
+ content
16
+ end
17
+ end
18
+
19
+ def liquid_render(html)
20
+ @template = Liquid::Template.parse(html)
21
+ @template.render(@assigns).html_safe
22
+ end
23
+ =end
24
+
25
+ end
@@ -0,0 +1,9 @@
1
+ module Refinery
2
+ module Themes
3
+ module Admin
4
+ module ThemesHelper
5
+
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,36 @@
1
+ module Liquid
2
+
3
+ # Capture stores the result of a block into a variable without rendering it inplace.
4
+ #
5
+ # {% capture_variable heading %}
6
+ # {% my_tag param1:value1 param2:value2 %}
7
+ # {% endcapture_variable %}
8
+ # ...
9
+ # <h1>{{ heading }}</h1>
10
+ #
11
+ # Capture is useful for saving content for use later in your template, such as
12
+ # in a sidebar or footer.
13
+ #
14
+ class CaptureVariable < Block
15
+ Syntax = /(\w+)/
16
+
17
+ def initialize(tag_name, markup, tokens)
18
+ if markup =~ Syntax
19
+ @to = $1
20
+ else
21
+ raise SyntaxError.new("Syntax Error in 'capture_variable' - Valid syntax: capture_variable [var]")
22
+ end
23
+
24
+ super
25
+ end
26
+
27
+ def render(context)
28
+ context.scopes.last['capture_variable'] = @to
29
+ render_all(@nodelist, context)
30
+ context.scopes.last.except!('capture_variable')
31
+ ''
32
+ end
33
+ end
34
+
35
+ Template.register_tag('capture_variable', CaptureVariable)
36
+ end
@@ -0,0 +1,55 @@
1
+ module Liquid
2
+
3
+ # The content_for method allows you to insert content into a yield block in your layout.
4
+ # You only use content_for to insert content in named yields.
5
+ #
6
+ # In your layout:
7
+ # <title>{{ content_for title }}</title>
8
+ #
9
+ # In the view:
10
+ # {% content_for_title %} The title {% end_content_for_title %}
11
+ #
12
+ #
13
+ # Will produce:
14
+ # <title>The title</title>
15
+ #
16
+ #
17
+ class ContentFor < Liquid::Block
18
+ SyntaxHelp = "Syntax Error in tag 'content_for' - Valid syntax: content_for_[name]"
19
+
20
+ def initialize(tag_name, markup, tokens)
21
+ if markup =~ /(#{VariableSignature}+)/
22
+ @name = $1
23
+ else
24
+ raise SyntaxError.new(SyntaxHelp)
25
+ end
26
+
27
+ super
28
+ end
29
+
30
+ def render(context)
31
+ result = ''
32
+
33
+ context.stack do
34
+ result = render_all(@nodelist, context)
35
+ end
36
+
37
+ context.registers[:action_view].view_flow.content[@name] = '' unless context.registers[:action_view].view_flow.content.has_key? @name
38
+
39
+ context.registers[:action_view].view_flow.content[@name].concat(result.html_safe)
40
+
41
+ #context['content_for'][@name] = '' unless context['content_for'][@name]
42
+ #context['content_for'][@name].concat(result.html_safe)
43
+
44
+ ''
45
+
46
+ end
47
+
48
+ def block_delimiter
49
+ "end_#{block_name}"
50
+ end
51
+
52
+ end
53
+ end
54
+
55
+ Liquid::Template.register_tag('content_for', Liquid::ContentFor)
@@ -0,0 +1,27 @@
1
+ class RenderRSS < Liquid::Block
2
+
3
+ def initialize(tag_name, markup, tokens)
4
+ super
5
+ @markup = markup
6
+ @attributes = {}
7
+ markup.scan(Liquid::TagAttributes) do |key, value|
8
+ @attributes[key] = value
9
+ end
10
+
11
+ RestClient.get(@attributes['source']).force_encoding('UTF-8')
12
+ @parsed_rss = SimpleRSS.parse(rss_data)
13
+ end
14
+
15
+ def render(context)
16
+ rss_reg = {
17
+ "title" => @parsed_rss.title,
18
+ "items" => @parsed_rss.items.map{|u| u.stringify_keys}
19
+ }
20
+ context.stack do
21
+ context['feed'] = rss_reg
22
+ render_all(@nodelist, context)
23
+ end
24
+ end
25
+ end
26
+
27
+ Liquid::Template.register_tag('rss', RenderRSS)