Module: RightRails::Config

Defined in:
lib/right_rails/config.rb

Overview

RightRails configuration interface

You can adjust the following settings with the RightRails::Config object

  • RightRails::Config.env auto, production or development

  • RightRails::Config.public_path auto or some string

  • RightRails::Config.locales_path auto or some string

  • RightRails::Config.safe_mode auto, true or false

  • RightRails::Config.rightjs_version auto, 2 or 1

  • RightRails::Config.include_rails_module true or false

  • RightRails::Config.swap_builds_and_sources true or false

  • RightRails::Config.include_scripts_automatically true or false

  • RightRails::Config.use_cdn_in_production false or true

  • RigthRails::Config.cdn_url ‘cdn.rightjs.org

When you set a property in auto then the script will try to figure the parameters out by the current environment and the content of the public/javascript/right.js file

Constant Summary collapse

DEFAULT_PUBLIC_PATH =

‘auto’ or some path

'auto'
DEFAULT_SAFE_MODE =

‘auto’, true or false

'auto'
DEFAULT_RIGHTJS_VERSION =

‘auto’, 2 or 1

'auto'
DEFAULT_ENVIRONMENT =

‘auto’, ‘production’ or ‘development’

'auto'
DEFAULT_RIGHTJS_LOCATION =
'javascripts/right.js'
DEFAULT_LOCALES_LOCATION =
'javascripts/right/i18n'
DEFAULT_CDN_URL =
'http://cdn.rightjs.org'
DEFAULT_USE_CDN =

false or true

false
DEFAULT_INCLUDE_RAILS =

true or false

true
DEFAULT_AUTO_INCLUDES =

true or false

true
DEFAULT_SWAP_BUILDS =

true or false

true

Class Method Summary collapse

Class Method Details

.cdn_urlObject

Returns the current CDN Server URL address



280
281
282
283
284
285
286
# File 'lib/right_rails/config.rb', line 280

def cdn_url
  unless defined?(@cdn_url)
    self.cdn_url = DEFAULT_CDN_URL
  end

  @cdn_url
end

.cdn_url=(value) ⇒ Object

Sets a new CDN Server url address



291
292
293
# File 'lib/right_rails/config.rb', line 291

def cdn_url=(value)
  @cdn_url = value
end

.dev_env?Boolean

Returns a marker if we are in the development environment

Returns:

  • (Boolean)


87
88
89
# File 'lib/right_rails/config.rb', line 87

def dev_env?
  env == 'development'
end

.envObject

Returns the currently used environment

By default will use the Rails.env



57
58
59
60
61
62
63
# File 'lib/right_rails/config.rb', line 57

def env
  unless defined?(@environment)
    self.env = DEFAULT_ENVIRONMENT
  end

  @environment
end

.env=(value) ⇒ Object

Sets the current environment, which will effectively make RightRails to switch between the builds and src versions of right.js and modules

You can use ‘production’, ‘development’ or ‘auto’



72
73
74
75
76
77
78
79
80
81
82
# File 'lib/right_rails/config.rb', line 72

def env=(value)
  if value == 'auto'
    value = if in_rails?
      Rails.env
    else
      "production"
    end
  end

  @environment = value.to_s == 'production' ? 'production' : 'development'
end

.include_rails_moduleObject Also known as: include_rails_module?

Returns a marker if the script should automatically include the ruby-on-rails module for RightJS



200
201
202
203
204
205
206
# File 'lib/right_rails/config.rb', line 200

def include_rails_module
  unless defined?(@include_rails)
    self.include_rails_module = DEFAULT_INCLUDE_RAILS
  end

  @include_rails
end

.include_rails_module=(value) ⇒ Object

Sets the marker if the plugin should automatically include the ruby-on-rails module for RightJS



212
213
214
# File 'lib/right_rails/config.rb', line 212

def include_rails_module=(value)
  @include_rails = !! value
end

.include_scripts_automaticallyObject Also known as: include_scripts_automatically?

Checks if the plugin should include JavaScript modules automatically when they needed



241
242
243
244
245
246
247
# File 'lib/right_rails/config.rb', line 241

def include_scripts_automatically
  unless defined?(@auto_includes)
    self.include_scripts_automatically = DEFAULT_AUTO_INCLUDES
  end

  @auto_includes
end

.include_scripts_automatically=(value) ⇒ Object

Sets the marker if the plugin should automatically include all the JavaScript files on the page when they needed



253
254
255
# File 'lib/right_rails/config.rb', line 253

def include_scripts_automatically=(value)
  @auto_includes = !! value
end

.locales_pathObject

Returns a full-path to the localization modules directory



129
130
131
132
133
134
135
# File 'lib/right_rails/config.rb', line 129

def locales_path
  unless defined?(@locales_path)
    self.locales_path = "#{public_path}/#{DEFAULT_LOCALES_LOCATION}"
  end

  @locales_path
end

.locales_path=(path) ⇒ Object

Sets the RightJS localilzation modules directory path



140
141
142
143
144
145
146
147
# File 'lib/right_rails/config.rb', line 140

def locales_path=(path)
  # getting rid of the trailing slash
  if path.slice(path.size-1, path.size) == '/'
    path = path.slice(0, path.size-1)
  end

  @locales_path = path
end

.public_pathObject

Returns the public_html directory path

By default it will return the Rails.public_path



96
97
98
99
100
101
102
# File 'lib/right_rails/config.rb', line 96

def public_path
  unless defined?(@public_path)
    self.public_path = DEFAULT_PUBLIC_PATH
  end

  @public_path
end

.public_path=(path) ⇒ Object

If you have your public_html somewhere else this is the place where you can define it



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/right_rails/config.rb', line 108

def public_path=(path)
  if path == 'auto'
    path = self.public_path = if in_rails?
      Rails.public_path
    else
      # TODO other frameworks handling in here
      "public"
    end
  end

  # getting rid of the trailing slash
  if path.slice(path.size-1, path.size) == '/'
    path = path.slice(0, path.size-1)
  end

  @public_path = path.dup
end

.reset!Object

Resetting the configuration to the defaults



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/right_rails/config.rb', line 39

def reset!
  remove_instance_variable(:@environment)     if defined?(@environment)
  remove_instance_variable(:@public_path)     if defined?(@public_path)
  remove_instance_variable(:@locales_path)    if defined?(@locales_path)
  remove_instance_variable(:@safe_mode)       if defined?(@safe_mode)
  remove_instance_variable(:@rightjs_version) if defined?(@rightjs_version)
  remove_instance_variable(:@include_rails)   if defined?(@include_rails)
  remove_instance_variable(:@auto_includes)   if defined?(@auto_includes)
  remove_instance_variable(:@swap_builds)     if defined?(@swap_builds)
  remove_instance_variable(:@use_cdn)         if defined?(@use_cdn)
  remove_instance_variable(:@cdn_url)         if defined?(@cdn_url)
end

.rightjs_versionObject

Returns the RightJS version (2 or 1)



174
175
176
177
178
179
180
# File 'lib/right_rails/config.rb', line 174

def rightjs_version
  unless defined?(@rightjs_version)
    self.rightjs_version = DEFAULT_RIGHTJS_VERSION
  end

  @rightjs_version
end

.rightjs_version=(value) ⇒ Object

With this method you can set up which version of RightJS do you use 2 or 1. You also can set it to a string ‘auto’ (by default) in which case it will try to figure it out by reading the ‘public/javascripts/right.js` file



188
189
190
191
192
193
194
# File 'lib/right_rails/config.rb', line 188

def rightjs_version=(value)
  if value == 'auto'
    value = read_rightjs_file =~ /version\s*(:|=)\s*("|')1/ ? 1 : 2
  end

  @rightjs_version = value < 2 ? 1 : 2
end

.safe_modeObject Also known as: safe_mode?

Checks if the RightJS is used in the safe-mode



152
153
154
155
156
157
158
# File 'lib/right_rails/config.rb', line 152

def safe_mode
  unless defined?(@safe_mode)
    self.safe_mode = DEFAULT_SAFE_MODE
  end

  @safe_mode
end

.safe_mode=(value) ⇒ Object

Setup whether RightJS is used in the safe-mode or not

You can use boolean values or a string ‘auto’ (default) in which case it will try to figure it out by reading the ‘public/javascripts/right.js` file



167
168
169
# File 'lib/right_rails/config.rb', line 167

def safe_mode=(value)
  @safe_mode = !!(value == 'auto' ? read_rightjs_file =~ /\.safe\s*=\s*true/ : value)
end

.swap_builds_and_sourcesObject Also known as: swap_builds_and_sources?

Checks if the plugin should automatically swap between the builds and the source-versions of JavaScript files depending on current environment



221
222
223
224
225
226
227
# File 'lib/right_rails/config.rb', line 221

def swap_builds_and_sources
  unless defined?(@swap_builds)
    self.swap_builds_and_sources = DEFAULT_SWAP_BUILDS
  end

  @swap_builds
end

.swap_builds_and_sources=(value) ⇒ Object

Sets the marker if the plugin should automatically swap between source and builds of JavaScript files



233
234
235
# File 'lib/right_rails/config.rb', line 233

def swap_builds_and_sources=(value)
  @swap_builds = !! value
end

.use_cdn_in_productionObject Also known as: use_cdn_in_production?

Checks if the plugin going to automatically use CDN Server in production instead of local files



261
262
263
264
265
266
267
# File 'lib/right_rails/config.rb', line 261

def use_cdn_in_production
  unless defined?(@use_cdn)
    self.use_cdn_in_production = DEFAULT_USE_CDN
  end

  @use_cdn
end

.use_cdn_in_production=(value) ⇒ Object

Sets the marker if the plugin should automatically use CDN Server in production instead of the local files



273
274
275
# File 'lib/right_rails/config.rb', line 273

def use_cdn_in_production=(value)
  @use_cdn = !! value
end