rails-latex 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +6 -0
- data/examples/rails-latex-demo/app/controllers/application_controller.rb +3 -0
- data/examples/rails-latex-demo/app/controllers/latex_example_controller.rb +5 -0
- data/examples/rails-latex-demo/config/application.rb +47 -0
- data/examples/rails-latex-demo/config/boot.rb +13 -0
- data/examples/rails-latex-demo/config/environment.rb +5 -0
- data/examples/rails-latex-demo/config/environments/development.rb +26 -0
- data/examples/rails-latex-demo/config/environments/production.rb +49 -0
- data/examples/rails-latex-demo/config/environments/test.rb +35 -0
- data/examples/rails-latex-demo/config/initializers/backtrace_silencers.rb +7 -0
- data/examples/rails-latex-demo/config/initializers/inflections.rb +10 -0
- data/examples/rails-latex-demo/config/initializers/mime_types.rb +6 -0
- data/examples/rails-latex-demo/config/initializers/secret_token.rb +7 -0
- data/examples/rails-latex-demo/config/initializers/session_store.rb +8 -0
- data/examples/rails-latex-demo/config/routes.rb +5 -0
- data/examples/rails-latex-demo/test/functional/latex_example_controller_test.rb +9 -0
- data/examples/rails-latex-demo/test/unit/helpers/latex_example_helper_test.rb +4 -0
- data/lib/erb_latex.rb +1 -1
- data/lib/latex_to_pdf.rb +5 -3
- metadata +37 -7
data/README.rdoc
CHANGED
@@ -40,6 +40,12 @@ config/initializers/mime_types.rb:
|
|
40
40
|
Only the file containing the \\documentclass should be of type: .pdf.erbtex . Partials and views (when there is a layout)
|
41
41
|
should be of type .pdf.erb .
|
42
42
|
|
43
|
+
If a LaTeX package requires two parses then add the following to the .pdf.erbtex file:
|
44
|
+
|
45
|
+
<% @latex_parse_twice=true %>
|
46
|
+
|
47
|
+
See the rails application under examples/rails-latex-demo/ for a working example.
|
48
|
+
|
43
49
|
== Requirements
|
44
50
|
|
45
51
|
* ruby 1.8 or 1.9
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require File.expand_path('../boot', __FILE__)
|
2
|
+
|
3
|
+
# Pick the frameworks you want:
|
4
|
+
# require "active_record/railtie"
|
5
|
+
require "action_controller/railtie"
|
6
|
+
require "action_mailer/railtie"
|
7
|
+
require "active_resource/railtie"
|
8
|
+
require "rails/test_unit/railtie"
|
9
|
+
|
10
|
+
# If you have a Gemfile, require the gems listed there, including any gems
|
11
|
+
# you've limited to :test, :development, or :production.
|
12
|
+
Bundler.require(:default, Rails.env) if defined?(Bundler)
|
13
|
+
|
14
|
+
module RailsLatexDemo
|
15
|
+
class Application < Rails::Application
|
16
|
+
# Settings in config/environments/* take precedence over those specified here.
|
17
|
+
# Application configuration should go into files in config/initializers
|
18
|
+
# -- all .rb files in that directory are automatically loaded.
|
19
|
+
|
20
|
+
# Custom directories with classes and modules you want to be autoloadable.
|
21
|
+
# config.autoload_paths += %W(#{config.root}/extras)
|
22
|
+
|
23
|
+
# Only load the plugins named here, in the order given (default is alphabetical).
|
24
|
+
# :all can be used as a placeholder for all plugins not explicitly named.
|
25
|
+
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]
|
26
|
+
|
27
|
+
# Activate observers that should always be running.
|
28
|
+
# config.active_record.observers = :cacher, :garbage_collector, :forum_observer
|
29
|
+
|
30
|
+
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
|
31
|
+
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
|
32
|
+
# config.time_zone = 'Central Time (US & Canada)'
|
33
|
+
|
34
|
+
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
|
35
|
+
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
|
36
|
+
# config.i18n.default_locale = :de
|
37
|
+
|
38
|
+
# JavaScript files you want as :defaults (application.js is always included).
|
39
|
+
config.action_view.javascript_expansions[:defaults] = %w()
|
40
|
+
|
41
|
+
# Configure the default encoding used in templates for Ruby 1.9.
|
42
|
+
config.encoding = "utf-8"
|
43
|
+
|
44
|
+
# Configure sensitive parameters which will be filtered from the log file.
|
45
|
+
config.filter_parameters += [:password]
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
# Set up gems listed in the Gemfile.
|
4
|
+
gemfile = File.expand_path('../../Gemfile', __FILE__)
|
5
|
+
begin
|
6
|
+
ENV['BUNDLE_GEMFILE'] = gemfile
|
7
|
+
require 'bundler'
|
8
|
+
Bundler.setup
|
9
|
+
rescue Bundler::GemNotFound => e
|
10
|
+
STDERR.puts e.message
|
11
|
+
STDERR.puts "Try running `bundle install`."
|
12
|
+
exit!
|
13
|
+
end if File.exist?(gemfile)
|
@@ -0,0 +1,26 @@
|
|
1
|
+
RailsLatexDemo::Application.configure do
|
2
|
+
# Settings specified here will take precedence over those in config/application.rb
|
3
|
+
|
4
|
+
# In the development environment your application's code is reloaded on
|
5
|
+
# every request. This slows down response time but is perfect for development
|
6
|
+
# since you don't have to restart the webserver when you make code changes.
|
7
|
+
config.cache_classes = false
|
8
|
+
|
9
|
+
# Log error messages when you accidentally call methods on nil.
|
10
|
+
config.whiny_nils = true
|
11
|
+
|
12
|
+
# Show full error reports and disable caching
|
13
|
+
config.consider_all_requests_local = true
|
14
|
+
config.action_view.debug_rjs = true
|
15
|
+
config.action_controller.perform_caching = false
|
16
|
+
|
17
|
+
# Don't care if the mailer can't send
|
18
|
+
config.action_mailer.raise_delivery_errors = false
|
19
|
+
|
20
|
+
# Print deprecation notices to the Rails logger
|
21
|
+
config.active_support.deprecation = :log
|
22
|
+
|
23
|
+
# Only use best-standards-support built into browsers
|
24
|
+
config.action_dispatch.best_standards_support = :builtin
|
25
|
+
end
|
26
|
+
|
@@ -0,0 +1,49 @@
|
|
1
|
+
RailsLatexDemo::Application.configure do
|
2
|
+
# Settings specified here will take precedence over those in config/application.rb
|
3
|
+
|
4
|
+
# The production environment is meant for finished, "live" apps.
|
5
|
+
# Code is not reloaded between requests
|
6
|
+
config.cache_classes = true
|
7
|
+
|
8
|
+
# Full error reports are disabled and caching is turned on
|
9
|
+
config.consider_all_requests_local = false
|
10
|
+
config.action_controller.perform_caching = true
|
11
|
+
|
12
|
+
# Specifies the header that your server uses for sending files
|
13
|
+
config.action_dispatch.x_sendfile_header = "X-Sendfile"
|
14
|
+
|
15
|
+
# For nginx:
|
16
|
+
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'
|
17
|
+
|
18
|
+
# If you have no front-end server that supports something like X-Sendfile,
|
19
|
+
# just comment this out and Rails will serve the files
|
20
|
+
|
21
|
+
# See everything in the log (default is :info)
|
22
|
+
# config.log_level = :debug
|
23
|
+
|
24
|
+
# Use a different logger for distributed setups
|
25
|
+
# config.logger = SyslogLogger.new
|
26
|
+
|
27
|
+
# Use a different cache store in production
|
28
|
+
# config.cache_store = :mem_cache_store
|
29
|
+
|
30
|
+
# Disable Rails's static asset server
|
31
|
+
# In production, Apache or nginx will already do this
|
32
|
+
config.serve_static_assets = false
|
33
|
+
|
34
|
+
# Enable serving of images, stylesheets, and javascripts from an asset server
|
35
|
+
# config.action_controller.asset_host = "http://assets.example.com"
|
36
|
+
|
37
|
+
# Disable delivery errors, bad email addresses will be ignored
|
38
|
+
# config.action_mailer.raise_delivery_errors = false
|
39
|
+
|
40
|
+
# Enable threaded mode
|
41
|
+
# config.threadsafe!
|
42
|
+
|
43
|
+
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
|
44
|
+
# the I18n.default_locale when a translation can not be found)
|
45
|
+
config.i18n.fallbacks = true
|
46
|
+
|
47
|
+
# Send deprecation notices to registered listeners
|
48
|
+
config.active_support.deprecation = :notify
|
49
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
RailsLatexDemo::Application.configure do
|
2
|
+
# Settings specified here will take precedence over those in config/application.rb
|
3
|
+
|
4
|
+
# The test environment is used exclusively to run your application's
|
5
|
+
# test suite. You never need to work with it otherwise. Remember that
|
6
|
+
# your test database is "scratch space" for the test suite and is wiped
|
7
|
+
# and recreated between test runs. Don't rely on the data there!
|
8
|
+
config.cache_classes = true
|
9
|
+
|
10
|
+
# Log error messages when you accidentally call methods on nil.
|
11
|
+
config.whiny_nils = true
|
12
|
+
|
13
|
+
# Show full error reports and disable caching
|
14
|
+
config.consider_all_requests_local = true
|
15
|
+
config.action_controller.perform_caching = false
|
16
|
+
|
17
|
+
# Raise exceptions instead of rendering exception templates
|
18
|
+
config.action_dispatch.show_exceptions = false
|
19
|
+
|
20
|
+
# Disable request forgery protection in test environment
|
21
|
+
config.action_controller.allow_forgery_protection = false
|
22
|
+
|
23
|
+
# Tell Action Mailer not to deliver emails to the real world.
|
24
|
+
# The :test delivery method accumulates sent emails in the
|
25
|
+
# ActionMailer::Base.deliveries array.
|
26
|
+
config.action_mailer.delivery_method = :test
|
27
|
+
|
28
|
+
# Use SQL instead of Active Record's schema dumper when creating the test database.
|
29
|
+
# This is necessary if your schema can't be completely dumped by the schema dumper,
|
30
|
+
# like if you have constraints or database-specific column types
|
31
|
+
# config.active_record.schema_format = :sql
|
32
|
+
|
33
|
+
# Print deprecation notices to the stderr
|
34
|
+
config.active_support.deprecation = :stderr
|
35
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
|
4
|
+
# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
|
5
|
+
|
6
|
+
# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
|
7
|
+
# Rails.backtrace_cleaner.remove_silencers!
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# Add new inflection rules using the following format
|
4
|
+
# (all these examples are active by default):
|
5
|
+
# ActiveSupport::Inflector.inflections do |inflect|
|
6
|
+
# inflect.plural /^(ox)$/i, '\1en'
|
7
|
+
# inflect.singular /^(ox)en/i, '\1'
|
8
|
+
# inflect.irregular 'person', 'people'
|
9
|
+
# inflect.uncountable %w( fish sheep )
|
10
|
+
# end
|
@@ -0,0 +1,6 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# Add new mime types for use in respond_to blocks:
|
4
|
+
# Mime::Type.register "text/richtext", :rtf
|
5
|
+
# Mime::Type.register_alias "text/html", :iphone
|
6
|
+
Mime::Type.register "application/pdf", :pdf, ['text/pdf'], ['pdf']
|
@@ -0,0 +1,7 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# Your secret key for verifying the integrity of signed cookies.
|
4
|
+
# If you change this key, all old signed cookies will become invalid!
|
5
|
+
# Make sure the secret is at least 30 characters and all random,
|
6
|
+
# no regular words or you'll be exposed to dictionary attacks.
|
7
|
+
RailsLatexDemo::Application.config.secret_token = '1f3454cf2022edc496819d0703eae2a92b3526bf35dc9cbfbb64842b764f83b50d11893a5af2c64babbf30edd9f150d33e8340064bee2498cc543b7427a26b9d'
|
@@ -0,0 +1,8 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
RailsLatexDemo::Application.config.session_store :cookie_store, :key => '_rails-latex-demo_session'
|
4
|
+
|
5
|
+
# Use the database for sessions instead of the cookie-based default,
|
6
|
+
# which shouldn't be used to store highly confidential information
|
7
|
+
# (create the session table with "rails generate session_migration")
|
8
|
+
# RailsLatexDemo::Application.config.session_store :active_record_store
|
data/lib/erb_latex.rb
CHANGED
@@ -8,7 +8,7 @@ module ActionView # :nodoc: all
|
|
8
8
|
def compile(template)
|
9
9
|
erb = "<% __in_erb_template=true %>#{template.source}"
|
10
10
|
out=self.class.erb_implementation.new(erb, :trim=>(self.class.erb_trim_mode == "-")).src
|
11
|
-
out + ";LatexToPdf.generate_pdf(@output_buffer.to_s)"
|
11
|
+
out + ";LatexToPdf.generate_pdf(@output_buffer.to_s,@latex_parse_twice)"
|
12
12
|
end
|
13
13
|
end
|
14
14
|
end
|
data/lib/latex_to_pdf.rb
CHANGED
@@ -3,13 +3,15 @@ class LatexToPdf
|
|
3
3
|
#
|
4
4
|
# pdflatex is used to convert the file and creates the directory +#{Rails.root}/tmp/rails-latex+ to store intermediate
|
5
5
|
# files.
|
6
|
-
def self.generate_pdf(code)
|
6
|
+
def self.generate_pdf(code,parse_twice=false)
|
7
7
|
dir=File.join(Rails.root,'tmp','rails-latex',"#{Process.pid}-#{Thread.current.hash}")
|
8
8
|
input=File.join(dir,'input.tex')
|
9
9
|
FileUtils.mkdir_p(dir)
|
10
10
|
File.open(input,'wb') {|io| io.write(code) }
|
11
|
-
|
12
|
-
|
11
|
+
(parse_twice ? 2 : 1).times {
|
12
|
+
system('pdflatex','-output-directory',dir,'-interaction','batchmode',input,
|
13
|
+
:umask => 7,:out => :close, :err => :close, :in => :close)
|
14
|
+
}
|
13
15
|
result=File.read(input.sub(/\.tex$/,'.pdf'))
|
14
16
|
FileUtils.rm_rf(dir)
|
15
17
|
result
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 1
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 1.0.
|
8
|
+
- 1
|
9
|
+
version: 1.0.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Geoff Jacobsen
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date:
|
17
|
+
date: 2011-01-19 00:00:00 +13:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -29,8 +29,7 @@ dependencies:
|
|
29
29
|
- 3
|
30
30
|
- 0
|
31
31
|
- 0
|
32
|
-
|
33
|
-
version: 3.0.0.beta3
|
32
|
+
version: 3.0.0
|
34
33
|
type: :runtime
|
35
34
|
version_requirements: *id001
|
36
35
|
description: rails-latex is a renderer for rails 3 which allows tex files with erb to be turned into an inline pdf.
|
@@ -51,13 +50,28 @@ files:
|
|
51
50
|
- test/test_doc.tex
|
52
51
|
- test/test_latex_to_pdf.rb
|
53
52
|
- README.rdoc
|
53
|
+
- examples/rails-latex-demo/app/controllers/application_controller.rb
|
54
|
+
- examples/rails-latex-demo/app/controllers/latex_example_controller.rb
|
55
|
+
- examples/rails-latex-demo/config/application.rb
|
56
|
+
- examples/rails-latex-demo/config/boot.rb
|
57
|
+
- examples/rails-latex-demo/config/environment.rb
|
58
|
+
- examples/rails-latex-demo/config/environments/development.rb
|
59
|
+
- examples/rails-latex-demo/config/environments/production.rb
|
60
|
+
- examples/rails-latex-demo/config/environments/test.rb
|
61
|
+
- examples/rails-latex-demo/config/initializers/backtrace_silencers.rb
|
62
|
+
- examples/rails-latex-demo/config/initializers/inflections.rb
|
63
|
+
- examples/rails-latex-demo/config/initializers/mime_types.rb
|
64
|
+
- examples/rails-latex-demo/config/initializers/secret_token.rb
|
65
|
+
- examples/rails-latex-demo/config/initializers/session_store.rb
|
66
|
+
- examples/rails-latex-demo/config/routes.rb
|
67
|
+
- examples/rails-latex-demo/test/functional/latex_example_controller_test.rb
|
68
|
+
- examples/rails-latex-demo/test/unit/helpers/latex_example_helper_test.rb
|
54
69
|
has_rdoc: true
|
55
70
|
homepage:
|
56
71
|
licenses: []
|
57
72
|
|
58
73
|
post_install_message:
|
59
74
|
rdoc_options:
|
60
|
-
- --charset=UTF-8
|
61
75
|
- --main=README.rdoc
|
62
76
|
require_paths:
|
63
77
|
- lib
|
@@ -85,5 +99,21 @@ signing_key:
|
|
85
99
|
specification_version: 3
|
86
100
|
summary: A LaTeX to pdf rails 3 renderer.
|
87
101
|
test_files:
|
88
|
-
-
|
102
|
+
- examples/rails-latex-demo/app/controllers/application_controller.rb
|
103
|
+
- examples/rails-latex-demo/app/controllers/latex_example_controller.rb
|
104
|
+
- examples/rails-latex-demo/config/application.rb
|
105
|
+
- examples/rails-latex-demo/config/boot.rb
|
106
|
+
- examples/rails-latex-demo/config/environment.rb
|
107
|
+
- examples/rails-latex-demo/config/environments/development.rb
|
108
|
+
- examples/rails-latex-demo/config/environments/production.rb
|
109
|
+
- examples/rails-latex-demo/config/environments/test.rb
|
110
|
+
- examples/rails-latex-demo/config/initializers/backtrace_silencers.rb
|
111
|
+
- examples/rails-latex-demo/config/initializers/inflections.rb
|
112
|
+
- examples/rails-latex-demo/config/initializers/mime_types.rb
|
113
|
+
- examples/rails-latex-demo/config/initializers/secret_token.rb
|
114
|
+
- examples/rails-latex-demo/config/initializers/session_store.rb
|
115
|
+
- examples/rails-latex-demo/config/routes.rb
|
116
|
+
- examples/rails-latex-demo/test/functional/latex_example_controller_test.rb
|
117
|
+
- examples/rails-latex-demo/test/unit/helpers/latex_example_helper_test.rb
|
89
118
|
- test/helper.rb
|
119
|
+
- test/test_latex_to_pdf.rb
|