Giter VIP home page Giter VIP logo

sunrise's Introduction

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

sunrise's People

Contributors

dependabot[bot] avatar galetahub avatar izikaj avatar olleolleolle avatar superp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

sunrise's Issues

License missing from gemspec

RubyGems.org doesn't report a license for your gem. This is because it is not specified in the gemspec of your last release.

via e.g.

spec.license = 'MIT'
# or
spec.licenses = ['MIT', 'GPL-2']

Including a license in your gemspec is an easy way for rubygems.org and other tools to check how your gem is licensed. As you can image, scanning your repository for a LICENSE file or parsing the README, and then attempting to identify the license or licenses is much more difficult and more error prone. So, even for projects that already specify a license, including a license in your gemspec is a good practice. See, for example, how rubygems.org uses the gemspec to display the rails gem license.

There is even a License Finder gem to help companies/individuals ensure all gems they use meet their licensing needs. This tool depends on license information being available in the gemspec. This is an important enough issue that even Bundler now generates gems with a default 'MIT' license.

I hope you'll consider specifying a license in your gemspec. If not, please just close the issue with a nice message. In either case, I'll follow up. Thanks for your time!

Appendix:

If you need help choosing a license (sorry, I haven't checked your readme or looked for a license file), GitHub has created a license picker tool. Code without a license specified defaults to 'All rights reserved'-- denying others all rights to use of the code.
Here's a list of the license names I've found and their frequencies

p.s. In case you're wondering how I found you and why I made this issue, it's because I'm collecting stats on gems (I was originally looking for download data) and decided to collect license metadata,too, and make issues for gemspecs not specifying a license as a public service :). See the previous link or my blog post about this project for more information.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.