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,128 @@
1
+ require 'uri'
2
+
3
+ module Liquid
4
+ module Filters
5
+ # Convert a Textile string into HTML output.
6
+ #
7
+ # input - The Textile String to convert.
8
+ #
9
+ # Returns the HTML formatted String.
10
+ def textilize(input)
11
+ site = @context.registers[:site]
12
+ converter = site.getConverterImpl(Jekyll::TextileConverter)
13
+ converter.convert(input)
14
+ end
15
+
16
+ # Convert a Markdown string into HTML output.
17
+ #
18
+ # input - The Markdown String to convert.
19
+ #
20
+ # Returns the HTML formatted String.
21
+ def markdownify(input)
22
+ site = @context.registers[:site]
23
+ converter = site.getConverterImpl(Jekyll::MarkdownConverter)
24
+ converter.convert(input)
25
+ end
26
+
27
+ # Format a date in short format e.g. "27 Jan 2011".
28
+ #
29
+ # date - the Time to format.
30
+ #
31
+ # Returns the formatting String.
32
+ def date_to_string(date)
33
+ date.strftime("%d %b %Y")
34
+ end
35
+
36
+ # Format a date in long format e.g. "27 January 2011".
37
+ #
38
+ # date - The Time to format.
39
+ #
40
+ # Returns the formatted String.
41
+ def date_to_long_string(date)
42
+ date.strftime("%d %B %Y")
43
+ end
44
+
45
+ # Format a date for use in XML.
46
+ #
47
+ # date - The Time to format.
48
+ #
49
+ # Examples
50
+ #
51
+ # date_to_xmlschema(Time.now)
52
+ # # => "2011-04-24T20:34:46+08:00"
53
+ #
54
+ # Returns the formatted String.
55
+ def date_to_xmlschema(date)
56
+ date.xmlschema
57
+ end
58
+
59
+ # XML escape a string for use. Replaces any special characters with
60
+ # appropriate HTML entity replacements.
61
+ #
62
+ # input - The String to escape.
63
+ #
64
+ # Examples
65
+ #
66
+ # xml_escape('foo "bar" <baz>')
67
+ # # => "foo &quot;bar&quot; &lt;baz&gt;"
68
+ #
69
+ # Returns the escaped String.
70
+ def xml_escape(input)
71
+ CGI.escapeHTML(input)
72
+ end
73
+
74
+ # CGI escape a string for use in a URL. Replaces any special characters
75
+ # with appropriate %XX replacements.
76
+ #
77
+ # input - The String to escape.
78
+ #
79
+ # Examples
80
+ #
81
+ # cgi_escape('foo,bar;baz?')
82
+ # # => "foo%2Cbar%3Bbaz%3F"
83
+ #
84
+ # Returns the escaped String.
85
+ def cgi_escape(input)
86
+ CGI::escape(input)
87
+ end
88
+
89
+ def uri_escape(input)
90
+ URI.escape(input)
91
+ end
92
+
93
+ # Count the number of words in the input string.
94
+ #
95
+ # input - The String on which to operate.
96
+ #
97
+ # Returns the Integer word count.
98
+ def number_of_words(input)
99
+ input.split.length
100
+ end
101
+
102
+ # Join an array of things into a string by separating with commes and the
103
+ # word "and" for the last one.
104
+ #
105
+ # array - The Array of Strings to join.
106
+ #
107
+ # Examples
108
+ #
109
+ # array_to_sentence_string(["apples", "oranges", "grapes"])
110
+ # # => "apples, oranges, and grapes"
111
+ #
112
+ # Returns the formatted String.
113
+ def array_to_sentence_string(array)
114
+ connector = "and"
115
+ case array.length
116
+ when 0
117
+ ""
118
+ when 1
119
+ array[0].to_s
120
+ when 2
121
+ "#{array[0]} #{connector} #{array[1]}"
122
+ else
123
+ "#{array[0...-1].join(', ')}, #{connector} #{array[-1]}"
124
+ end
125
+ end
126
+
127
+ end
128
+ end
@@ -0,0 +1,28 @@
1
+ module Protected
2
+ extend ERB::Util
3
+ extend ActionView::Helpers
4
+ extend ActionView::Helpers::UrlHelper
5
+ extend ActionView::Helpers::TagHelper
6
+ #extend ActionView::Context
7
+
8
+
9
+ class << self
10
+ include ActionDispatch::Routing
11
+ include Rails.application.routes.url_helpers
12
+ include Refinery::Core::Engine.routes.url_helpers
13
+ include Spree::Core::Engine.routes.url_helpers
14
+
15
+ def config=(controller)
16
+ @controller = controller
17
+ end
18
+
19
+ def config
20
+ @controller
21
+ end
22
+
23
+ def controller
24
+ @controller
25
+ end
26
+ end
27
+
28
+ end
@@ -0,0 +1,73 @@
1
+ module RailsFilters
2
+
3
+ def truncate(text, length = 50)
4
+ Protected.truncate(text, length)
5
+ end
6
+
7
+
8
+ def yaml_to_hash(str)
9
+ YAML.load(str)
10
+ end
11
+
12
+ def to_json(value)
13
+ value.to_json
14
+ end
15
+
16
+ def url_encode(value)
17
+ CGI::escape(value || '')
18
+ end
19
+
20
+ def url_decode(value)
21
+ CGI::unescape(value || '')
22
+ end
23
+
24
+ def time_now(format)
25
+ Time.now.strftime(format)
26
+ end
27
+
28
+ def script_tag(url)
29
+ Protected.config = @context.registers[:controller]
30
+ Protected.javascript_include_tag url
31
+ end
32
+
33
+ def stylesheet_tag(url)
34
+ return '' if url.blank?
35
+
36
+ Protected.config = @context.registers[:controller]
37
+ Protected.stylesheet_link_tag url
38
+ end
39
+
40
+ def image_tag(url, title = nil, size = nil)
41
+ return '' if url.blank?
42
+
43
+ Protected.config = @context.registers[:controller]
44
+
45
+ options = title.present? ? {:title => title, :alt => title} : {}
46
+ options[:size] = size if size.present?
47
+ Protected.image_tag url, options
48
+ end
49
+
50
+ def link_to(text, url)
51
+ Protected.link_to text, url
52
+ end
53
+
54
+ def url_helper(url_helper, object=nil)
55
+ return if url_helper.nil?
56
+ Protected.config = @context.registers[:controller]
57
+
58
+ if object.nil?
59
+ Protected.send(url_helper.to_sym) || 'not found'
60
+ else
61
+ Protected.send(url_helper.to_sym, object.source) || 'not found'
62
+ end
63
+
64
+ end
65
+
66
+ def url_for(obj)
67
+ Protected.config = @context.registers[:controller]
68
+ Protected.url_for(obj) || 'not found'
69
+ end
70
+
71
+ end
72
+
73
+ Liquid::Template.register_filter RailsFilters
@@ -0,0 +1,63 @@
1
+ # {% cache "some_key" %}
2
+ # ...
3
+ # {% endcache %}
4
+
5
+ class Cacher < Liquid::Tag
6
+ def initialize(tag_name, markup, tokens)
7
+ super
8
+ @key= markup.to_s
9
+ end
10
+
11
+ def render(context)
12
+ Rails.cache.fetch(@key) do
13
+ super
14
+ end
15
+ end
16
+ end
17
+
18
+ Liquid::Template.register_tag('cache', Cacher)
19
+
20
+ ########################################################################################################################
21
+
22
+ class ImageTag < Liquid::Tag
23
+
24
+ def initialize(tag_name, markup, tokens)
25
+ unless markup.empty?
26
+ if markup =~ /url:([*.]+)/
27
+ @url = $1
28
+ end
29
+ end
30
+ super
31
+ end
32
+
33
+ def render(context)
34
+ context.registers[:action_view].image_tag(@url)
35
+ end
36
+ end
37
+
38
+ Liquid::Template.register_tag('image_tag', ImageTag)
39
+
40
+ class TagBuilder < Liquid::Tag
41
+ QuotedString = /"[^"]*"|'[^']*'/
42
+ QuotedFragment = /#{QuotedString}|(?:[^\s,\|'"]|#{QuotedString})+/o
43
+ TagAttributes = /(\w+)\s*\:\s*(#{QuotedFragment})/o
44
+
45
+ def initialize(tag_name, markup, tokens)
46
+ unless markup.empty?
47
+ @attributes = {}
48
+ markup.scan(Liquid::TagAttributes) do |key, value|
49
+ @attributes[key] = value
50
+ end
51
+ end
52
+ super
53
+ end
54
+
55
+ def render(context)
56
+ if @attributes.has_key?('html')
57
+ @attributes['html'] = eval(@attributes['html'].chomp('"').reverse.chomp('"').reverse)
58
+ end
59
+ context['form'].send(@attributes['tag'].to_sym, @attributes.except('tag'))
60
+ end
61
+ end
62
+
63
+ Liquid::Template.register_tag('tag_builder', TagBuilder)
@@ -0,0 +1,33 @@
1
+ class BootstrapPagesMenu < Liquid::Tag
2
+ def initialize(tag_name, block, tokens)
3
+ super
4
+ @name = block
5
+ end
6
+
7
+ def render(context)
8
+ context.registers[:controller].render :partial => "refinery/shared/pages_menu"
9
+ end
10
+ end
11
+
12
+ Liquid::Template.register_tag('bootstrap_pages_menu', BootstrapPagesMenu)
13
+
14
+ ########################################################################################################################
15
+
16
+ class RefineryPagesMenu < Liquid::Tag
17
+ def initialize(tag_name, block, tokens)
18
+ super
19
+ @name = block
20
+ end
21
+
22
+ def render(context)
23
+ if context['capture_variable']
24
+ context[context['capture_variable']] ||= context.registers[:action_view].refinery_menu_pages.roots.inject([]) { |ary, menu_item| ary << Refinery::MenuItemDrop.new(menu_item); ary }
25
+ else
26
+ context['pages_roots'] ||= context.registers[:action_view].refinery_menu_pages.roots.inject([]) { |ary, menu_item| ary << Refinery::MenuItemDrop.new(menu_item); ary }
27
+ end
28
+
29
+ ''
30
+ end
31
+ end
32
+
33
+ Liquid::Template.register_tag('refinery_pages_menu', RefineryPagesMenu)
@@ -0,0 +1,164 @@
1
+ class ImageForProduct < Liquid::Tag
2
+
3
+ def initialize(tag_name, markup, tokens)
4
+ unless markup.empty?
5
+ if markup =~ /style:([-_a-z0-9]+)/
6
+ @style = $1
7
+ end
8
+ end
9
+
10
+ super
11
+ end
12
+
13
+ def render(context)
14
+ context.registers[:action_view].send("#{@style}_image".to_sym, context["product"].source)
15
+ end
16
+ end
17
+
18
+ Liquid::Template.register_tag('image_for_product', ImageForProduct)
19
+
20
+ ########################################################################################################################
21
+
22
+ class VariantsFor < Liquid::Tag
23
+
24
+ def initialize(tag_name, markup, tokens)
25
+ unless markup.empty?
26
+ if markup =~ /([-_a-z0-9]+)/
27
+ @object = $1
28
+ end
29
+ end
30
+
31
+ super
32
+ end
33
+
34
+
35
+ def render(context)
36
+ return "object with name #{@object} not found" if context[@object].nil?
37
+ @product = context[@object].source
38
+ context.registers[:action_view].render(:partial => 'spree/products/variants')
39
+ end
40
+ end
41
+
42
+ Liquid::Template.register_tag('variants_for', VariantsFor)
43
+
44
+ ########################################################################################################################
45
+
46
+
47
+ class ProductImageUrl < Liquid::Tag
48
+
49
+ def initialize(tag_name, markup, tokens)
50
+ unless markup.empty?
51
+ if markup =~ /style:([-_a-z0-9]+)/
52
+ @style = $1
53
+ end
54
+
55
+ if markup =~ /object:([-_a-z0-9]+)/
56
+ @object = $1
57
+ end
58
+ end
59
+
60
+ @object ||= 'product'
61
+
62
+ super
63
+ end
64
+
65
+ def render(context)
66
+ context[@object].source.images.first.attachment.url(@style.to_sym)
67
+ end
68
+ end
69
+
70
+ Liquid::Template.register_tag('product_image_url', ProductImageUrl)
71
+
72
+ ########################################################################################################################
73
+
74
+ class GetProducts < Liquid::Tag
75
+
76
+ def initialize(tag_name, markup, tokens)
77
+ unless markup.empty?
78
+ if markup =~ /per_page:(\d+)/
79
+ @per_page = $1.to_i
80
+ end
81
+
82
+ if markup =~ /type:([-_a-z0-9]+)/
83
+ @type = $1
84
+ end
85
+ end
86
+
87
+ @per_page ||= 5
88
+
89
+ super
90
+ end
91
+
92
+ def render(context)
93
+ @searcher = Spree::Config.searcher_class.new(context.registers[:controller].params)
94
+ @searcher.current_user = context.registers[:controller].try_spree_current_user
95
+ @searcher.current_currency = context.registers[:action_view].current_currency
96
+ @products = @searcher.retrieve_products
97
+
98
+ if @type == 'latest'
99
+
100
+ end
101
+
102
+ if context['capture_variable']
103
+ context[context['capture_variable']] ||= @products.per(@per_page)
104
+ else
105
+ context['products'] ||= @products.per(@per_page)
106
+ end
107
+
108
+ ''
109
+ end
110
+ end
111
+
112
+ Liquid::Template.register_tag('get_products', GetProducts)
113
+
114
+ ########################################################################################################################
115
+
116
+
117
+ class GetProductsByTaxon < Liquid::Tag
118
+
119
+ def initialize(tag_name, markup, tokens)
120
+ unless markup.empty?
121
+ if markup =~ /per_page:(\d+)/
122
+ @per_page = $1.to_i
123
+ end
124
+
125
+ if markup =~ /taxon:([\/-_a-z0-9]+)/
126
+ @taxon_name = $1
127
+ end
128
+
129
+ if markup =~ /type:([_a-z0-9]+)/
130
+ @type = $1
131
+ end
132
+ end
133
+
134
+ @per_page ||= 5
135
+
136
+ super
137
+ end
138
+
139
+ def render(context)
140
+ @taxon = Spree::Taxon.find_by_permalink!(@taxon_name)
141
+ return unless @taxon
142
+
143
+ context[@taxon_name] = @taxon
144
+
145
+ @searcher = Spree::Config.searcher_class.new(context.registers[:controller].params.merge(:taxon => @taxon.id))
146
+ @searcher.current_user = context.registers[:controller].spree_current_user
147
+ @searcher.current_currency = Spree::Config[:currency]
148
+ @products = @searcher.retrieve_products
149
+
150
+ if @type == 'latest'
151
+
152
+ end
153
+
154
+ if context['capture_variable']
155
+ context[context['capture_variable']] = @products.per(@per_page)
156
+ else
157
+ context['products'] = @products.per(@per_page)
158
+ end
159
+
160
+ ''
161
+ end
162
+ end
163
+
164
+ Liquid::Template.register_tag('get_products_by_taxon', GetProductsByTaxon)