Class: Landable::Api::TemplatesController

Inherits:
Landable::ApiController show all
Defined in:
app/controllers/landable/api/templates_controller.rb

Constant Summary

Constants inherited from Landable::ApiController

Landable::ApiController::API_MEDIA_REGEX

Instance Method Summary collapse

Methods inherited from Landable::ApiController

#api_media

Instance Method Details

#createObject

RESTful methods



10
11
12
13
14
15
# File 'app/controllers/landable/api/templates_controller.rb', line 10

def create
  template = Template.new(template_params)
  template.save!

  respond_with template, status: :created, location: template_url(template)
end

#destroyObject



17
18
19
20
21
22
# File 'app/controllers/landable/api/templates_controller.rb', line 17

def destroy
  @template.temp_author = current_author
  @template.try(:deactivate)

  respond_with @template
end

#indexObject



24
25
26
# File 'app/controllers/landable/api/templates_controller.rb', line 24

def index
  respond_with Template.all
end

#previewObject

custom methods



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'app/controllers/landable/api/templates_controller.rb', line 52

def preview
  template = Template.new(template_params)
  theme = Theme.most_used_on_pages

  page = Page.example(theme: theme, body: template.body)

  content = generate_preview_for(page)

  respond_to do |format|
    format.html do
      render text: content, layout: false, content_type: 'text/html'
    end

    format.json do
      render json: { template: { preview: content } }
    end
  end
end

#publishObject

custom methods



39
40
41
42
43
# File 'app/controllers/landable/api/templates_controller.rb', line 39

def publish
  @template.publish! author_id: current_author.id, notes: params[:notes], is_minor: !params[:is_minor].nil?

  respond_with @template
end

#reactivateObject



45
46
47
48
49
# File 'app/controllers/landable/api/templates_controller.rb', line 45

def reactivate
  @template.try(:reactivate)

  respond_with @template
end

#showObject



28
29
30
# File 'app/controllers/landable/api/templates_controller.rb', line 28

def show
  respond_with @template
end

#updateObject



32
33
34
35
36
# File 'app/controllers/landable/api/templates_controller.rb', line 32

def update
  @template.update_attributes!(template_params)

  respond_with @template
end