Module: Knitkit::Extensions::ActionController::ThemeSupport::ActsAsThemedController::InstanceMethods

Defined in:
lib/knitkit/extensions/action_controller/theme_support/acts_as_themed_controller.rb

Instance Method Summary collapse

Instance Method Details

#add_theme_view_pathsObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/knitkit/extensions/action_controller/theme_support/acts_as_themed_controller.rb', line 40

def add_theme_view_paths
  ThemeSupport::Cache.theme_resolvers = [] if ThemeSupport::Cache.theme_resolvers.nil?
  if respond_to?(:current_theme_paths)
    current_theme_paths.each do |theme|
      resolver = case Rails.application.config.erp_tech_svcs.file_storage
                   when :s3
                     path = File.join(theme[:url], "templates")
                     cached_resolver = ThemeSupport::Cache.theme_resolvers.find { |cached_resolver| cached_resolver.to_path == path }
                     if cached_resolver.nil?
                       resolver = ActionView::S3Resolver.new(path)
                       ThemeSupport::Cache.theme_resolvers << resolver
                       resolver
                     else
                       cached_resolver
                     end
                   when :filesystem
                     path = "#{theme[:path]}/templates"
                     cached_resolver = ThemeSupport::Cache.theme_resolvers.find { |cached_resolver| cached_resolver.to_path == path }
                     if cached_resolver.nil?
                       resolver = ActionView::ThemeFileResolver.new(path)
                       ThemeSupport::Cache.theme_resolvers << resolver
                       resolver
                     else
                       cached_resolver
                     end
                 end
      prepend_view_path(resolver)
    end
  end
end

#allowed_template_type?(ext) ⇒ Boolean

Returns:

  • (Boolean)


80
81
82
# File 'lib/knitkit/extensions/action_controller/theme_support/acts_as_themed_controller.rb', line 80

def allowed_template_type?(ext)
  force_template_types.blank? || force_template_types.include?(ext)
end

#authorize_template_extension!(template, ext) ⇒ Object

Raises:

  • (ThemeSupport::TemplateTypeError)


75
76
77
78
# File 'lib/knitkit/extensions/action_controller/theme_support/acts_as_themed_controller.rb', line 75

def authorize_template_extension!(template, ext)
  return if allowed_template_type?(ext)
  raise ThemeSupport::TemplateTypeError.new(template, force_template_types)
end

#current_theme_pathsObject



71
72
73
# File 'lib/knitkit/extensions/action_controller/theme_support/acts_as_themed_controller.rb', line 71

def current_theme_paths
  current_themes ? current_themes.map { |theme| {:path => theme.path.to_s, :url => theme.url.to_s} } : []
end

#current_themesObject



30
31
32
33
34
35
36
37
38
# File 'lib/knitkit/extensions/action_controller/theme_support/acts_as_themed_controller.rb', line 30

def current_themes
  # the lambda broke in rails 3.2, changing this to an instance variable
  @current_themes ||= self.website.themes.collect{|t| t if t.active == 1}.compact rescue []
  # @current_themes ||= case accessor = self.class.read_inheritable_attribute(:current_themes)
  # when Symbol then accessor == :current_themes ? raise("screwed") : send(accessor)
  # when Proc   then accessor.call(self)
  # else accessor
  # end
end