Class: ActsAsCalculator::TemplatesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/acts_as_calculator/templates_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



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

#destroyObject



19
20
21
22
23
# File 'app/controllers/acts_as_calculator/templates_controller.rb', line 19

def destroy
  template.destroy!

  head :no_content
end

#indexObject



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

#previewObject

{ 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

#promoteObject

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

#showObject



9
10
11
# File 'app/controllers/acts_as_calculator/templates_controller.rb', line 9

def show
  render json: { template: SerializeTemplate.(template:) }
end