Module: CamaleonCms::Frontend::ContentSelectHelper

Included in:
ApplicationHelper
Defined in:
app/helpers/camaleon_cms/frontend/content_select_helper.rb

Instance Method Summary collapse

Instance Method Details

#each_category_of(post_type_slug, options = {}) ⇒ Object

loop through each category of post type each_category_of('post') do the_title end

each_category_of('post', limit: 4) do the_title end



146
147
148
149
150
151
152
153
154
# File 'app/helpers/camaleon_cms/frontend/content_select_helper.rb', line 146

def each_category_of(post_type_slug, options = {})
  the_post_type(post_type_slug) do
    the_categories(options).each do |category|
      process_in_block(category) do
        yield(category) if block_given?
      end
    end
  end
end

#each_post_of(post_type_slug, options = {}) ⇒ Object

loop through each post of post type each_post_of('post') do the_title end

each_post_of('post', limit: 10) do the_title end



128
129
130
131
132
133
134
135
136
# File 'app/helpers/camaleon_cms/frontend/content_select_helper.rb', line 128

def each_post_of(post_type_slug, options = {})
  the_post_type(post_type_slug) do
    the_posts(options).each do |post|
      process_in_block(post) do
        yield(post) if block_given?
      end
    end
  end
end

#process_in_block(object) ⇒ Object

allow object to be global varaible in block work_in_block_of(post) do the_field('extra-content') end



160
161
162
163
164
165
166
# File 'app/helpers/camaleon_cms/frontend/content_select_helper.rb', line 160

def process_in_block(object)
  temp_object = CurrentRequest.frontend_object
  CurrentRequest.frontend_object = object
  yield
ensure
  CurrentRequest.frontend_object = temp_object
end

#the_comments(options = {}) ⇒ Object

select comments of post the_post('blog') the_comments end



55
56
57
# File 'app/helpers/camaleon_cms/frontend/content_select_helper.rb', line 55

def the_comments(options = {})
  camaleon_frontend_object.comments.limit(options[:limit]).decorate if camaleon_frontend_object.present?
end

#the_contentObject

select content of post the_post('blog') do the_content end



71
72
73
74
75
76
77
78
# File 'app/helpers/camaleon_cms/frontend/content_select_helper.rb', line 71

def the_content
  # Security (scan-and-reject policy): no render-time transform. Stored content is gated at
  # save (Post#reject_untrusted_dangerous_content), always equals what its author wrote, and
  # renders verbatim — the same contract as the templates' `raw post.the_content`. The
  # sanitize this once applied used the narrow default allowlist, so it also broke trusted
  # authors' tables and embeds on this DSL path only.
  camaleon_frontend_object.the_content.to_s.html_safe if camaleon_frontend_object.present? # rubocop:disable Rails/OutputSafety
end

#the_excerpt(chars = 200) ⇒ Object

select excerpt of post the_post('blog') do the_excerpt end



108
109
110
# File 'app/helpers/camaleon_cms/frontend/content_select_helper.rb', line 108

def the_excerpt(chars = 200)
  camaleon_frontend_object&.the_excerpt(chars)
end

#the_field(slug) ⇒ Object

select custome field from object the_post('blog') do the_field('extra-content') end



116
117
118
# File 'app/helpers/camaleon_cms/frontend/content_select_helper.rb', line 116

def the_field(slug)
  camaleon_frontend_object&.the_field(slug)
end

#the_post(slug) ⇒ Object

select a single post of post type the_post_type('post') do the_post('first-blog-post') end



17
18
19
20
21
# File 'app/helpers/camaleon_cms/frontend/content_select_helper.rb', line 17

def the_post(slug)
  post = camaleon_frontend_object.the_post(slug)
  process_in_block(post) { yield(post) if block_given? }
  post
end

#the_post_type(slug) ⇒ Object

select post type by just pass slug to parameter Example: the_post_type('post') the_post_type('page')

the_post_type('post') do the_post('first-blog') end



43
44
45
46
47
48
49
# File 'app/helpers/camaleon_cms/frontend/content_select_helper.rb', line 43

def the_post_type(slug)
  post_type = current_site.the_post_type(slug)
  process_in_block(post_type) do
    yield(post_type) if block_given?
  end
  post_type
end

#the_posts(options = {}) ⇒ Object

select posts of post type the_post_type('post') do the_posts end

the_post_type('post') do the_posts(limit: 10) end



31
32
33
# File 'app/helpers/camaleon_cms/frontend/content_select_helper.rb', line 31

def the_posts(options = {})
  camaleon_frontend_object.posts.visible_frontend.limit(options[:limit]).decorate
end

#the_slugObject

select slug of post, post type ... the_post('blog') do the_slug end



100
101
102
# File 'app/helpers/camaleon_cms/frontend/content_select_helper.rb', line 100

def the_slug
  camaleon_frontend_object&.the_slug
end

#the_thumbnailObject

select thumbnail of post the_post('blog') do the_thumbnail end



92
93
94
# File 'app/helpers/camaleon_cms/frontend/content_select_helper.rb', line 92

def the_thumbnail
  camaleon_frontend_object&.the_thumb_url
end

#the_titleObject

select title of post the_post('blog') do the_title end



63
64
65
# File 'app/helpers/camaleon_cms/frontend/content_select_helper.rb', line 63

def the_title
  camaleon_frontend_object&.the_title
end

#the_urlObject

select url of post the_post('blog') do the_url end



84
85
86
# File 'app/helpers/camaleon_cms/frontend/content_select_helper.rb', line 84

def the_url
  camaleon_frontend_object&.the_url
end