Class: Tiler::UserWidgetsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- Tiler::UserWidgetsController
- Defined in:
- app/controllers/tiler/user_widgets_controller.rb
Overview
CRUD for runtime user-defined (Liquid) widgets. Lives under /settings/user_widgets so it’s discoverable from the Settings page.
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
-
#preview ⇒ Object
POST /settings/user_widgets/preview Body: { template, sample_data } — returns the rendered HTML so the form can show a live preview without saving.
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'app/controllers/tiler/user_widgets_controller.rb', line 17 def create @user_widget = UserWidget.new() if @user_widget.save redirect_to , notice: "Custom widget '#{@user_widget.slug}' created." else render :new, status: :unprocessable_entity end end |
#destroy ⇒ Object
36 37 38 39 40 |
# File 'app/controllers/tiler/user_widgets_controller.rb', line 36 def destroy slug = @user_widget.slug @user_widget.destroy! redirect_to , notice: "Custom widget '#{slug}' deleted." end |
#edit ⇒ Object
26 |
# File 'app/controllers/tiler/user_widgets_controller.rb', line 26 def edit; end |
#index ⇒ Object
8 9 10 |
# File 'app/controllers/tiler/user_widgets_controller.rb', line 8 def index @user_widgets = UserWidget.order(:slug) end |
#new ⇒ Object
12 13 14 15 |
# File 'app/controllers/tiler/user_widgets_controller.rb', line 12 def new @user_widget = UserWidget.new(default_w: 4, default_h: 3, template: default_template_seed) end |
#preview ⇒ Object
POST /settings/user_widgets/preview Body: { template, sample_data } — returns the rendered HTML so the form can show a live preview without saving.
45 46 47 48 49 50 51 52 |
# File 'app/controllers/tiler/user_widgets_controller.rb', line 45 def preview template = params[:template].to_s.first(UserWidget::TEMPLATE_MAX) sample = JSON.parse(params[:sample_data].to_s.presence || "{}") rescue {} tpl = ::Liquid::Template.parse(template, error_mode: :strict) render plain: tpl.render!("data" => sample, "panel" => { "title" => "Preview" }, "config" => {}) rescue ::Liquid::Error => e render plain: "Liquid error: #{e.}", status: :unprocessable_entity end |
#update ⇒ Object
28 29 30 31 32 33 34 |
# File 'app/controllers/tiler/user_widgets_controller.rb', line 28 def update if @user_widget.update() redirect_to , notice: "Custom widget '#{@user_widget.slug}' updated." else render :edit, status: :unprocessable_entity end end |