-
Notifications
You must be signed in to change notification settings - Fork 34
/
content.rb
99 lines (90 loc) · 2.79 KB
/
content.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
module Content
# returns only dates that have issues if using all or >
def self.parse_dates(date)
if date == 'all'
dates = Entry.find_as_array(
:select => "distinct(publication_date) AS publication_date",
:order => "publication_date"
)
elsif date =~ /^>/
date = Date.parse(date.sub(/^>/, ''))
dates = Entry.find_as_array(
:select => "distinct(publication_date) AS publication_date",
:conditions => {:publication_date => date .. Time.current.to_date},
:order => "publication_date"
)
elsif date =~ /^\d{4}$/
dates = Entry.find_as_array(
:select => "distinct(publication_date) AS publication_date",
:conditions => {:publication_date => Date.parse("#{date}-01-01") .. Date.parse("#{date}-12-31")},
:order => "publication_date"
)
elsif date.present?
dates = [date.is_a?(String) ? date : date.to_s(:iso)]
else
dates = [Time.current.to_date]
end
end
# returns dates regardless of whether they have issues associated
def self.parse_all_dates(date)
if date =~ /^>/
date = Date.parse(date.sub(/^>/, ''))
dates = (date .. Time.current.to_date).to_a
elsif date.present?
dates = [date.is_a?(String) ? date : date.to_s(:iso)]
else
dates = [Time.current.to_date]
end
end
def self.run_myfr2_command(command)
old_gemfile = ENV['BUNDLE_GEMFILE']
Dir.chdir("/var/www/apps/federalregister-web") do
ENV['BUNDLE_GEMFILE'] = nil
puts "running MyFR command: '#{command}'"
system(command) or raise "Error when calling '#{command}'"
end
ensure
ENV['BUNDLE_GEMFILE'] = old_gemfile
end
def self.render_erb(template_path, locals = {})
view = ActionView::Base.new(Rails::Configuration.new.view_path, {})
[
ActionView::Helpers::UrlHelper,
ActionController::UrlWriter,
ApplicationHelper,
HandlebarsHelper,
HtmlHelper,
Html5Helper,
CitationsHelper,
Citations::CfrHelper,
XsltHelper,
RegulatoryPlanHelper,
TextHelper
].each do |mod|
view.extend mod
end
class << view.class
def default_url_options
{:host => "federalregister.gov"}
end
end
# Monkeypatching url_for to deal with this issue: https://rails.lighthouseapp.com/projects/8994/tickets/1560#ticket-1560-4
class << view
include RouteBuilder
def url_for_with_string_support(options)
if String === options
options
else
url_for_without_string_support(options)
end
end
alias_method_chain :url_for, :string_support
end
if template_path =~ /\.erb$/
path = template_path
else
path = "#{template_path}.html.erb"
end
view.render(:file => path, :locals => locals)
end
end