Class: Humpyard::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/humpyard/config.rb

Overview

Humpyard::Config is responsible for holding and managing the configuration for your Humpyard Rails Application.

Possible configuration options are:

table_name_prefix

The prefix for the SQL tables

The default value is "humpyard_"

www_prefix

The prefix for the pages in your routes

You may use some variables that will be replaced by Humpyard::Page.human_url

":locale"

The current ::I18n.locale

Leading slashes (“/”) as it would result in invalid URLs and will be ignored.

A tailing slash (“/”) indicates, that the value should be a path. Without the tailing slash the last part would become a prefix to the pages URL. A page with the path “about/config.html” with the ::I18n.locale=“en” and the given prefix will result in:

":locale/"

"/en/about/config.html"

":locale/cms_"

"/en/cms_about_config.html"

"cms/"

"/cms/about/config.html"

"": "/about/config.html"

The default value is ":locale/"

admin_prefix

The prefix for the admin controllers

The default value is "admin"

locales

The locales used for the pages

This option can be configured by giving an Array or comma separated String, e.g. 'en,de,fr' or ['en', 'de', 'fr'].

Setting this option will also alter the HumpyardForm.config.locales to the given value

The default value is ['en']

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Config

:nodoc:



51
52
53
# File 'lib/humpyard/config.rb', line 51

def initialize(&block) #:nodoc:
  configure(&block) if block_given?
end

Instance Attribute Details

#browser_title_postfixObject

:nodoc:



146
147
148
# File 'lib/humpyard/config.rb', line 146

def browser_title_postfix #:nodoc:
  @browser_title_postfix ||= ''
end

#browser_title_prefixObject

:nodoc:



142
143
144
# File 'lib/humpyard/config.rb', line 142

def browser_title_prefix #:nodoc:
  @browser_title_prefix ||= ''
end

#compass_formatObject



206
207
208
# File 'lib/humpyard/config.rb', line 206

def compass_format
  @compass_format ||= 'scss'
end


210
211
212
# File 'lib/humpyard/config.rb', line 210

def compass_stylesheet_link_tag_path
  @compass_stylesheet_link_tag_path ||= 'compiled/'
end

#default_templateObject

:nodoc:



134
135
136
# File 'lib/humpyard/config.rb', line 134

def default_template #:nodoc:
  @default_template ||= templates.keys.first
end

#element_typesObject

:nodoc:



77
78
79
80
81
82
83
84
85
# File 'lib/humpyard/config.rb', line 77

def element_types #:nodoc:
  @element_types ||= {
    'box_element' => Humpyard::Elements::BoxElement,
    'text_element' => Humpyard::Elements::TextElement,
    'media_element' => Humpyard::Elements::MediaElement,
    'news_element' => Humpyard::Elements::NewsElement,
    'sitemap_element' => Humpyard::Elements::SitemapElement
  }
end

#js_frameworkObject



202
203
204
# File 'lib/humpyard/config.rb', line 202

def js_framework
  @js_framework ||= 'jquery-ui-18'
end

#page_typesObject

:nodoc:



87
88
89
90
91
92
93
# File 'lib/humpyard/config.rb', line 87

def page_types #:nodoc:
  @page_types ||= {
    'static' => Humpyard::Pages::StaticPage,
    'virtual' => Humpyard::Pages::VirtualPage,
    'news' => Humpyard::Pages::NewsPage
  }
end

#table_name_prefixObject

:nodoc:



61
62
63
# File 'lib/humpyard/config.rb', line 61

def table_name_prefix #:nodoc:
  @table_name_prefix ||= 'humpyard_'
end

#templatesObject

:nodoc:



102
103
104
105
106
# File 'lib/humpyard/config.rb', line 102

def templates #:nodoc:
  @templates ||= {
    'application' => {:yields => [:sidebar]}
  }
end

#users_frameworkObject



198
199
200
# File 'lib/humpyard/config.rb', line 198

def users_framework
  @users_framework ||= 'simple'
end

Instance Method Details

#admin_prefixObject

:nodoc:



162
163
164
# File 'lib/humpyard/config.rb', line 162

def admin_prefix #:nodoc:
  @admin_prefix.blank? ? 'admin' : @admin_prefix
end

#admin_prefix=(prefix) ⇒ Object



166
167
168
169
170
171
172
# File 'lib/humpyard/config.rb', line 166

def admin_prefix=(prefix)
  if prefix
    @admin_prefix = prefix.gsub /^\//, ''
  else
    @admin_prefix = nil
  end
end

#asset_typesObject

:nodoc:



95
96
97
98
99
100
# File 'lib/humpyard/config.rb', line 95

def asset_types #:nodoc:
  @asset_types ||= {
    'paperclip' => Humpyard::Assets::PaperclipAsset,
    'youtube' => Humpyard::Assets::YoutubeAsset
  }
end

#configure {|_self| ... } ⇒ Object

Configure your Humpyard Rails Application with the given parameters in the block. For possible options see above.

Yields:

  • (_self)

Yield Parameters:



57
58
59
# File 'lib/humpyard/config.rb', line 57

def configure(&block)
  yield(self)
end

#default_template_nameObject



138
139
140
# File 'lib/humpyard/config.rb', line 138

def default_template_name
  default_template.to_s
end

#localesObject

:nodoc:



187
188
189
# File 'lib/humpyard/config.rb', line 187

def locales #:nodoc:
  @locales ||= [:en]
end

#locales=(locales) ⇒ Object

:nodoc:



174
175
176
177
178
179
180
181
182
183
184
185
# File 'lib/humpyard/config.rb', line 174

def locales=(locales) #:nodoc:
  if locales.nil? 
    @locales = nil
  elsif locales.class == Array
    @locales = locales.map{|l| l.to_sym}
  else
    @locales = locales.split(',').collect{|l| l.to_sym}
  end
  
  # Keep HumpyardForm locales in sync
  HumpyardForm.config.locales = locales
end

#locales_contraintObject

Get the given locales as Regexp constraint. This may be used to see if a locale matches the configured locales. Usage is e.g. in the routes.



194
195
196
# File 'lib/humpyard/config.rb', line 194

def locales_contraint
  Regexp.new locales * '|'
end

#page_formatsObject

:nodoc:



224
225
226
# File 'lib/humpyard/config.rb', line 224

def page_formats #:nodoc:
  @page_formats ||= [:html]
end

#page_formats=(formats) ⇒ Object

:nodoc:



214
215
216
217
218
219
220
221
222
# File 'lib/humpyard/config.rb', line 214

def page_formats=(formats) #:nodoc:
  if formats.nil? 
    @page_formats = nil
  elsif formats.class == Array
    @page_formats = formats.map{|l| l.to_sym}
  else
    @page_formats = formats.split(',').collect{|l| l.to_sym}
  end
end

#page_formats_contraintObject

Get the given locales as Regexp constraint. This may be used to see if a locale matches the configured locales. Usage is e.g. in the routes.



231
232
233
# File 'lib/humpyard/config.rb', line 231

def page_formats_contraint
  Regexp.new page_formats * '|'
end

#parsed_www_prefix(params) ⇒ Object

Get the prefix of your pages with interpreted variables given as params. You normally don’t want to call it yourself. Instead use the Humpyard::Page.human_url which will put the current ::I18n.locale into the params.



154
155
156
157
158
159
160
# File 'lib/humpyard/config.rb', line 154

def parsed_www_prefix(params)
  prefix = "#{www_prefix}"
  params.each do |key,value|
    prefix.gsub!(":#{key}", value.to_s)
  end
  prefix
end

#toolbar_actionsObject

:nodoc:



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/humpyard/config.rb', line 108

def toolbar_actions #:nodoc:
  @toolbar_actions ||= {
    #'edit' => {
    #  :title => 'humpyard_cms.toolbar.edit',
    #  :command => 'toggleEditMode',
    #  :icon => 'ui-icon-pencil'
    #},
    'hy_pages' => {
      :title => 'humpyard_cms.toolbar.pages',
      :controller => '/humpyard/pages',
      :action => :index,
      :dialog => "size:800x700;dialog_id:pages-dialog",
      :icon => 'ui-icon-document',
      :class => Humpyard::Page
    },
    'hy_assets' => {
      :title => 'humpyard_cms.toolbar.assets',
      :controller => '/humpyard/assets',
      :action => :index,
      :dialog => "size:800x700;dialog_id:assets-dialog",
      :icon => 'ui-icon-video',
      :class => Humpyard::Asset
    }
  }
end

#www_prefixObject

:nodoc:



65
66
67
# File 'lib/humpyard/config.rb', line 65

def www_prefix #:nodoc:
  @www_prefix ||= ':locale/'
end

#www_prefix=(prefix) ⇒ Object



69
70
71
72
73
74
75
# File 'lib/humpyard/config.rb', line 69

def www_prefix=(prefix)
  if prefix
    @www_prefix = prefix.gsub /^\//, ''
  else
    @www_prefix = nil
  end
end