Module: KitModulesHelper
- Defined in:
- app/helpers/kit_modules_helper.rb
Instance Method Summary collapse
- #kit_asset(id, size = :original, options = {}) ⇒ Object
- #kit_asset_src(id, size = :original, missing = "/images/not-found.png") ⇒ Object
- #kit_asset_tagged(tag, size = :original, options = {}) ⇒ Object
- #kit_asset_tagged_src(tag, size = :original, missing = "/images/not-found.png") ⇒ Object
- #kit_block(id, version = 0) ⇒ Object
- #kit_block_without_instance(id, options = {}) ⇒ Object
- #kit_calendar(calendar_id, options = {}) ⇒ Object
- #kit_calendar_entry(id, options = {}) ⇒ Object
- #kit_calendar_entry_add(calendar_id, options = {}) ⇒ Object
- #kit_code(name) ⇒ Object
- #kit_current_month(format = '%b') ⇒ Object
- #kit_current_year ⇒ Object
- #kit_dated_snippet_line(id) ⇒ Object
- #kit_editable_block(instance_id, block_id, defaults = {}) ⇒ Object
- #kit_form(id, show_title = false, show_body = false, no_permissions = "You need to sign in to see this") ⇒ Object
- #kit_form_edit_submission(id, submission_id, show_title = false, show_body = false, no_permissions = "You need to sign in to see this") ⇒ Object
-
#kit_forums_favourites(count = 5, options = {}) ⇒ Object
also ‘threads I’m watching’.
- #kit_forums_recent_posts(count = 5, options = {}) ⇒ Object
- #kit_forums_recent_threads_from_category_id(category_id, count = 5, options = {}) ⇒ Object
- #kit_forums_recent_threads_from_topic_id(topic_id, count = 5, options = {}) ⇒ Object
- #kit_forums_threads_im_on(count = 5, options = {}) ⇒ Object
- #kit_forums_topics ⇒ Object
- #kit_forums_topics_from_category_id(category_id) ⇒ Object
- #kit_gallery(id) ⇒ Object
- #kit_map(location, title = "", height = 400, width = 400) ⇒ Object
- #kit_menu(id) ⇒ Object
- #kit_page_field(page_id, field_name, is_template = false) ⇒ Object
- #kit_page_list(options = {}) ⇒ Object
- #kit_page_terms(id) ⇒ Object
- #kit_page_terms_by_ids(ids) ⇒ Object
- #kit_random_snippet_line(id) ⇒ Object
- #kit_rss_feed(rss, opts = {}) ⇒ Object
- #kit_search ⇒ Object
- #kit_signin_form(options = {}) ⇒ Object
- #kit_slideshow(id, options) ⇒ Object
- #kit_snippet(id, default = nil, sid = nil) ⇒ Object
- #kit_snippet!(sid, id) ⇒ Object
- #kit_template_block(instance_id, block_id, defaults = {}) ⇒ Object
-
#kit_term_child_list(term_id, page_template_id, parent_value) ⇒ Object
requires a block to which this will yield for each child term of the given parent.
- #kit_term_options(term_id, page_template_id) ⇒ Object
-
#kit_term_parent_list(term_id, page_template_id) ⇒ Object
requires a block to which this will yield for each parent term found, OR returns an array of arrays.
- #kit_users_email ⇒ Object
- #kit_view(id) ⇒ Object
Instance Method Details
#kit_asset(id, size = :original, options = {}) ⇒ Object
105 106 107 108 109 110 111 112 |
# File 'app/helpers/kit_modules_helper.rb', line 105 def kit_asset(id, size = :original, = {}) src = Asset.asset_url(_sid, id, size) if src return image_tag src, else return "image '#{id}' not found" end end |
#kit_asset_src(id, size = :original, missing = "/images/not-found.png") ⇒ Object
100 101 102 103 |
# File 'app/helpers/kit_modules_helper.rb', line 100 def kit_asset_src(id, size = :original, missing = "/images/not-found.png") src = Asset.asset_url(_sid, id, size) return src ? src : missing end |
#kit_asset_tagged(tag, size = :original, options = {}) ⇒ Object
119 120 121 122 123 124 125 126 |
# File 'app/helpers/kit_modules_helper.rb', line 119 def kit_asset_tagged(tag, size = :original, = {}) src = Asset.asset_tagged_url(_sid, tag, size) if src return image_tag src, else return "image '#{tag}' not found" end end |
#kit_asset_tagged_src(tag, size = :original, missing = "/images/not-found.png") ⇒ Object
114 115 116 117 |
# File 'app/helpers/kit_modules_helper.rb', line 114 def kit_asset_tagged_src(tag, size = :original, missing = "/images/not-found.png") src = Asset.asset_tagged_url(_sid, tag, size) return src ? src : missing end |
#kit_block(id, version = 0) ⇒ Object
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 |
# File 'app/helpers/kit_modules_helper.rb', line 278 def kit_block(id, version=0) if id.is_number? @instance = BlockInstance.where(:version=>version).sys(_sid).where(:id=>id).first else @instance = BlockInstance.where(:version=>version).sys(_sid).where(:instance_id=>id).first end if @instance begin (render :inline=>@instance.render).html_safe rescue Exception => e logger.debug("***** Block error: #{e.}") e. end else "[Block instance missing '#{id}']" end end |
#kit_block_without_instance(id, options = {}) ⇒ Object
268 269 270 271 272 273 274 275 276 |
# File 'app/helpers/kit_modules_helper.rb', line 268 def kit_block_without_instance(id, = {}) @block = Block.cache_get(_sid, id) if @block render :inline=>@block.render_preview() else "[Block definition missing '#{id}']" end end |
#kit_calendar(calendar_id, options = {}) ⇒ Object
204 205 206 |
# File 'app/helpers/kit_modules_helper.rb', line 204 def kit_calendar(calendar_id, = {}) module_kit_calendar(calendar_id, ) end |
#kit_calendar_entry(id, options = {}) ⇒ Object
200 201 202 |
# File 'app/helpers/kit_modules_helper.rb', line 200 def kit_calendar_entry(id, = {}) module_kit_calendar_entry(id, ) end |
#kit_calendar_entry_add(calendar_id, options = {}) ⇒ Object
196 197 198 |
# File 'app/helpers/kit_modules_helper.rb', line 196 def kit_calendar_entry_add(calendar_id, = {}) module_kit_calendar_entry_add(calendar_id, ) end |
#kit_code(name) ⇒ Object
369 370 371 |
# File 'app/helpers/kit_modules_helper.rb', line 369 def kit_code(name) eval(name) end |
#kit_current_month(format = '%b') ⇒ Object
264 265 266 |
# File 'app/helpers/kit_modules_helper.rb', line 264 def kit_current_month(format = '%b') Time.now.strftime(format) end |
#kit_current_year ⇒ Object
260 261 262 |
# File 'app/helpers/kit_modules_helper.rb', line 260 def kit_current_year Time.now.strftime("%Y") end |
#kit_dated_snippet_line(id) ⇒ Object
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 |
# File 'app/helpers/kit_modules_helper.rb', line 233 def kit_dated_snippet_line(id) begin lines = Snippet.parse_lines(id, _sid) return "snippet '#{id}' not found" unless lines current = 'none' now = Time.now lines.each do |line| if line =~ /^(\d\d)\/(\d\d)\/(\d\d)\:(.*)$/ date = DateTime.new((2000+$3.to_i),$2.to_i,$1.to_i) if date > now return current.html_safe else current = $4 end end end return current.html_safe rescue Exception => e logger.debug("Error with kit_dated_snippet_line") logger.debug(e) logger.debug(e.backtrace.join("\r\n")) return "error" end end |
#kit_editable_block(instance_id, block_id, defaults = {}) ⇒ Object
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 |
# File 'app/helpers/kit_modules_helper.rb', line 300 def kit_editable_block(instance_id, block_id, defaults = {}) block_instance = @page.block_instances.where(:instance_id=>instance_id).where(:version=>params[:version]||0).first unless block_instance block_instance = @page.generate_block_instance(instance_id, block_id, defaults, current_user.id) end = block_instance.render block_rendered = render :inline=> r = %? <div class='mercury-region' data-type='snippetable' data-fieldid='#{instance_id}' data-field='#{instance_id}' id='#{instance_id}'><div class="mercury-snippet" data-snippet="#{instance_id}">#{block_rendered.html_safe}</div></div> ?.html_safe end |
#kit_form(id, show_title = false, show_body = false, no_permissions = "You need to sign in to see this") ⇒ Object
373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 |
# File 'app/helpers/kit_modules_helper.rb', line 373 def kit_form(id, show_title = false, show_body = false, ="You need to sign in to see this") begin if id.is_number? form = Form.where(:id=>id).sys(_sid).first else form = Form.where(:url=>id).sys(_sid).first end if form if form.public_creatable || (current_user && form.user_creatable) kit_render(:partial=>"form/show", :locals=>{:form=>form, :show_title=>show_title, :show_body=>show_body, :submission=>nil}) else end else "[Form missing #{id}]" end rescue Exception => e logger.error e. logger.error e.backtrace.join("\n") Event.store("Form render error", request, current_user ? current_user.id : nil, e. + "\n" + e.backtrace.join("\n"), "form #{form.id}") end end |
#kit_form_edit_submission(id, submission_id, show_title = false, show_body = false, no_permissions = "You need to sign in to see this") ⇒ Object
397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 |
# File 'app/helpers/kit_modules_helper.rb', line 397 def kit_form_edit_submission(id, submission_id, show_title = false, show_body = false, ="You need to sign in to see this") if id.is_number? form = Form.where(:id=>id).sys(_sid).first else form = Form.where(:url=>id).sys(_sid).first end sub = form.form_submissions.where(:id=>params[:edit]).first if form if sub && form if sub.can_edit?(current_user) kit_render(:partial=>"form/show", :locals=>{:form=>form, :show_title=>show_title, :show_body=>show_body, :submission=>sub}) else end else "[Form missing or submission missing #{id} - #{submission_id}]" end end |
#kit_forums_favourites(count = 5, options = {}) ⇒ Object
also ‘threads I’m watching’
140 141 142 143 144 145 146 147 148 149 150 |
# File 'app/helpers/kit_modules_helper.rb', line 140 def kit_forums_favourites(count=5, ={}) # also 'threads I'm watching' @user_options ||= ForumUser.load(current_user) mod = can?(:moderate, ForumController) if current_user threads = current_user.topic_threads kit_render :partial=>"forum/thread_list",:locals=>{:threads=>threads, :options=>} else "" end end |
#kit_forums_recent_posts(count = 5, options = {}) ⇒ Object
152 153 154 155 156 157 158 |
# File 'app/helpers/kit_modules_helper.rb', line 152 def kit_forums_recent_posts(count=5, = {}) mod = can?(:moderate, ForumController) threads = TopicThread.most_recent(current_user, count) kit_render :partial=>"forum/thread_list",:locals=>{:threads => threads, :options => } end |
#kit_forums_recent_threads_from_category_id(category_id, count = 5, options = {}) ⇒ Object
170 171 172 173 174 175 176 177 178 179 |
# File 'app/helpers/kit_modules_helper.rb', line 170 def kit_forums_recent_threads_from_category_id(category_id, count = 5, = {}) category = TopicCategory.sys(_sid).where(["topic_category.read_access_level <= ?", current_user ? current_user.forum_level : 0]).where(:is_open=>1).where(:id=>category_id).first return "" unless category [:show_topic] = false if [:show_topic]==nil threads = category.recent_threads(current_user, count) kit_render :partial=>"forum/thread_list",:locals=>{:threads => threads, :options => } end |
#kit_forums_recent_threads_from_topic_id(topic_id, count = 5, options = {}) ⇒ Object
160 161 162 163 164 165 166 167 168 |
# File 'app/helpers/kit_modules_helper.rb', line 160 def kit_forums_recent_threads_from_topic_id(topic_id, count = 5, = {}) topic = Topic.sys(_sid).where(["topics.read_access_level <= ?", current_user ? current_user.forum_level : 0]).where(:is_visible=>1).where(:id=>topic_id).first return "" unless topic [:show_topic] = false if [:show_topic]==nil threads = topic.recent_threads(current_user, count) kit_render :partial=>"forum/thread_list",:locals=>{:threads => threads, :options => } end |
#kit_forums_threads_im_on(count = 5, options = {}) ⇒ Object
129 130 131 132 133 134 135 136 137 138 |
# File 'app/helpers/kit_modules_helper.rb', line 129 def kit_forums_threads_im_on(count=5, ={}) mod = can?(:moderate, ForumController) if current_user threads = TopicThread.im_on(current_user, count, mod) kit_render :partial=>"forum/thread_list",:locals=>{:threads=>threads, :options=>} else "" end end |
#kit_forums_topics ⇒ Object
181 182 183 184 185 |
# File 'app/helpers/kit_modules_helper.rb', line 181 def kit_forums_topics topics = Topic.sys(_sid).where(["topics.read_access_level <= ?", current_user ? current_user.forum_level : 0]).where(:is_visible=>1).all kit_render :partial=>"forum/topic_list", :locals=>{:topics => topics, :category=>category, :show_headings=>false, :show_mod=>false, :show_meta=>false, :paginate=>false} end |
#kit_forums_topics_from_category_id(category_id) ⇒ Object
188 189 190 191 192 193 194 |
# File 'app/helpers/kit_modules_helper.rb', line 188 def kit_forums_topics_from_category_id(category_id) category = TopicCategory.sys(_sid).where(:id=>category_id).where(["read_access_level <= ?", current_user ? current_user.forum_level : 0]).where(:is_open=>1).first return "" unless category topics = category.topics.where(["topics.read_access_level <= ?", current_user ? current_user.forum_level : 0]).where(:is_visible=>1).all kit_render :partial=>"forum/topic_list", :locals=>{:topics => topics, :category=>category, :show_headings=>false, :show_mod=>false, :show_meta=>false, :paginate=>false} end |
#kit_gallery(id) ⇒ Object
417 418 419 420 |
# File 'app/helpers/kit_modules_helper.rb', line 417 def kit_gallery(id) gallery = Gallery.name_or_id(id).sys(_sid).includes(:assets).first gallery ? render(:partial=>"admin/gallery/view", :locals=>{:gallery=>gallery}) : "[Gallery missing #{id}]" end |
#kit_map(location, title = "", height = 400, width = 400) ⇒ Object
317 318 319 |
# File 'app/helpers/kit_modules_helper.rb', line 317 def kit_map(location, title="", height = 400, width = 400) kit_render :partial=>"utility/map", :locals=>{height: height, width: width, location: location, title:title} end |
#kit_menu(id) ⇒ Object
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 |
# File 'app/helpers/kit_modules_helper.rb', line 208 def (id) html = Rails.cache.fetch(Menu.cache_key(_sid, id)) return html if html if id.is_number? = Menu.sys(_sid).where(:id=>id).first else = Menu.sys(_sid).where(:name=>id).first end html = (kit_render :partial=>"menu/render", :locals=>{:name=>id, :menu=>}).html_safe if && .can_cache==1 Rails.cache.write(Menu.cache_key(_sid, id), html, :expires_in=>60.seconds, :race_condition_ttl=>5.seconds) end return html end |
#kit_page_field(page_id, field_name, is_template = false) ⇒ Object
359 360 361 362 363 364 365 366 367 |
# File 'app/helpers/kit_modules_helper.rb', line 359 def kit_page_field(page_id, field_name, is_template = false) if page_id.is_number? page = Page.find_sys_id(_sid, page_id) else page = Page.sys(_sid).where(:full_path=>page_id).first end page ? field(field_name, is_template) : "[Page missing #{page_id}]" end |
#kit_page_list(options = {}) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'app/helpers/kit_modules_helper.rb', line 7 def kit_page_list(={}) # category, template_snippet, limit = 5, order_by = "updated_at desc") pages = Page.sys(_sid) pages = pages.where("full_path like '#{[:category]}%'") if [:category] pages = pages.where([:where]) if [:where] pages = pages.order([:order_by] || "updated_at desc").limit([:limit] || 5).all if [:template_snippet] template = kit_snippet!(_sid, [:template_snippet]) else template = [:template] template.gsub!("[", "<%").gsub!("]", "%>") end template ||= "No template" render :partial=>"pages/list", locals: { pages:pages, template:template.html_safe } end |
#kit_page_terms(id) ⇒ Object
40 41 42 |
# File 'app/helpers/kit_modules_helper.rb', line 40 def kit_page_terms(id) kit_page_terms_by_ids([id]) end |
#kit_page_terms_by_ids(ids) ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'app/helpers/kit_modules_helper.rb', line 31 def kit_page_terms_by_ids(ids) if @page PageTemplateTerm.where(:page_template_id=>@page.page_template_id).where(:system_id=>_sid).first.terms.where(:page_id=>@page.id).where("terms.page_template_term_id in (#{ids.join(',')})").pluck(:value) else nil end end |
#kit_random_snippet_line(id) ⇒ Object
228 229 230 231 |
# File 'app/helpers/kit_modules_helper.rb', line 228 def kit_random_snippet_line(id) lines = Snippet.parse_lines(id, _sid) return lines ? lines[rand(lines.size)].html_safe : "snippet '#{id}' not found" end |
#kit_rss_feed(rss, opts = {}) ⇒ Object
24 25 26 27 28 29 |
# File 'app/helpers/kit_modules_helper.rb', line 24 def kit_rss_feed(rss, opts = {}) opts[:limit] = 5 opts[:truncate_body] = 80 opts[:html] = "strip" render :partial=>"utility/fetch_rss", :locals=>{:rss=>rss, :options=>opts} end |
#kit_search ⇒ Object
355 356 357 |
# File 'app/helpers/kit_modules_helper.rb', line 355 def kit_search kit_render :partial=>"pages/search_form", :locals=>{dashboard:false} end |
#kit_signin_form(options = {}) ⇒ Object
3 4 5 |
# File 'app/helpers/kit_modules_helper.rb', line 3 def kit_signin_form( = {}) account_sign_in_form() end |
#kit_slideshow(id, options) ⇒ Object
422 423 424 425 426 427 428 |
# File 'app/helpers/kit_modules_helper.rb', line 422 def (id, ) gallery = Gallery.name_or_id(id).sys(_sid).first return "[gallery missing #{id}]" unless gallery assets = gallery.gallery_assets.order(:display_order).page(params[:page]).per([:per_page] || 10) render(:partial=>"admin/gallery/slideshow", :locals=>{:gallery=>gallery, :assets=>assets}) end |
#kit_snippet(id, default = nil, sid = nil) ⇒ Object
334 335 336 337 338 339 340 341 342 343 344 |
# File 'app/helpers/kit_modules_helper.rb', line 334 def kit_snippet(id, default = nil, sid = nil) b = Snippet.cache_get(sid ? sid : _sid, id) return default || "[Snippet missing '#{id}']" unless b if b.has_code==1 return render(:inline=>b.body).html_safe else return b.body.html_safe end end |
#kit_snippet!(sid, id) ⇒ Object
321 322 323 324 325 326 327 328 329 330 331 332 |
# File 'app/helpers/kit_modules_helper.rb', line 321 def kit_snippet!(sid, id) b = Snippet.cache_get(sid, id) return nil unless b if b.has_code==1 return render(:inline=>b.body).html_safe else return b.body.html_safe end end |
#kit_template_block(instance_id, block_id, defaults = {}) ⇒ Object
296 297 298 |
# File 'app/helpers/kit_modules_helper.rb', line 296 def kit_template_block(instance_id, block_id, defaults = {}) kit_editable_block(instance_id, block_id, defaults) end |
#kit_term_child_list(term_id, page_template_id, parent_value) ⇒ Object
requires a block to which this will yield for each child term of the given parent
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'app/helpers/kit_modules_helper.rb', line 76 def kit_term_child_list(term_id, page_template_id, parent_value) # requires a block to which this will yield for each child term of the given parent opts = (term_id, page_template_id) return "term '#{term_id}' not found" unless opts child_opts = nil opts.each do |k,v| if k.urlise==parent_value child_opts = v end end return "parent '#{parent_value}' not found for term '#{term_id}'" unless child_opts op = [] unless block_given? child_opts.each do |v| if block_given? yield v else op << v end end return op unless block_given? end |
#kit_term_options(term_id, page_template_id) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'app/helpers/kit_modules_helper.rb', line 44 def (term_id, page_template_id) pt = PageTemplate.sys(_sid).name_or_id(page_template_id).first term = pt.page_template_terms.name_or_id( term_id).first return "term '#{term_id}' not found" unless term r = {} term.form_field_type..split("|").each do |line| values = line.split('~') r[values[0]] = [] for i in 1..(values.size-1) r[values[0]] << values[i] end end return r end |
#kit_term_parent_list(term_id, page_template_id) ⇒ Object
requires a block to which this will yield for each parent term found, OR returns an array of arrays
61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'app/helpers/kit_modules_helper.rb', line 61 def kit_term_parent_list(term_id, page_template_id) # requires a block to which this will yield for each parent term found, OR returns an array of arrays opts = (term_id, page_template_id) return "term '#{term_id}' not found" unless opts op = [] unless block_given? opts.each do |k,v| if block_given? yield k else op << [ k, v] end end return op unless block_given? end |
#kit_users_email ⇒ Object
351 352 353 |
# File 'app/helpers/kit_modules_helper.rb', line 351 def kit_users_email current_user ? current_user.email : "" end |
#kit_view(id) ⇒ Object
346 347 348 349 |
# File 'app/helpers/kit_modules_helper.rb', line 346 def kit_view(id) view = View.find_sys_id(_sid, id) view ? controller.get_view_content(view).html_safe : "[View missing '#{name}']" end |