Class: Landable::Api::ThemesController

Inherits:
Landable::ApiController show all
Defined in:
app/controllers/landable/api/themes_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/themes_controller.rb', line 10

def create
  theme = Theme.new(theme_params)
  theme.save!

  respond_with theme, status: :created, location: theme_url(theme)
end

#destroyObject



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

def destroy
  @theme.try(:deactivate)

  respond_with @theme
end

#indexObject



23
24
25
# File 'app/controllers/landable/api/themes_controller.rb', line 23

def index
  respond_with Theme.all
end

#previewObject

custom methods



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'app/controllers/landable/api/themes_controller.rb', line 44

def preview
  theme = Theme.new(theme_params)
  page  = Page.example(theme: theme)

  params[:theme][:asset_ids].try(:each) do |asset_id|
    theme.attachments.add Asset.find(asset_id)
  end

  content = render_to_string(
    text: RenderService.call(page),
    layout: page.theme.file || false
  )

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

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

#reactivateObject



27
28
29
30
31
# File 'app/controllers/landable/api/themes_controller.rb', line 27

def reactivate
  @theme.try(:reactivate)

  respond_with @theme
end

#showObject



33
34
35
# File 'app/controllers/landable/api/themes_controller.rb', line 33

def show
  respond_with @theme
end

#updateObject



37
38
39
40
41
# File 'app/controllers/landable/api/themes_controller.rb', line 37

def update
  @theme.update_attributes!(theme_params)

  respond_with @theme
end