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_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
101 102 103 104 105 106 107 108 |
# File 'app/helpers/kit_modules_helper.rb', line 101 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
96 97 98 99 |
# File 'app/helpers/kit_modules_helper.rb', line 96 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
115 116 117 118 119 120 121 122 |
# File 'app/helpers/kit_modules_helper.rb', line 115 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
110 111 112 113 |
# File 'app/helpers/kit_modules_helper.rb', line 110 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
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 |
# File 'app/helpers/kit_modules_helper.rb', line 274 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
264 265 266 267 268 269 270 271 272 |
# File 'app/helpers/kit_modules_helper.rb', line 264 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
200 201 202 |
# File 'app/helpers/kit_modules_helper.rb', line 200 def kit_calendar(calendar_id, = {}) module_kit_calendar(calendar_id, ) end |
#kit_calendar_entry(id, options = {}) ⇒ Object
196 197 198 |
# File 'app/helpers/kit_modules_helper.rb', line 196 def kit_calendar_entry(id, = {}) module_kit_calendar_entry(id, ) end |
#kit_calendar_entry_add(calendar_id, options = {}) ⇒ Object
192 193 194 |
# File 'app/helpers/kit_modules_helper.rb', line 192 def kit_calendar_entry_add(calendar_id, = {}) module_kit_calendar_entry_add(calendar_id, ) end |
#kit_code(name) ⇒ Object
365 366 367 |
# File 'app/helpers/kit_modules_helper.rb', line 365 def kit_code(name) eval(name) end |
#kit_current_month(format = '%b') ⇒ Object
260 261 262 |
# File 'app/helpers/kit_modules_helper.rb', line 260 def kit_current_month(format = '%b') Time.now.strftime(format) end |
#kit_current_year ⇒ Object
256 257 258 |
# File 'app/helpers/kit_modules_helper.rb', line 256 def kit_current_year Time.now.strftime("%Y") end |
#kit_dated_snippet_line(id) ⇒ Object
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 |
# File 'app/helpers/kit_modules_helper.rb', line 229 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
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 |
# File 'app/helpers/kit_modules_helper.rb', line 296 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
369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 |
# File 'app/helpers/kit_modules_helper.rb', line 369 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
393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 |
# File 'app/helpers/kit_modules_helper.rb', line 393 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’
136 137 138 139 140 141 142 143 144 145 146 |
# File 'app/helpers/kit_modules_helper.rb', line 136 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
148 149 150 151 152 153 154 |
# File 'app/helpers/kit_modules_helper.rb', line 148 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
166 167 168 169 170 171 172 173 174 175 |
# File 'app/helpers/kit_modules_helper.rb', line 166 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
156 157 158 159 160 161 162 163 164 |
# File 'app/helpers/kit_modules_helper.rb', line 156 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
125 126 127 128 129 130 131 132 133 134 |
# File 'app/helpers/kit_modules_helper.rb', line 125 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
177 178 179 180 181 |
# File 'app/helpers/kit_modules_helper.rb', line 177 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
184 185 186 187 188 189 190 |
# File 'app/helpers/kit_modules_helper.rb', line 184 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
413 414 415 416 |
# File 'app/helpers/kit_modules_helper.rb', line 413 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
313 314 315 |
# File 'app/helpers/kit_modules_helper.rb', line 313 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
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 |
# File 'app/helpers/kit_modules_helper.rb', line 204 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
355 356 357 358 359 360 361 362 363 |
# File 'app/helpers/kit_modules_helper.rb', line 355 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
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'app/helpers/kit_modules_helper.rb', line 3 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
36 37 38 |
# File 'app/helpers/kit_modules_helper.rb', line 36 def kit_page_terms(id) kit_page_terms_by_ids([id]) end |
#kit_page_terms_by_ids(ids) ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'app/helpers/kit_modules_helper.rb', line 27 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
224 225 226 227 |
# File 'app/helpers/kit_modules_helper.rb', line 224 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
20 21 22 23 24 25 |
# File 'app/helpers/kit_modules_helper.rb', line 20 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
351 352 353 |
# File 'app/helpers/kit_modules_helper.rb', line 351 def kit_search kit_render :partial=>"pages/search_form", :locals=>{dashboard:false} end |
#kit_slideshow(id, options) ⇒ Object
418 419 420 421 422 423 424 |
# File 'app/helpers/kit_modules_helper.rb', line 418 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
330 331 332 333 334 335 336 337 338 339 340 |
# File 'app/helpers/kit_modules_helper.rb', line 330 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
317 318 319 320 321 322 323 324 325 326 327 328 |
# File 'app/helpers/kit_modules_helper.rb', line 317 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
292 293 294 |
# File 'app/helpers/kit_modules_helper.rb', line 292 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
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'app/helpers/kit_modules_helper.rb', line 72 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
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'app/helpers/kit_modules_helper.rb', line 40 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
57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'app/helpers/kit_modules_helper.rb', line 57 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
347 348 349 |
# File 'app/helpers/kit_modules_helper.rb', line 347 def kit_users_email current_user ? current_user.email : "" end |
#kit_view(id) ⇒ Object
342 343 344 345 |
# File 'app/helpers/kit_modules_helper.rb', line 342 def kit_view(id) view = View.find_sys_id(_sid, id) view ? controller.get_view_content(view).html_safe : "[View missing '#{name}']" end |