ruby2xlsx 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.rdoc +99 -0
  3. data/Rakefile +37 -0
  4. data/lib/ruby2xlsx/base.rb +46 -0
  5. data/lib/ruby2xlsx/default.rb +13 -0
  6. data/lib/ruby2xlsx/document.rb +66 -0
  7. data/lib/ruby2xlsx/engine.rb +17 -0
  8. data/lib/ruby2xlsx/template.rb +25 -0
  9. data/lib/ruby2xlsx/version.rb +3 -0
  10. data/lib/ruby2xlsx/xrb.rb +14 -0
  11. data/lib/ruby2xlsx.rb +9 -0
  12. data/lib/tasks/ruby2xlsx_tasks.rake +4 -0
  13. data/test/dummy/Rakefile +7 -0
  14. data/test/dummy/app/assets/javascripts/application.js +9 -0
  15. data/test/dummy/app/assets/javascripts/articles.js +2 -0
  16. data/test/dummy/app/assets/stylesheets/application.css +7 -0
  17. data/test/dummy/app/assets/stylesheets/articles.css +4 -0
  18. data/test/dummy/app/assets/stylesheets/scaffold.css +56 -0
  19. data/test/dummy/app/controllers/application_controller.rb +4 -0
  20. data/test/dummy/app/controllers/articles_controller.rb +100 -0
  21. data/test/dummy/app/helpers/application_helper.rb +2 -0
  22. data/test/dummy/app/helpers/articles_helper.rb +2 -0
  23. data/test/dummy/app/models/article.rb +3 -0
  24. data/test/dummy/app/views/articles/_form.html.erb +20 -0
  25. data/test/dummy/app/views/articles/another.xlsx.xrb +55 -0
  26. data/test/dummy/app/views/articles/edit.html.erb +6 -0
  27. data/test/dummy/app/views/articles/index.html.erb +26 -0
  28. data/test/dummy/app/views/articles/new.html.erb +5 -0
  29. data/test/dummy/app/views/articles/show.html.erb +5 -0
  30. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  31. data/test/dummy/config/application.rb +45 -0
  32. data/test/dummy/config/boot.rb +10 -0
  33. data/test/dummy/config/database.yml +25 -0
  34. data/test/dummy/config/environment.rb +5 -0
  35. data/test/dummy/config/environments/development.rb +30 -0
  36. data/test/dummy/config/environments/production.rb +60 -0
  37. data/test/dummy/config/environments/test.rb +39 -0
  38. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  39. data/test/dummy/config/initializers/inflections.rb +10 -0
  40. data/test/dummy/config/initializers/mime_types.rb +5 -0
  41. data/test/dummy/config/initializers/secret_token.rb +7 -0
  42. data/test/dummy/config/initializers/session_store.rb +8 -0
  43. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  44. data/test/dummy/config/locales/en.yml +5 -0
  45. data/test/dummy/config/routes.rb +6 -0
  46. data/test/dummy/config.ru +4 -0
  47. data/test/dummy/db/migrate/20120116125427_create_articles.rb +9 -0
  48. data/test/dummy/db/test.sqlite3 +0 -0
  49. data/test/dummy/public/404.html +26 -0
  50. data/test/dummy/public/422.html +26 -0
  51. data/test/dummy/public/500.html +26 -0
  52. data/test/dummy/public/favicon.ico +0 -0
  53. data/test/dummy/script/rails +6 -0
  54. data/test/integration/navigation_test.rb +46 -0
  55. data/test/ruby2xlsx_test.rb +12 -0
  56. data/test/support/integration_case.rb +7 -0
  57. data/test/test_helper.rb +15 -0
  58. metadata +192 -0
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2012 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,99 @@
1
+ = Ruby2xlsx
2
+
3
+ Export your data to Excel. Provide two ways for export data: template or renderer.
4
+
5
+ == Install
6
+
7
+ This is very simple (Rails 3 only):
8
+
9
+ gem "ruby2xlsx"
10
+
11
+ == Usage
12
+
13
+ You can use two types: template and renderer.
14
+
15
+ === Renderer
16
+
17
+ def index
18
+ @articles = Article.order('id DESC')
19
+
20
+ respond_to do |format|
21
+ format.html # index.html.erb
22
+ format.xlsx { render xlsx: @articles }
23
+ end
24
+ end
25
+
26
+ With options:
27
+
28
+ format.xlsx { render xlsx: @articles,
29
+ :columns => [:id, :title, :updated_at],
30
+ :filename => ["articles_", Time.now.to_s, ".xlsx"].join,
31
+ :worksheet_name => "My articles" }
32
+
33
+ === Template
34
+
35
+ In controller (app/controllers/articles_controller.rb):
36
+
37
+ class ArticlesController < ApplicationController
38
+ respond_to :xlsx, :only => [:index]
39
+
40
+ def index
41
+ @articles = Article.order('id DESC')
42
+ respond_with(@articles)
43
+ end
44
+ end
45
+
46
+ In view (app/views/articles/index.xlsx.xrb):
47
+
48
+ add_worksheet "Data"
49
+
50
+ bold = add_format(:bold => 1)
51
+ headings = [ 'Title', 'Views', 'Comments' ]
52
+
53
+ write('A1', headings, bold)
54
+
55
+ @articles.each_with_index do |article, index|
56
+ row = index + 1
57
+ write(row, 0, article.title)
58
+ write(row, 1, article.views_count)
59
+ write(row, 2, article.comments_count)
60
+ end
61
+
62
+ chart4 = add_chart(:name => 'Results Chart', :type => 'Chart::Area')
63
+
64
+ # Configure the series.
65
+ chart4.add_series(
66
+ :categories => '=Sheet1!$A$2:$A$7',
67
+ :values => '=Sheet1!$B$2:$B$7',
68
+ :name => 'Test data series 1'
69
+ )
70
+
71
+ # Add another series.
72
+ chart4.add_series(
73
+ :categories => '=Sheet1!$A$2:$A$7',
74
+ :values => '=Sheet1!$C$2:$C$7',
75
+ :name => 'Test data series 2'
76
+ )
77
+
78
+ # Add some labels.
79
+ chart4.set_title( :name => 'Results of sample analysis' )
80
+ chart4.set_x_axis( :name => 'Sample number' )
81
+ chart4.set_y_axis( :name => 'Sample length' )
82
+
83
+ == Dependencies
84
+
85
+ 1. https://github.com/cxn03651/writeexcel
86
+ 2. https://rubygems.org/gems/activemodel
87
+
88
+ == Other similar gems
89
+
90
+ 1. https://github.com/arydjmal/to_xls
91
+ 2. https://github.com/xinuc/ekuseru
92
+ 3. https://github.com/harvesthq/simple_xlsx_writer
93
+ 4. https://github.com/stevo/excellent
94
+ 5. https://github.com/asanghi/excel_rails
95
+ 6. https://github.com/rdavila/active_record_to_excel
96
+ 7. https://github.com/liangwenke/to_xls-rails
97
+
98
+
99
+ This project rocks and uses MIT-LICENSE.
data/Rakefile ADDED
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'Ruby2xlsx'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+
24
+
25
+ Bundler::GemHelper.install_tasks
26
+
27
+ require 'rake/testtask'
28
+
29
+ Rake::TestTask.new(:test) do |t|
30
+ t.libs << 'lib'
31
+ t.libs << 'test'
32
+ t.pattern = 'test/**/*_test.rb'
33
+ t.verbose = false
34
+ end
35
+
36
+
37
+ task :default => :test
@@ -0,0 +1,46 @@
1
+ require 'writeexcel'
2
+ require 'stringio'
3
+
4
+ module Ruby2xlsx
5
+ class Base
6
+ # Constructs a new ejs engine based on given xlsx", :root => true, :view_path => "/path/to/views" })
7
+ #
8
+ def initialize(source, options = {})
9
+ @source = source
10
+ @options = options
11
+ @compiled = false
12
+ @io = ::StringIO.new
13
+ end
14
+
15
+ def workbook
16
+ @workbook ||= ::WriteExcel.new(@io)
17
+ end
18
+
19
+ def worksheet
20
+ @worksheet ||= add_worksheet(worksheet_name)
21
+ end
22
+
23
+ def add_worksheet(*args)
24
+ @worksheet = workbook.add_worksheet(*args)
25
+ end
26
+
27
+ def render(*args)
28
+ workbook.close
29
+ @io.string
30
+ end
31
+
32
+ def worksheet_name
33
+ "somename"
34
+ end
35
+
36
+ def method_missing(m, *args, &block)
37
+ if worksheet.respond_to?(m)
38
+ worksheet.send(m, *args, &block)
39
+ elsif workbook.respond_to?(m)
40
+ workbook.send(m, *args, &block)
41
+ else
42
+ super
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,13 @@
1
+ require 'active_model/naming'
2
+ require 'active_model/translation'
3
+
4
+ module Ruby2xlsx
5
+ class Default
6
+ extend ActiveModel::Naming
7
+ extend ActiveModel::Translation
8
+
9
+ def self.column_names
10
+ [:id]
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,66 @@
1
+ module Ruby2xlsx
2
+ class Document < Base
3
+ def render
4
+ date_format = workbook.add_format(:num_format => 'dd.mm.yyyy')
5
+ time_format = workbook.add_format(:num_format => 'dd.mm.yyyy HH:MM')
6
+
7
+ each_with_index do |record, index|
8
+ row = index + 1
9
+
10
+ columns_names.each_with_index do |column, num|
11
+ value = record.send(column)
12
+
13
+ if value.is_a?(Date)
14
+ worksheet.write_string(row, num, value.strftime("%Y-%m-%dT"), date_format)
15
+ elsif value.is_a?(DateTime) || value.is_a?(Time)
16
+ worksheet.write_date_time(row, num, value.strftime("%Y-%m-%dT%H:%M:%S.%L"), time_format)
17
+ else
18
+ worksheet.write(row, num, value)
19
+ end
20
+ end
21
+ end
22
+
23
+ bold = workbook.add_format(:bold => 1)
24
+ worksheet.write('A1', human_columns_names, bold)
25
+
26
+ super
27
+ end
28
+
29
+ def columns_names
30
+ @columns_names ||= (@options[:columns] || @klass.column_names)
31
+ end
32
+
33
+ def human_columns_names
34
+ @human_columns_names ||= columns_names.map { |column| @klass.human_attribute_name(column.to_s) }
35
+ end
36
+
37
+ def worksheet_name
38
+ @worksheet_name ||= (@options[:worksheet_name] || @klass.model_name.human)
39
+ end
40
+
41
+ def filename
42
+ @filename ||= [(@options[:filename] || @klass.model_name.plural || "document"), ".xlsx"].join
43
+ end
44
+
45
+ def each_with_index
46
+ count = 0
47
+ if @source.is_a?(::ActiveRecord::Relation)
48
+ @klass ||= @source.klass
49
+
50
+ @source.find_each do |item|
51
+ yield item, count
52
+ count += 1
53
+ end
54
+ else
55
+ items = Array.wrap(@source)
56
+ @klass ||= items.first.class unless items.empty?
57
+ @klass ||= Default
58
+
59
+ items.each do |item|
60
+ yield item, count
61
+ count += 1
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,17 @@
1
+ require 'rails'
2
+ require 'ruby2xlsx'
3
+
4
+ module Ruby2xlsx
5
+ class Engine < ::Rails::Engine
6
+ initializer "ruby2xlsx.setup" do
7
+ ::Mime::Type.register "application/vnd.ms-excel", :xlsx
8
+
9
+ ::ActionView::Template.register_template_handler :xrb, Ruby2xlsx::Xrb.new
10
+
11
+ ::ActionController::Renderers.add :xlsx do |collection, options|
12
+ doc = Ruby2xlsx::Document.new(collection, options)
13
+ send_data(doc.render, :filename => doc.filename, :type => "application/vnd.ms-excel", :disposition => "attachment")
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,25 @@
1
+ module Ruby2xlsx
2
+ class Template < Base
3
+
4
+ # Renders the representation based on source, object, scope and locals
5
+ # Template.new("...source...", { :format => "xlsx" }).render(scope, { :foo => "bar", :object => @user })
6
+ #
7
+ def render(scope, locals, &block)
8
+ @locals, @scope = locals, scope
9
+ set_locals_variables
10
+
11
+ instance_eval(@source) if @source.present?
12
+ instance_eval(&block) if block_given?
13
+
14
+ super
15
+ end
16
+
17
+ protected
18
+
19
+ def set_locals_variables
20
+ @locals.each do |key, value|
21
+ instance_variable_set("@#{key}", value)
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,3 @@
1
+ module Ruby2xlsx
2
+ VERSION = "0.0.1".freeze
3
+ end
@@ -0,0 +1,14 @@
1
+ module Ruby2xlsx
2
+ class Xrb
3
+ # Default format used by Excel builder.
4
+ class_attribute :default_format
5
+ self.default_format = ::Mime::XLSX
6
+
7
+ def call(template)
8
+ %{ controller.send_data ::Ruby2xlsx::Template.new(#{template.source.inspect}).render(self, assigns.merge(local_assigns)),
9
+ :filename => [controller.action_name, ".xlsx"].join,
10
+ :type => "application/vnd.ms-excel",
11
+ :disposition => "attachment" }
12
+ end
13
+ end
14
+ end
data/lib/ruby2xlsx.rb ADDED
@@ -0,0 +1,9 @@
1
+ module Ruby2xlsx
2
+ autoload :Xrb, "ruby2xlsx/xrb"
3
+ autoload :Base, "ruby2xlsx/base"
4
+ autoload :Template, "ruby2xlsx/template"
5
+ autoload :Document, "ruby2xlsx/document"
6
+ autoload :Default, "ruby2xlsx/default"
7
+ end
8
+
9
+ require "ruby2xlsx/engine"
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :ruby2xlsx do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env rake
2
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
3
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
4
+
5
+ require File.expand_path('../config/application', __FILE__)
6
+
7
+ Dummy::Application.load_tasks
@@ -0,0 +1,9 @@
1
+ // This is a manifest file that'll be compiled into including all the files listed below.
2
+ // Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
3
+ // be included in the compiled file accessible from http://example.com/assets/application.js
4
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
5
+ // the compiled file.
6
+ //
7
+ //= require jquery
8
+ //= require jquery_ujs
9
+ //= require_tree .
@@ -0,0 +1,2 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
@@ -0,0 +1,7 @@
1
+ /*
2
+ * This is a manifest file that'll automatically include all the stylesheets available in this directory
3
+ * and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
4
+ * the top of the compiled file, but it's generally better to create a new file per style scope.
5
+ *= require_self
6
+ *= require_tree .
7
+ */
@@ -0,0 +1,4 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -0,0 +1,56 @@
1
+ body { background-color: #fff; color: #333; }
2
+
3
+ body, p, ol, ul, td {
4
+ font-family: verdana, arial, helvetica, sans-serif;
5
+ font-size: 13px;
6
+ line-height: 18px;
7
+ }
8
+
9
+ pre {
10
+ background-color: #eee;
11
+ padding: 10px;
12
+ font-size: 11px;
13
+ }
14
+
15
+ a { color: #000; }
16
+ a:visited { color: #666; }
17
+ a:hover { color: #fff; background-color:#000; }
18
+
19
+ div.field, div.actions {
20
+ margin-bottom: 10px;
21
+ }
22
+
23
+ #notice {
24
+ color: green;
25
+ }
26
+
27
+ .field_with_errors {
28
+ padding: 2px;
29
+ background-color: red;
30
+ display: table;
31
+ }
32
+
33
+ #error_explanation {
34
+ width: 450px;
35
+ border: 2px solid red;
36
+ padding: 7px;
37
+ padding-bottom: 0;
38
+ margin-bottom: 20px;
39
+ background-color: #f0f0f0;
40
+ }
41
+
42
+ #error_explanation h2 {
43
+ text-align: left;
44
+ font-weight: bold;
45
+ padding: 5px 5px 5px 15px;
46
+ font-size: 12px;
47
+ margin: -7px;
48
+ margin-bottom: 0px;
49
+ background-color: #c00;
50
+ color: #fff;
51
+ }
52
+
53
+ #error_explanation ul li {
54
+ font-size: 12px;
55
+ list-style: square;
56
+ }
@@ -0,0 +1,4 @@
1
+ class ApplicationController < ActionController::Base
2
+ protect_from_forgery
3
+ respond_to :html
4
+ end
@@ -0,0 +1,100 @@
1
+ class ArticlesController < ApplicationController
2
+ respond_to :xlsx, :only => [:index, :another, :empty]
3
+
4
+ # GET /articles
5
+ # GET /articles.json
6
+ def index
7
+ @articles = Article.order('id DESC')
8
+
9
+ respond_to do |format|
10
+ format.html # index.html.erb
11
+ format.json { render json: @articles }
12
+ format.xlsx { render xlsx: @articles }
13
+ end
14
+ end
15
+
16
+ def another
17
+ @articles = Article.order('id DESC')
18
+ respond_with(@articles)
19
+ end
20
+
21
+ def empty
22
+ @articles = []
23
+
24
+ respond_to do |format|
25
+ format.json { render json: @articles }
26
+ format.xlsx { render xlsx: @articles }
27
+ end
28
+ end
29
+
30
+ # GET /articles/1
31
+ # GET /articles/1.json
32
+ def show
33
+ @article = Article.find(params[:id])
34
+
35
+ respond_to do |format|
36
+ format.html # show.html.erb
37
+ format.json { render json: @article }
38
+ end
39
+ end
40
+
41
+ # GET /articles/new
42
+ # GET /articles/new.json
43
+ def new
44
+ @article = Article.new
45
+
46
+ respond_to do |format|
47
+ format.html # new.html.erb
48
+ format.json { render json: @article }
49
+ end
50
+ end
51
+
52
+ # GET /articles/1/edit
53
+ def edit
54
+ @article = Article.find(params[:id])
55
+ end
56
+
57
+ # POST /articles
58
+ # POST /articles.json
59
+ def create
60
+ @article = Article.new(params[:article])
61
+
62
+ respond_to do |format|
63
+ if @article.save
64
+ format.html { redirect_to @article, notice: 'Article was successfully created.' }
65
+ format.json { render json: @article, status: :created, location: @article }
66
+ else
67
+ format.html { render action: "new" }
68
+ format.json { render json: @article.errors, status: :unprocessable_entity }
69
+ end
70
+ end
71
+ end
72
+
73
+ # PUT /articles/1
74
+ # PUT /articles/1.json
75
+ def update
76
+ @article = Article.find(params[:id])
77
+
78
+ respond_to do |format|
79
+ if @article.update_attributes(params[:article])
80
+ format.html { redirect_to @article, notice: 'Article was successfully updated.' }
81
+ format.json { head :ok }
82
+ else
83
+ format.html { render action: "edit" }
84
+ format.json { render json: @article.errors, status: :unprocessable_entity }
85
+ end
86
+ end
87
+ end
88
+
89
+ # DELETE /articles/1
90
+ # DELETE /articles/1.json
91
+ def destroy
92
+ @article = Article.find(params[:id])
93
+ @article.destroy
94
+
95
+ respond_to do |format|
96
+ format.html { redirect_to articles_url }
97
+ format.json { head :ok }
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ module ArticlesHelper
2
+ end
@@ -0,0 +1,3 @@
1
+ class Article < ActiveRecord::Base
2
+ validates_presence_of :title
3
+ end
@@ -0,0 +1,20 @@
1
+ <%= form_for(@article) do |f| %>
2
+ <% if @article.errors.any? %>
3
+ <div id="error_explanation">
4
+ <h2><%= pluralize(@article.errors.count, "error") %> prohibited this article from being saved:</h2>
5
+
6
+ <ul>
7
+ <% @article.errors.full_messages.each do |msg| %>
8
+ <li><%= msg %></li>
9
+ <% end %>
10
+ </ul>
11
+ </div>
12
+ <% end %>
13
+
14
+ <%= f.label :title %><br/>
15
+ <%= f.text_field :title %>
16
+
17
+ <div class="actions">
18
+ <%= f.submit %>
19
+ </div>
20
+ <% end %>
@@ -0,0 +1,55 @@
1
+ add_worksheet "Sheet1"
2
+
3
+ bold = add_format(:bold => 1)
4
+
5
+ # Add the worksheet data that the charts will refer to.
6
+ headings = [ 'Category', 'Values 1', 'Values 2' ]
7
+ data = [
8
+ [ 2, 3, 4, 5, 6, 7 ],
9
+ [ 1, 4, 5, 2, 1, 5 ],
10
+ [ 3, 6, 7, 5, 4, 3 ]
11
+ ]
12
+
13
+ write('A1', headings, bold)
14
+ write('A2', data)
15
+
16
+ @articles.each_with_index do |article, index|
17
+ row = index + 10
18
+ write(row, 0, article.id)
19
+ write(row, 1, article.title)
20
+ write(row, 2, article.created_at)
21
+ end
22
+
23
+ chart1 = add_chart(:type => 'Chart::Area')
24
+ # Add values only. Use the default categories.
25
+ chart1.add_series( :values => '=Sheet1!$B$2:$B$7' )
26
+
27
+ chart2 = add_chart(:type => 'Chart::Area')
28
+
29
+ # Configure the series.
30
+ chart2.add_series(
31
+ :categories => '=Sheet1!$A$2:$A$7',
32
+ :values => '=Sheet1!$B$2:$B$7',
33
+ :name => 'Test data series 1'
34
+ )
35
+
36
+ chart4 = add_chart(:name => 'Results Chart', :type => 'Chart::Area')
37
+
38
+ # Configure the series.
39
+ chart4.add_series(
40
+ :categories => '=Sheet1!$A$2:$A$7',
41
+ :values => '=Sheet1!$B$2:$B$7',
42
+ :name => 'Test data series 1'
43
+ )
44
+
45
+ # Add another series.
46
+ chart4.add_series(
47
+ :categories => '=Sheet1!$A$2:$A$7',
48
+ :values => '=Sheet1!$C$2:$C$7',
49
+ :name => 'Test data series 2'
50
+ )
51
+
52
+ # Add some labels.
53
+ chart4.set_title( :name => 'Results of sample analysis' )
54
+ chart4.set_x_axis( :name => 'Sample number' )
55
+ chart4.set_y_axis( :name => 'Sample length (cm)' )
@@ -0,0 +1,6 @@
1
+ <h1>Editing article</h1>
2
+
3
+ <%= render 'form' %>
4
+
5
+ <%= link_to 'Show', @article %> |
6
+ <%= link_to 'Back', articles_path %>