Class: ActsAsCalculator::TemplatesController
- Inherits:
-
ApplicationController
- Object
- ActionController::API
- ApplicationController
- ActsAsCalculator::TemplatesController
- Defined in:
- app/controllers/acts_as_calculator/templates_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #index ⇒ Object
-
#preview ⇒ Object
{ body:, format: }, neverhtml_safe— whether API-authored markup is safe to inject into a page is the host's call, not this gem's (Phase 3). -
#promote ⇒ Object
Rollback: point
currentat an older version instead of deleting the one that went wrong, which is the whole reason the version history exists. - #show ⇒ Object
Instance Method Details
#create ⇒ Object
13 14 15 16 17 |
# File 'app/controllers/acts_as_calculator/templates_controller.rb', line 13 def create published = PublishTemplate.(**template_attributes) render json: { template: SerializeTemplate.(template: published) }, status: :created end |
#destroy ⇒ Object
19 20 21 22 23 |
# File 'app/controllers/acts_as_calculator/templates_controller.rb', line 19 def destroy template.destroy! head :no_content end |
#index ⇒ Object
5 6 7 |
# File 'app/controllers/acts_as_calculator/templates_controller.rb', line 5 def index render json: { templates: scoped_templates.map { |template| SerializeTemplate.(template:) } } end |
#preview ⇒ Object
{ body:, format: }, never html_safe — whether API-authored markup is safe to
inject into a page is the host's call, not this gem's (Phase 3).
27 28 29 30 31 |
# File 'app/controllers/acts_as_calculator/templates_controller.rb', line 27 def preview body = RenderTemplate.(template:, context: plain_hash(params[:context])) render json: { preview: { body:, format: template.format } } end |
#promote ⇒ Object
Rollback: point current at an older version instead of deleting the one that went
wrong, which is the whole reason the version history exists.
35 36 37 |
# File 'app/controllers/acts_as_calculator/templates_controller.rb', line 35 def promote render json: { template: SerializeTemplate.(template: PromoteTemplate.(template:)) } end |
#show ⇒ Object
9 10 11 |
# File 'app/controllers/acts_as_calculator/templates_controller.rb', line 9 def show render json: { template: SerializeTemplate.(template:) } end |