caracal-rails 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +26 -0
  3. data/Appraisals +17 -0
  4. data/Gemfile +3 -0
  5. data/LICENSE.txt +22 -0
  6. data/README.md +99 -0
  7. data/Rakefile +2 -0
  8. data/caracal-rails.gemspec +27 -0
  9. data/gemfiles/rails_3.2.gemfile +8 -0
  10. data/gemfiles/rails_4.0.gemfile +8 -0
  11. data/gemfiles/rails_4.1.gemfile +8 -0
  12. data/lib/caracal-rails.rb +29 -0
  13. data/lib/caracal/rails/template_handler.rb +11 -0
  14. data/lib/caracal/rails/version.rb +5 -0
  15. data/spec/dummy/Rakefile +6 -0
  16. data/spec/dummy/app/assets/images/.keep +0 -0
  17. data/spec/dummy/app/assets/javascripts/application.js +16 -0
  18. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  19. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  20. data/spec/dummy/app/controllers/concerns/.keep +0 -0
  21. data/spec/dummy/app/controllers/statics_controller.rb +3 -0
  22. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  23. data/spec/dummy/app/mailers/.keep +0 -0
  24. data/spec/dummy/app/models/.keep +0 -0
  25. data/spec/dummy/app/models/concerns/.keep +0 -0
  26. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  27. data/spec/dummy/app/views/statics/show.docx.caracal +1 -0
  28. data/spec/dummy/bin/bundle +3 -0
  29. data/spec/dummy/bin/rails +8 -0
  30. data/spec/dummy/bin/rake +8 -0
  31. data/spec/dummy/bin/spring +18 -0
  32. data/spec/dummy/config.ru +4 -0
  33. data/spec/dummy/config/application.rb +23 -0
  34. data/spec/dummy/config/boot.rb +4 -0
  35. data/spec/dummy/config/database.yml +25 -0
  36. data/spec/dummy/config/environment.rb +5 -0
  37. data/spec/dummy/config/environments/development.rb +37 -0
  38. data/spec/dummy/config/environments/production.rb +83 -0
  39. data/spec/dummy/config/environments/test.rb +39 -0
  40. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  41. data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
  42. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  43. data/spec/dummy/config/initializers/inflections.rb +16 -0
  44. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  45. data/spec/dummy/config/initializers/session_store.rb +3 -0
  46. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  47. data/spec/dummy/config/locales/en.yml +23 -0
  48. data/spec/dummy/config/routes.rb +3 -0
  49. data/spec/dummy/config/secrets.yml +22 -0
  50. data/spec/dummy/public/404.html +67 -0
  51. data/spec/dummy/public/422.html +67 -0
  52. data/spec/dummy/public/500.html +66 -0
  53. data/spec/dummy/public/favicon.ico +0 -0
  54. data/spec/dummy/public/robots.txt +5 -0
  55. data/spec/lib/caracal-rails_spec.rb +59 -0
  56. data/spec/lib/caracal/rails/template_handler_spec.rb +21 -0
  57. data/spec/lib/caracal/rails/version.rb +3 -0
  58. data/spec/spec_helper.rb +40 -0
  59. metadata +219 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: adb1feddfbe63116a2ee52a308f0bc0db2ee8942
4
+ data.tar.gz: 39165bf8dd33040c07d6e0ca600026d5ccf64e98
5
+ SHA512:
6
+ metadata.gz: 85c6d51dc91ee6573adc4e04efd8851bc9aa4b9ac9c06b9d85de6f57a4b7a8fd28a5c0089d0c623acd28c67956ec9bbeb817f23eb02e666a2536a34f90d1ac59
7
+ data.tar.gz: 9307effc71b92b3bad2e0dd7a08404280f979d6c692f9271f83aa28b8bd47c95eeeec27979e11fe152a3108f9f11d0df99157c49ed6cd3fdf805659dbc70d079
@@ -0,0 +1,26 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
23
+ gemfiles/*.gemfile.lock
24
+ spec/dummy/db
25
+ spec/dummy/log
26
+ spec/dummy/tmp
@@ -0,0 +1,17 @@
1
+ appraise 'rails-3.2' do
2
+ gem 'rails', '~> 3.2.18'
3
+ gem 'sqlite3'
4
+ gem 'caracal', path: '~/workspace/plia/caracal', ref: 'e2b84b191efe6b7871259201413c13918091c6b4'
5
+ end
6
+
7
+ appraise 'rails-4.0' do
8
+ gem 'rails', '~> 4.0.5'
9
+ gem 'sqlite3'
10
+ gem 'caracal', path: '~/workspace/plia/caracal', ref: 'e2b84b191efe6b7871259201413c13918091c6b4'
11
+ end
12
+
13
+ appraise 'rails-4.1' do
14
+ gem 'rails', '~> 4.1.1'
15
+ gem 'sqlite3'
16
+ gem 'caracal', path: '~/workspace/plia/caracal', ref: 'e2b84b191efe6b7871259201413c13918091c6b4'
17
+ end
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Trade Informatics, Inc
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,99 @@
1
+ # Caracal-Rails
2
+
3
+ [Caracal](https://github.com/ibpinc/caracal) is a ruby library for dynamically creating professional-quality Microsoft Word documents (.docx).
4
+
5
+ Caracal-Rails is a drop in solution for registering the Microsoft Word mime type and for establishing a template handler in Rails for the :docx format. All caracal documents are rendered with an explicit block passing an argument named `docx`.
6
+
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ gem 'caracal-rails'
13
+
14
+ Then execute:
15
+
16
+ $ bundle install
17
+
18
+
19
+ ## Usage
20
+
21
+ Design your controller normally:
22
+
23
+ class ReportsController < ApplicationController
24
+ def show
25
+ # collect your models/view models here
26
+ end
27
+ end
28
+
29
+ Then add a view file with the Caracal extension:
30
+
31
+ apps/views/reports/show.docx.caracal
32
+
33
+ Inside your view, simply issue Caracal commands on the document object:
34
+
35
+ docx.file_name 'quarterly_report'
36
+
37
+ docx.font 'Arial'
38
+ docx.font 'Droid Serif'
39
+
40
+ docx.style 'special' do
41
+ font 'Droid Serif'
42
+ italic true
43
+ size 16
44
+ end
45
+
46
+ docx.content do
47
+ h1 'Quarterly Report'
48
+ hr
49
+ h2 'Client A'
50
+ p 'Lorem ipsum dolor...'
51
+ p do
52
+ text 'Normal text'
53
+ link 'Link text', 'http://www.google.com/', class: 'special
54
+ text 'More normal text'
55
+ end
56
+ img image_url('example.png'), width: 300, height: 200, align: 'right'
57
+ br
58
+ table data, border: 1 do
59
+ cell_style rows(0), background_color: '3366cc', color: 'ffffff', bold: true
60
+ end
61
+ page
62
+ p 'This is an bulleted list'
63
+ ul do
64
+ li do
65
+ strong 'Item 1'
66
+ text 'More text'
67
+ end
68
+ li 'Item 2'
69
+ end
70
+ ...
71
+ end
72
+
73
+ *See the [Caracal](https://github.com/ibpinc/caracal) library for more details.*
74
+
75
+
76
+ ## Contributing
77
+
78
+ 1. Fork it ( https://github.com/ibpinc/caracal-rails/fork )
79
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
80
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
81
+ 4. Push to the branch (`git push origin my-new-feature`)
82
+ 5. Create a new Pull Request
83
+
84
+
85
+ ## Why is It Called Caracal?
86
+
87
+ Because my son likes caracals. :)
88
+
89
+
90
+ ## Inspiration
91
+
92
+ A tip of the hat to the wonderful PDF generation libraries [Prawn](https://github.com/prawnpdf/prawn) and [Prawnto](https://github.com/GetJobber/prawnto).
93
+
94
+
95
+ ## License
96
+
97
+ Copyright (c) 2014 Trade Informatics, Inc
98
+
99
+ [MIT License](https://github.com/ibpinc/caracal-rails/blob/master/LICENSE.txt)
@@ -0,0 +1,2 @@
1
+ require 'bundler/gem_tasks'
2
+
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'caracal/rails/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'caracal-rails'
8
+ spec.version = Caracal::Rails::VERSION
9
+ spec.authors = ['Trade Informatics', 'John Dugan']
10
+ spec.email = ['jpdugan@gmail.com']
11
+ spec.summary = %q{ Caracal::Rails makes using Caracal in Rails a no-brainer. }
12
+ spec.description = %q{ Caracal::Rails takes care of registering Microsoft Word output with Rails. Essentially, this involves registering the mime type, establishing a template handler for .docx formats, and establishing sane defaults for generating professional quality Word documents. }
13
+ spec.homepage = 'https://github.com/ibpinc/caracal-rails'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_dependency 'caracal', '~> 0.1'
22
+ spec.add_dependency 'rails', '>= 3.2'
23
+
24
+ spec.add_development_dependency 'appraisal', '~> 1.0'
25
+ spec.add_development_dependency 'bundler', '~> 1.6'
26
+ spec.add_development_dependency 'rspec-rails', '~> 3.0'
27
+ end
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "~> 3.2.18"
6
+ gem "sqlite3"
7
+
8
+ gemspec :path => "../"
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "~> 4.0.5"
6
+ gem "sqlite3"
7
+
8
+ gemspec :path => "../"
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "~> 4.1.1"
6
+ gem "sqlite3"
7
+
8
+ gemspec :path => "../"
@@ -0,0 +1,29 @@
1
+ require 'caracal'
2
+ require 'caracal/rails/template_handler'
3
+ require 'caracal/rails/version'
4
+ require 'tilt'
5
+ require 'tilt/caracal'
6
+
7
+
8
+ module Caracal
9
+ module Rails
10
+ class Railtie < ::Rails::Railtie
11
+
12
+ #----------------------------------------------------
13
+ # Register mime types and template handlers.
14
+ #
15
+ initializer 'caracal.registrations' do
16
+ Tilt.register 'caracal', Tilt::CaracalTemplate
17
+
18
+ unless Mime::Type.lookup_by_extension(:docx)
19
+ Mime::Type.register('application/vnd.openxmlformats-officedocument.wordprocessingml.document', :docx)
20
+ end
21
+
22
+ ActiveSupport.on_load(:action_view) do
23
+ ActionView::Template.register_template_handler :caracal, Caracal::Rails::TemplateHandler
24
+ end
25
+ end
26
+
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,11 @@
1
+ module Caracal
2
+ module Rails
3
+ class TemplateHandler
4
+
5
+ def self.call(template)
6
+ "Tilt.new('#{ template.identifier }').render(self)"
7
+ end
8
+
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ module Caracal
2
+ module Rails
3
+ VERSION = '0.1.0'
4
+ end
5
+ end
@@ -0,0 +1,6 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require File.expand_path('../config/application', __FILE__)
5
+
6
+ Rails.application.load_tasks
File without changes
@@ -0,0 +1,16 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require jquery
14
+ //= require jquery_ujs
15
+ //= require turbolinks
16
+ //= require_tree .
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any styles
10
+ * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
+ * file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,5 @@
1
+ class ApplicationController < ActionController::Base
2
+ # Prevent CSRF attacks by raising an exception.
3
+ # For APIs, you may want to use :null_session instead.
4
+ protect_from_forgery with: :exception
5
+ end
@@ -0,0 +1,3 @@
1
+ class StaticsController < ApplicationController
2
+ def index; end
3
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
File without changes
File without changes
File without changes
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Dummy</title>
5
+ <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
6
+ <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1 @@
1
+ docx.file_name 'test.docx'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
3
+ load Gem.bin_path('bundler', 'bundle')
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ begin
3
+ load File.expand_path("../spring", __FILE__)
4
+ rescue LoadError
5
+ end
6
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
7
+ require_relative '../config/boot'
8
+ require 'rails/commands'
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ begin
3
+ load File.expand_path("../spring", __FILE__)
4
+ rescue LoadError
5
+ end
6
+ require_relative '../config/boot'
7
+ require 'rake'
8
+ Rake.application.run
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # This file loads spring without using Bundler, in order to be fast
4
+ # It gets overwritten when you run the `spring binstub` command
5
+
6
+ unless defined?(Spring)
7
+ require "rubygems"
8
+ require "bundler"
9
+
10
+ if match = Bundler.default_lockfile.read.match(/^GEM$.*?^ spring \((.*?)\)$.*?^$/m)
11
+ ENV["GEM_PATH"] = ([Bundler.bundle_path.to_s] + Gem.path).join(File::PATH_SEPARATOR)
12
+ ENV["GEM_HOME"] = ""
13
+ Gem.paths = ENV
14
+
15
+ gem "spring", match[1]
16
+ require "spring/binstub"
17
+ end
18
+ end
@@ -0,0 +1,4 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
+ run Rails.application
@@ -0,0 +1,23 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ require 'rails/all'
4
+
5
+ # Require the gems listed in Gemfile, including any gems
6
+ # you've limited to :test, :development, or :production.
7
+ Bundler.require(*Rails.groups)
8
+
9
+ module Dummy
10
+ class Application < Rails::Application
11
+ # Settings in config/environments/* take precedence over those specified here.
12
+ # Application configuration should go into files in config/initializers
13
+ # -- all .rb files in that directory are automatically loaded.
14
+
15
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
16
+ # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
17
+ # config.time_zone = 'Central Time (US & Canada)'
18
+
19
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
20
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
21
+ # config.i18n.default_locale = :de
22
+ end
23
+ end