Module: RailsOnboarding::TemplatesHelper
- Defined in:
- app/helpers/rails_onboarding/templates_helper.rb
Overview
Helper methods for working with onboarding templates
Instance Method Summary collapse
-
#apply_template(template_key) ⇒ Boolean
Apply a template to configuration.
-
#available_templates ⇒ Hash
Get all available templates.
-
#compare_templates(*template_keys) ⇒ Hash
Compare templates.
-
#detect_current_template ⇒ Symbol?
Detect which template matches current configuration.
-
#estimate_template_time(template) ⇒ String
Estimate completion time for a template.
-
#get_template(template_key) ⇒ Hash?
Get a specific template.
-
#recommended_template(context = {}) ⇒ Symbol?
Get recommended template based on context.
-
#render_template_comparison(*template_keys) ⇒ String
Render template comparison table.
-
#template_categories(template) ⇒ Array<Symbol>
Get categories/tags for a template.
-
#template_difficulty(template) ⇒ Symbol
Determine template difficulty.
-
#template_metadata(template_key) ⇒ Hash
Get template metadata.
-
#template_option(key, template, selected = false) ⇒ String
Render a single template option.
-
#template_selector(options = {}) ⇒ String
Render template selection UI.
Instance Method Details
#apply_template(template_key) ⇒ Boolean
Apply a template to configuration
25 26 27 |
# File 'app/helpers/rails_onboarding/templates_helper.rb', line 25 def apply_template(template_key) RailsOnboarding.configuration.apply_template(template_key) end |
#available_templates ⇒ Hash
Get all available templates
9 10 11 |
# File 'app/helpers/rails_onboarding/templates_helper.rb', line 9 def available_templates RailsOnboarding.configuration.onboarding_templates || {} end |
#compare_templates(*template_keys) ⇒ Hash
Compare templates
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'app/helpers/rails_onboarding/templates_helper.rb', line 124 def compare_templates(*template_keys) comparison = {} template_keys.each do |key| template = get_template(key) next unless template comparison[key] = { name: template[:name], total_steps: template[:steps]&.size || 0, required_steps: template[:steps]&.count { |s| !s[:skippable] } || 0, optional_steps: template[:steps]&.count { |s| s[:skippable] } || 0, steps: template[:steps] } end comparison end |
#detect_current_template ⇒ Symbol?
Detect which template matches current configuration
111 112 113 114 115 116 117 118 |
# File 'app/helpers/rails_onboarding/templates_helper.rb', line 111 def detect_current_template current_steps = RailsOnboarding.configuration.steps return nil if current_steps.empty? available_templates.find do |key, template| template[:steps] == current_steps end&.first end |
#estimate_template_time(template) ⇒ String
Estimate completion time for a template
210 211 212 213 214 215 216 |
# File 'app/helpers/rails_onboarding/templates_helper.rb', line 210 def estimate_template_time(template) steps_count = template[:steps]&.size || 0 min_time = steps_count * 1 # 1 minute per step minimum max_time = steps_count * 3 # 3 minutes per step maximum "#{min_time}-#{max_time} minutes" end |
#get_template(template_key) ⇒ Hash?
Get a specific template
17 18 19 |
# File 'app/helpers/rails_onboarding/templates_helper.rb', line 17 def get_template(template_key) RailsOnboarding.configuration.template(template_key) end |
#recommended_template(context = {}) ⇒ Symbol?
Get recommended template based on context
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 |
# File 'app/helpers/rails_onboarding/templates_helper.rb', line 37 def recommended_template(context = {}) templates = available_templates # Recommend based on industry if provided if context[:industry] return context[:industry].to_sym if templates[context[:industry].to_sym] end # Recommend based on user type if context[:user_type] case context[:user_type].to_sym when :student, :learner return :education if templates[:education] when :seller, :merchant return :marketplace if templates[:marketplace] when :business, :company return :saas if templates[:saas] end end # Recommend based on team size if context[:team_size] if context[:team_size] > 10 return :saas if templates[:saas] elsif context[:team_size] == 1 return :community if templates[:community] end end # Default to first available template templates.keys.first end |
#render_template_comparison(*template_keys) ⇒ String
Render template comparison table
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 |
# File 'app/helpers/rails_onboarding/templates_helper.rb', line 147 def render_template_comparison(*template_keys) comparison = compare_templates(*template_keys) return "" if comparison.empty? content_tag :table, class: "template-comparison" do concat(content_tag(:thead) do content_tag(:tr) do concat(content_tag(:th, "Feature")) comparison.each_key do |key| concat(content_tag(:th, comparison[key][:name])) end end end) concat(content_tag(:tbody) do # Total steps row concat(content_tag(:tr) do concat(content_tag(:td, "Total Steps")) comparison.each_value do |data| concat(content_tag(:td, data[:total_steps])) end end) # Required steps row concat(content_tag(:tr) do concat(content_tag(:td, "Required Steps")) comparison.each_value do |data| concat(content_tag(:td, data[:required_steps])) end end) # Optional steps row concat(content_tag(:tr) do concat(content_tag(:td, "Optional Steps")) comparison.each_value do |data| concat(content_tag(:td, data[:optional_steps])) end end) end) end end |
#template_categories(template) ⇒ Array<Symbol>
Get categories/tags for a template
239 240 241 242 243 244 245 246 247 248 249 250 251 |
# File 'app/helpers/rails_onboarding/templates_helper.rb', line 239 def template_categories(template) categories = [] step_names = template[:steps]&.map { |s| s[:name].to_s } || [] categories << :profile if step_names.any? { |n| n.include?("profile") } categories << :team if step_names.any? { |n| n.include?("team") || n.include?("invite") } categories << :payment if step_names.any? { |n| n.include?("payment") || n.include?("billing") } categories << :content if step_names.any? { |n| n.include?("post") || n.include?("product") } categories << :social if step_names.any? { |n| n.include?("connect") || n.include?("friends") } categories end |
#template_difficulty(template) ⇒ Symbol
Determine template difficulty
222 223 224 225 226 227 228 229 230 231 232 233 |
# File 'app/helpers/rails_onboarding/templates_helper.rb', line 222 def template_difficulty(template) total_steps = template[:steps]&.size || 0 required_steps = template[:steps]&.count { |s| !s[:skippable] } || 0 if total_steps <= 3 && required_steps <= 2 :easy elsif total_steps <= 5 && required_steps <= 3 :medium else :hard end end |
#template_metadata(template_key) ⇒ Hash
Get template metadata
193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'app/helpers/rails_onboarding/templates_helper.rb', line 193 def (template_key) template = get_template(template_key) return {} unless template { name: template[:name], total_steps: template[:steps]&.size || 0, estimated_time: estimate_template_time(template), difficulty: template_difficulty(template), categories: template_categories(template) } end |
#template_option(key, template, selected = false) ⇒ String
Render a single template option
95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'app/helpers/rails_onboarding/templates_helper.rb', line 95 def template_option(key, template, selected = false) content_tag :div, class: "template-option #{selected ? 'selected' : ''}", data: { template: key } do concat(content_tag(:div, class: "template-icon") do template[:icon] || "📋" end) concat(content_tag(:div, class: "template-info") do concat(content_tag(:h4, template[:name])) concat(content_tag(:p, template[:description] || "#{key.to_s.titleize} onboarding")) concat(content_tag(:span, "#{template[:steps]&.size || 0} steps", class: "step-count")) end) end end |
#template_selector(options = {}) ⇒ String
Render template selection UI
74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'app/helpers/rails_onboarding/templates_helper.rb', line 74 def template_selector( = {}) templates = available_templates current_template = [:current] || detect_current_template content_tag :div, class: "template-selector" do concat(content_tag(:h3, [:title] || "Choose a Template")) concat(content_tag(:div, class: "template-options") do templates.each do |key, template| concat(template_option(key, template, key == current_template)) end end) end end |