GithubHelp home page GithubHelp logo

mrzou / activeadmin-xls Goto Github PK

View Code? Open in Web Editor NEW

This project forked from beansmile/activeadmin-xls

0.0 1.0 0.0 28 KB

ActiveAdmin plugin for adding Excel (xls) download links for your resources

License: MIT License

Ruby 100.00%

activeadmin-xls's Introduction

Active Admin Xls: Excel Spreadsheet Export for Active Admin

Git:http://github.com/thambley/activeadmin-xls

Author: Todd Hambley

Copyright: 2014 ~ 2016

License: MIT License

Latest Version: 1.0.3

Release Date: 2014.09.21

Synopsis

This gem provides xls downloads for Active Admin resources.

This gem borrows heavily from https://github.com/randym/activeadmin-axlsx and https://github.com/splendeo/to_xls.

Usage example:

Add the following to your Gemfile and you are good to go. All resource index views will now include a link for download directly to xls.

gem 'activeadmin-xls'

Cool Toys

Here are a few quick examples of things you can easily tweak.

localize column headers

# app/admin/posts.rb
ActiveAdmin.register Post do
  config.xls_builder.i18n_scope = [:active_record, :models, :posts]
end

Use blocks for adding computed fields

# app/admin/posts.rb
ActiveAdmin.register Post do
  config.xls_builder.column('author_name') do |resource|
    resource.author.name
  end
end

Change the column header format

# app/admin/posts.rb
ActiveAdmin.register Post do
  config.xls_builder.header_format = { :weight => :bold,
                                       :color => :blue }
end

Remove columns

# app/admin/posts.rb
ActiveAdmin.register Post do
  config.xls_builder.delete_columns :id, :created_at, :updated_at
end

Using the DSL

Everything that you do with the config's default builder can be done via the resource DSL.

Below is an example of the DSL

ActiveAdmin.register Post do

  # i18n_scope and header style are set via options
  xlsx(:i18n_scope => [:active_admin, :xls, :post],
       :header_style => {:weight => :bold, :color => :blue }) do

    # Specify that you want to white list column output.
    # whitelist

    # Do not serialize the header, only output data.
    # skip_header

    # deleting columns from the report
    delete_columns :id, :created_at, :updated_at

    # adding a column to the report
    column(:author) { |resource| "#{resource.author.first_name} #{resource.author.last_name}" }

    # creating a chart and inserting additional data with after_filter
    after_filter { |sheet|
      # todo
    }

    # iserting data with before_filter
    before_filter do |sheet|
      # todo
    end
  end
end

Specs


Running specs for this gem requires that you construct a rails application. To execute the specs, navigate to the gem directory, run bundle install and run these to rake tasks:

bundle exec rake setup
bundle exec rake

Copyright and License


activeadmin-xls © 2014 by Todd Hambley.

activeadmin-xls is licensed under the MIT license. Please see the LICENSE document for more information.

activeadmin-xls's People

Contributors

ejaypcanaria avatar jundihuang avatar rainchen avatar rewritten avatar thambley avatar xifengzhu avatar

Watchers

 avatar

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.