Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sunrise-cms

Package Overview
Dependencies
Maintainers
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sunrise-cms

  • 1.1.1
  • Rubygems
  • Socket score

Version published
Maintainers
2
Created
Source

Sunrise CMS

Open source mini content management system for programmers.

Setup

For rails 5.x.x:

  gem 'sunrise-cms', '~> 1.1.0', require: 'sunrise'

For rails 4.x.x:

  gem "sunrise-cms", :require => "sunrise"

For rails 3.x.x:

  gem "sunrise-cms", "~> 0.7.x" :require => "sunrise"

Instructions

ActiveRecord

$> rails g devise:install
$> rails g sunrise:install --orm=active_record

Copy db migrations files:

$> rake sunrise:install:migrations
$> rake page_parts_engine:install:migrations
$> rake meta_manager_engine:install:migrations
$> rails g public_activity:migration

Mongoid

$> rails g sunrise:install --orm=mongoid

Usage

Just create class:

class SunriseProduct < Sunrise::AbstractModel
  self.resource_name = "Product"

  association :structure

  after_sort :clear_cache
  
  index :thumbs do
    scope { Product.includes(:picture) }
    preview lambda { |product| product.picture.try(:url, :thumb) }

    field :title
    field :price
    field :total_stock
  end

  export do
    scope { Product.includes(:picture).recently.with_state(:finished) }

    field :id
    field :product_title
    field :size
    field :started_at
    field :finished_at
    field :unique_accounts_count
    field :total_points
  end
  
  show do
    field :title
    field :price
    field :total_stock
    field :sort_order
    field :is_visible
  end
  
  form do
    field :title
    field :price
    field :total_stock
    
    field do |form, record|
      form.input :notes, :as => :text, :id => record.id
    end

    group :sidebar, :holder => :sidebar do
      field :sale_limit_id, :collection => lambda { SaleLimit.all }, :include_blank => false
      field :sort_order
      field :is_visible, :boolean => true
    end

    group :bottom, :holder => :bottom do
      nested_attributes :variants, :multiply => true do
        field :size
        field :total_stock, :html => { :style => 'width:100%;clear:both;' }
        field :item_model_id, :collection => lambda { ItemModel.all }, :include_blank => false
      end

      nested_attributes :project_fields, multiply: true, sort: true do
        field :name
        field :value
      end
    
      field :picture, :as => :uploader
    end
  end

  protected

    def clear_cache
      Rails.cache.clear
    end
end

Assets uploading detect ccurrent user by request.env['warden'].user. To overwrite it use:

class Asset
  def uploader_user(request)
    request.env['warden'].user(:account) || request.env['warden'].user(:user)
  end
end

Export data

XML, JSON, CSV
  GET /manage/users/export.xml
  GET /manage/users/export.csv
JSON
  GET /manage/users/export.json

For more info look at jbuilder https://rubygems.org/gems/jbuilder.

Excel
  gem "ruby2xlsx", "~> 0.0.1"

  GET /manage/users/export.xlsx

Strong parameters

Now in sunrise file you can perform attributes check. By default permited_attributes allow edit all attributes.

class SunrisePost < Sunrise::AbstractModel
  self.resource_name = "Post"
  edit do
    # Default value
    # permited_attributes :all 

    # Pre user check
    permited_attributes lambda { |user| 
      user.admin? ? :all : [:title, :content] 
    }
  end
end

Include additional js codes

For example your want to include ckeditor editor. In "Gemfile" include gem:

gem "ckeditor"

Create file "app/assets/javascripts/sunrise/plugins.js":

//= require ckeditor/init

Layout for devise login page

# config/application.rb
config.to_prepare do
  Devise::SessionsController.layout "sunrise/devise"
  Devise::PasswordsController.layout "sunrise/devise"
  Devise::ConfirmationsController.layout "sunrise/devise"
end

Copyright (c) 2014 Fodojo, released under the MIT license

FAQs

Package last updated on 13 Apr 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc