Sha256: 30edd77133cf4aa1c783ddd058d0030fb3e764695976e7df60262bfb36969a03
Contents?: true
Size: 1.72 KB
Versions: 3
Compression:
Stored size: 1.72 KB
Contents
class RevelryContent::ContentsController < ApplicationController respond_to :html, :json layout 'layouts/revelry_content/application' include RevelryContent::WithRevelryContent include RevelryContent::ControllerAuthorization after_action :export_javascript, only: :create, if: proc { RevelryContent.config.js_export? } def index @all_versions = RevelryContent::ContentVersion.all.order('created_at DESC') respond_with @all_versions end def create @content = RevelryContent::Content.find_or_initialize_by(key: key_param) @content.last_whodunnit = RevelryContent.config.user_for_content.call(self).to_s @content.update(content_params) respond_with @content do |fmt| fmt.html { redirect_to :back } fmt.json { render json: @content } end end def import # Parse file into a hash content_objs = JSON.parse(import_file_param.read) content_objs.each do |key, content_object| RevelryContent::Content.from_import_hash(content_object) end redirect_to :back end def export # i.e. content-2015-01-23-142345.json filename = DateTime.now.strftime('content-%Y-%m-%d-%H%M%S.json') respond_with RevelryContent::Content.all do |fmt| fmt.json do # send the file as a file download (instead of rendering) with a json # mime type send_data RevelryContent::Content.as_serialized_table.to_json, filename: filename end end end protected def content_params params.require(:content).permit(:content, :src) end def key_param params.require(:content).permit(:key).try(:[],:key) end def import_file_param params.require(:import) end def export_javascript RevelryContent::JsExporter.write_export end end
Version data entries
3 entries across 3 versions & 1 rubygems