Module: Zena

Defined in:
lib/gettext_strings.rb,
lib/zena.rb,
lib/zena/db.rb,
lib/zena/app.rb,
lib/zena/use.rb,
lib/zena/info.rb,
lib/zena/parser.rb,
lib/zena/remote.rb,
lib/zena/routes.rb,
lib/zena/status.rb,
lib/zena/console.rb,
lib/zena/migrator.rb,
lib/zena/use/ajax.rb,
lib/zena/use/i18n.rb,
lib/zena/use/urls.rb,
lib/zena/use/dates.rb,
lib/zena/use/forms.rb,
lib/zena/use/kpath.rb,
lib/zena/use/zazen.rb,
lib/zena/use/action.rb,
lib/zena/use/search.rb,
lib/zena/use/upload.rb,
lib/zena/acts/secure.rb,
lib/zena/code_syntax.rb,
lib/zena/foxy_parser.rb,
lib/zena/remote/mock.rb,
lib/zena/remote/node.rb,
lib/zena/site_worker.rb,
lib/zena/use/context.rb,
lib/zena/use/display.rb,
lib/zena/remote/klass.rb,
lib/zena/use/ancestry.rb,
lib/zena/use/calendar.rb,
lib/zena/use/fixtures.rb,
lib/zena/use/fulltext.rb,
lib/zena/use/ml_index.rb,
lib/zena/use/refactor.rb,
lib/zena/use/workflow.rb,
lib/zena/use/authlogic.rb,
lib/zena/use/html_tags.rb,
lib/zena/use/prop_eval.rb,
lib/zena/use/recursion.rb,
lib/zena/use/relations.rb,
lib/zena/use/rendering.rb,
lib/zena/use/zafu_eval.rb,
lib/zena/zafu_compiler.rb,
lib/zena/base_additions.rb,
lib/zena/unit/test_case.rb,
lib/zena/use/query_link.rb,
lib/zena/use/query_node.rb,
lib/zena/view/test_case.rb,
lib/zena/webdav_adapter.rb,
lib/zena/acts/enrollable.rb,
lib/zena/db_helper/mysql.rb,
lib/zena/test_controller.rb,
lib/zena/use/field_index.rb,
lib/zena/use/scope_index.rb,
lib/zena/use/test_helper.rb,
lib/zena/acts/secure_node.rb,
lib/zena/remote/interface.rb,
lib/zena/use/node_context.rb,
lib/zena/use/version_hash.rb,
lib/zena/acts/serializable.rb,
lib/zena/db_helper/sqlite3.rb,
lib/zena/parser/zazen_tags.rb,
lib/zena/remote/connection.rb,
lib/zena/use/image_builder.rb,
lib/zena/use/query_builder.rb,
lib/zena/use/query_comment.rb,
lib/zena/loader/yaml_loader.rb,
lib/zena/parser/zazen_rules.rb,
lib/zena/use/dyn_attributes.rb,
lib/zena/use/zafu_templates.rb,
lib/zena/code/default_syntax.rb,
lib/zena/use/error_rendering.rb,
lib/zena/use/zafu_attributes.rb,
lib/zena/controller/test_case.rb,
lib/zena/db_helper/postgresql.rb,
lib/zena/db_helper/abstract_db.rb,
lib/zena/integration/test_case.rb,
lib/zena/crypto_provider/initial.rb,
lib/zena/refactor/act_as_content.rb,
lib/zena/remote/serializable_array.rb,
lib/zena/use/zafu_safe_definitions.rb,
lib/zena/use/nested_attributes_alias.rb

Overview

Copyright © 2007 Gaspard Bucher

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Defined Under Namespace

Modules: Acts, App, Code, Console, Controller, CryptoProvider, DbHelper, Integration, Loader, Parser, Refactor, Remote, Routes, Status, Unit, Use, View, WebDav Classes: AccessViolation, BadConfiguration, CodeSyntax, FoxyAttachmentsParser, FoxyColumnsParser, FoxyCommentsParser, FoxyGroupsUsersParser, FoxyIformatsParser, FoxyLinksParser, FoxyNodesParser, FoxyNodesRolesParser, FoxyParser, FoxyRelationsParser, FoxyRolesParser, FoxySitesParser, FoxyUsersParser, FoxyVersionsParser, FoxyZipsParser, InvalidRecord, Migrator, RecordNotSecured, SiteWorker, TestController

Constant Summary collapse

ASSET_PORT =
Bricks.raw_config['asset_port'].to_i
LOCAL_IPS =
((Bricks.raw_config['local_ips'] || '').split(',').map(&:strip) + %w{127.0.0.1 ::1}).uniq
ENABLE_LATEX =

enable LateX post-rendering

true  && has_executable('pdflatex')
ENABLE_FOP =

enable xsl-fo post-rendering

true  && has_executable('fop', 'xsltproc')
ENABLE_MATH =
true  && has_executable('latex', 'dvips', 'convert', 'gs')
VERSION =
'1.2.7'
ROOT =
File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
ZafuCompiler =

Zena::Use::ZafuSafeDefinitions::ZafuMethods

Zafu.parser_with_rules([
  Zafu::All,
  Zena::Use::Conditional::ZafuMethods,
  Zena::Use::Context::ZafuMethods,
  Zena::Use::Urls::ZafuMethods,
  Zena::Use::ZafuAttributes::ZafuMethods,
  Zena::Use::ZafuEval::ZafuMethods,
  Zena::Use::QueryBuilder::ZafuMethods,
  # Has to come after QB
  Zena::Use::Display::ZafuMethods,
  Zena::Use::Calendar::ZafuMethods,
  Zena::Use::I18n::ZafuMethods,
  Zena::Use::Action::ZafuMethods,
  Zena::Use::Dates::ZafuMethods,
  Zena::Use::Forms::ZafuMethods,
  Zena::Use::Recursion::ZafuMethods,
  Zena::Use::Rendering::ZafuMethods,
  Zena::Use::Search::ZafuMethods,
  Zena::Use::Ajax::ZafuMethods,
  Zena::Use::ZafuSafeDefinitions::ZafuMethods,
  Zena::Acts::Enrollable::ZafuMethods,
])

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.tools_enabledObject

Returns the value of attribute tools_enabled.



36
37
38
# File 'lib/zena.rb', line 36

def tools_enabled
  @tools_enabled
end

Class Method Details

.add_inflectionsObject



202
203
204
205
206
# File 'lib/zena.rb', line 202

def add_inflections
  ActiveSupport::Inflector.inflections do |inflect|
    inflect.uncountable %w( children )
  end
end

.add_load_paths(config = nil) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/zena.rb', line 52

def add_load_paths(config = nil)
  paths_to_add = (
    Dir["#{Zena::ROOT}/vendor/gems/*/lib"] +
    Dir["#{Zena::ROOT}/vendor/plugins/*/lib"] +
    Bricks.models_paths
  )
  if config
    ["#{Zena::ROOT}/vendor", "#{Zena::ROOT}/lib"].each do |path|
      ActiveSupport::Dependencies.autoload_paths      << path
      ActiveSupport::Dependencies.autoload_once_paths << path
      $LOAD_PATH                                      << path
    end
  else
    paths_to_add.each do |path|
      $LOAD_PATH.push path
    end
  end
end

.config_gems(config) ⇒ Object



140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/zena.rb', line 140

def config_gems(config)
  gem_configuration.each do |gem_name, gem_config|
    if gem_config
      conf = gem_config.symbolize_keys
      if conf[:version]
        conf[:version].gsub!(/\A=\s*/,'')
      end
      if conf[:optional]
        if brick = conf[:brick]
          if Bricks::CONFIG[brick]
            config.gem gem_name, conf
          end
        else
          begin
            config.gem gem_name, conf
          rescue LoadError
            # ignore
          end
        end
      else
        config.gem gem_name, conf
      end
    else
      config.gem gem_name
    end
  end
end

.enable_toolsObject



75
76
77
78
# File 'lib/zena.rb', line 75

def enable_tools
  # TODO: move all code from environment.rb here...
  @tools_enabled ||= {:Latex => Zena::ENABLE_LATEX, :fop => Zena::ENABLE_FOP, :math => Zena::ENABLE_MATH}.map{|k,v| v ? k : nil}.compact
end

.gem_configurationObject



104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/zena.rb', line 104

def gem_configuration
  conf = open("#{Zena::ROOT}/config/gems.yml") {|f| YAML.load(f.read)}
  res = {}
  conf.each do |k, v|
    if v.kind_of?(String)
      res[k] = {'version' => v}
    else
      res[k] = v
    end
  end
  res
end

.gems_setupObject



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/zena.rb', line 117

def gems_setup
  gem_configuration.each do |gem_name, gem_config|
    if gem_config
      if gem_config['optional']
        if brick_name = gem_config['brick']
          unless Bricks::CONFIG[brick_name]
            next
          end
        end
        begin
          gem gem_name, gem_config['version']
        rescue LoadError
          # ignore
        end
      else
        gem gem_name, gem_config['version']
      end
    else
      gem gem_name
    end
  end
end

.has_executable(*list) ⇒ Object



16
17
18
19
20
21
# File 'lib/zena.rb', line 16

def self.has_executable(*list)
  return false if RUBY_PLATFORM =~ /mswin32/
  list.inject(true) do |s,e|
    s && !(`which #{e} || echo 'no #{e}'` =~ /^no #{e}/)
  end
end

.include_modulesObject



80
81
82
83
84
85
86
87
88
# File 'lib/zena.rb', line 80

def include_modules
  ActionController::Routing::RouteSet::Mapper.send :include, Zena::Routes


  # FIXME: make this explicit in models
  ActiveRecord::Base.send :include, Zena::Acts::Secure
  ActionController::Base.send :include, Zena::Acts::Secure

end

.initObject



225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
# File 'lib/zena.rb', line 225

def init
  config = Rails.configuration
  enable_tools
  puts "** zena #{Zena::VERSION} starting (c) Gaspard Bucher 2012"
  puts "** Bricks: #{Bricks::CONFIG.map{|k,v| k}.sort.join(', ')}"

  add_load_paths(config)
  config_gems(config)
  set_default_timezone(config)
  Zena::Db.prepare_connection

  require_ordered_dependencies

  # This is needed for idx fields taming (lock table content in OR clause).
  # Must come after 'require_ordered_dependencies' so that AfterCommit is loaded
  # before first DB usage.
  Zena::Db.insert_dummy_ids

  load_plugins if RAILS_ROOT != Zena::ROOT
  include_modules
  Bricks.load_bricks
  add_inflections
  initialize_authlogic
  initialize_gettext
end

.initialize_authlogicObject



216
217
218
# File 'lib/zena.rb', line 216

def initialize_authlogic
  require "authlogic"
end

.initialize_gettextObject



208
209
210
211
212
213
214
# File 'lib/zena.rb', line 208

def initialize_gettext
  require 'fast_gettext'

  FastGettext.add_text_domain 'zena', :path => "#{Zena::ROOT}/locale" #File.dirname(__FILE__) + '/../../locale'
  FastGettext.default_text_domain = 'zena'
  FastGettext.text_domain = 'zena'
end

.load_custom_extensionsObject



177
178
179
180
181
182
183
184
185
186
# File 'lib/zena.rb', line 177

def load_custom_extensions
  #FIXME: cleanup all these hacks !
  lib_path = File.join(Zena::ROOT, 'lib/zena')
  Dir.foreach(File.join(lib_path, 'core_ext')) do |f|
    next unless f =~ /\.rb\Z/
    require File.join(lib_path, 'core_ext', f)
  end
  require File.join(lib_path, 'base_additions')
  require File.join(lib_path, 'fix_rails_layouts.rb') # FIXME: remove when https://rails.lighthouseapp.com/projects/8994/tickets/3207 approved
end

.load_pluginsObject



168
169
170
171
172
173
174
175
# File 'lib/zena.rb', line 168

def load_plugins
  Dir.foreach("#{Zena::ROOT}/vendor/plugins") do |plugin_name|
    next if plugin_name =~ /\A\./
    require_in_lib plugin_name, "#{Zena::ROOT}/vendor/plugins"
  end
  # init.rb not evaluated in responds-to-parent
  ActionController::Base.send :include, RespondsToParent
end

.log_pathObject



71
72
73
# File 'lib/zena.rb', line 71

def log_path
  "#{RAILS_ROOT}/log/#{RAILS_ENV}.log"
end

.require_in_lib(name, dir, lib_name = nil) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/zena.rb', line 90

def require_in_lib(name, dir, lib_name = nil)
  if defined?(ActiveRecord)
    # late loading, require
    base = Dir["#{dir}/*#{name}*"].first
    lib_path = "#{base}/lib/#{lib_name || name}"
    lib_path += '.rb' unless lib_path =~ /\.rb$/
    if File.exist?(lib_path)
      require lib_path
    else
      puts "Could not require #{lib_path.inspect}"
    end
  end
end

.require_ordered_dependenciesObject

The dependencies listed here need to be loaded in this order to make sure AfterCommit is included before the first connection to the database.



190
191
192
193
# File 'lib/zena.rb', line 190

def require_ordered_dependencies
  require 'versions'
  require 'property'
end

.resolve_const(klass) ⇒ Object

Resolve a fully defined constant like ‘Bricks::Pdf::Engine::Prince’



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

def resolve_const(klass)
  if klass.kind_of?(String)
    constant = nil
    # Foo.const_get('Bar') is not guaranteed to find/load Foo::Bar, it can return just Bar.
    if klass =~ /\A[^A-Z\:]|[^0-9a-zA-Z\:]/
      raise NameError.new("Invalid constant name: #{klass.inspect}.")
    end
    eval "::#{klass}"
  else
    klass
  end
end

.set_default_timezone(config) ⇒ Object



195
196
197
198
199
200
# File 'lib/zena.rb', line 195

def set_default_timezone(config)
  # Make Active Record use UTC-base instead of local time
  # do not change this !
  ActiveRecord::Base.default_timezone = :utc
  ENV['TZ'] = 'UTC'
end

.use(*args) ⇒ Object

Nicer syntax: Zena.use Bricks:Foobar instead of Zena::Use.module Bricks::Foobar



221
222
223
# File 'lib/zena.rb', line 221

def use(*args)
  Zena::Use.module(*args)
end

Instance Method Details

#CustomGettextObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/gettext_strings.rb', line 3

def CustomGettext
  N_('help_tab')  # edit form tab name

  N_('drive_tab') # drive form tab name
  N_('links_tab') # drive form tab name

  N_('text_tab')  # edit form tab name
  N_('title_tab') # edit form tab name
  N_('import_tab') # edit form tab name
  N_('textdocument_tab')  # edit form tab
  N_('image_tab')         # edit form tab
  N_('document_tab')      # edit form tab
  N_('contact_tab')       # edit form tab

  N_('attach_img')  # version edit.rhtml
  N_('dettach_img') # version edit.rhtml

  N_('file_tab')              # document form tab name
  N_('template_tab')          # document form tab name
  N_('text_document_tab')     # document form tab name
  N_('custom_tab')            # custom form tab name

  N_('btn_add_doc') # used by zafu layout template
  N_('btn_add') # used by zafu layout template
  N_('btn_add_comment') # used by zafu layout template
  N_('btn_title_edit')
  N_('btn_title_drive')

  # admin icons
  N_('relation_img')
  N_('relations_img')
  N_('site_img')
  N_('btn_site_add')
  N_('options')
  N_('public group')
  N_('site group')
  N_('btn_relation_add')
  N_('virtual_class_img')
  N_('virtual_class_error_img')
  N_('btn_virtual_class_add')

  N_('posted by')
  N_('original by')
  N_('modified by')

  N_('img_public')         # icon
  N_('img_private')        # icon
  N_('img_custom_inherit') # icon
  N_('img_user')          # edit users (admin)
  N_('img_user_admin')    # edit users (admin)
  N_('img_user_su')       # edit users (admin)
  N_('img_user_pub')      # edit users (admin)
  N_('img_group')         # edit groups (admin)
  N_('img_group_pub')     # edit users (admin)
  N_('img_group_site')    # edit users (admin)
  N_('img_comments')          # comments
  N_('img_comments_inside')   # comments
  N_('inside')                # comments
  N_('outside')               # comments
  N_('open')                  # comments
  N_('closed')                # comments

  N_('img_prev_page')     # admin lists
  N_('img_next_page')     # admin lists

  N_('admin')             # user status
  N_('user')              # user status
  N_('commentator')       # user status
  N_('moderated')         # user status
  N_('reader')            # user status
  N_('deleted')           # user status

  N_('%{ext} document')   # alt attribute for img_tag
  N_('%{type} node')      # alt attribute for img_tag

  N_('no result found')   # search template
  N_('search results')    # search template

  N_('btn_unpublish')    # version action
  N_('btn_destroy')
  N_('btn_propose')
  N_('btn_edit')
  N_('btn_drive')
  N_('btn_refuse')
  N_('btn_destroy_version')
  N_('btn_redit')

  N_('status_50')         # published
  N_('status_60')         # proposed
  N_('status_65')         # proposed with
  N_('status_70')         # redaction
  N_('status_20')         # replaced
  N_('status_10')         # removed
  N_('status_0')          # deleted

  N_('status_50_img')         # published
  N_('status_60_img')         # proposed
  N_('status_65_img')         # proposed with
  N_('status_70_img')         # redaction
  N_('status_20_img')         # replaced
  N_('status_10_img')         # removed
  N_('status_0_img')          # deleted

  N_('en')
  N_('fr')
  N_('de')
  N_('Monday')
  N_('Tuesday')
  N_('Wednesday')
  N_('Thursday')
  N_('Friday')
  N_('Saturday')
  N_('Sunday')

  N_('datetime')          # Same as %Y-%m-%d %H:%M
  N_(Zena::Use::Dates::DATETIME)
  N_('%Y-%m-%d %H:%M')    # marked as not needed if we use the above constant...
  N_('news_date')         # calendar day (event list view)

  N_('Mon')
  N_('Tue')
  N_('Wed')
  N_('Thu')
  N_('Fri')
  N_('Sat')
  N_('Sun')

  N_('January')
  N_('February')
  N_('March')
  N_('April')
  N_('May')
  N_('June')
  N_('July')
  N_('August')
  N_('September')
  N_('October')
  N_('November')
  N_('December')

  N_('Jan')
  N_('Feb')
  N_('Mar')
  N_('Apr')
  N_('May')
  N_('Jun')
  N_('Jul')
  N_('Aug')
  N_('Sep')
  N_('Oct')
  N_('Nov')
  N_('Dec')

  N_('User name:')  # login form
  N_('Password:')   # login form

  # temporary (seems like the updatepo script does not parse 'templates' directory)
  N_('you are editing the original')
  N_('redaction saved')

  # failed to find
  N_('rebuild')     # zafu_templates.rb
  N_('rebuild_btn')     # zafu_templates.rb
  N_('turn_dev_off_btn') # zafu_templates.rb
  # contact: FIXME remove ?
  N_('first_name')
  N_('last_name')
  N_('address')
  N_('postal_code')
  N_('locality')
  N_('country')
  N_('telephone')
  N_('mobile')
  N_('email')
  N_('birthday')

  # Site actions
  N_('clear_cache')
  N_('clear_cache done.')
  N_('rebuild_index')
  N_('rebuild_index done.')

  # Column types
  N_('img_string')
  N_('img_integer')
  N_('img_float')
  N_('img_datetime')
end