Module: Fir

Defined in:
lib/fir/boot.rb,
lib/fir/util.rb,
lib/fir/admin.rb,
lib/fir/pages.rb,
lib/fir/tasks.rb,
lib/fir/static.rb,
lib/fir/helpers.rb,
lib/fir/generator.rb

Defined Under Namespace

Modules: AdminMiddleware, Helpers, Tasks, TemplateLoading Classes: AdminAuth, AdminInterface, ErbAdapter, Generator, MarkdownAdapter, NoOpAdapter, PageRenderer, Static, TemplateAdapter

Class Method Summary collapse

Class Method Details

.boot_procObject



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/fir/boot.rb', line 2

def self.boot_proc
	# This get called in config.ru. Thus, Passenger can eval the contents of config.ru the way it wants to
	lambda do
		# Depending on the location of the script that invoked Fir, all the relative paths may be messed up.
		# This happens, for example, when running dispatch.cgi from the public directory. Changing the working
		# directory fixes that.
		Dir.chdir(FIR_ROOT)
		::Fir.validate_config
		::Fir.load_support_files
		#use ::Rack::Reloader # Only when developing the Fir gem
		use ::Rack::ContentLength
		use ::Fir::Static
		use ::Fir::AdminAuth
		use ::Fir::AdminInterface
		run ::Fir::PageRenderer.new
	end
end

.clear_cache(page) ⇒ Object

Page is a path such as you would find in a URL, not a local filesystem path



3
4
5
6
7
8
9
# File 'lib/fir/util.rb', line 3

def self.clear_cache(page)
	directory, filename, ext = Fir.split_path(page)
	path = File.join(FIR_ROOT, 'public/cache', directory, filename + '.html')
	if File.exists?(path)
		File.delete(path)
	end
end

.config {|@config| ... } ⇒ Object

Yields:



11
12
13
14
15
16
17
18
19
20
# File 'lib/fir/util.rb', line 11

def self.config
	@config ||= OpenStruct.new
	yield @config if block_given?
	# force_caching allows the export task to turn caching on even if it's set to off in config.rb
	@config.perform_caching = true if @config.force_caching
	# Default configs go here
	@config.perform_caching ||= false
	@config.relative_url_root ||= ''
	@config
end

.encrypt_password(password, salt) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/fir/util.rb', line 22

def self.encrypt_password(password, salt)
	crypted_password = password + salt
	3.times do
		crypted_password = Digest::SHA512.hexdigest(crypted_password)
	end
	crypted_password
end

.generate!(args) ⇒ Object



2
3
4
# File 'lib/fir/generator.rb', line 2

def self.generate!(args)
	::Fir::Generator.new.generate!(args)
end

.load_support_filesObject



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/fir/util.rb', line 30

def self.load_support_files
	Dir.glob(File.join(FIR_ROOT, 'helpers', '*.rb')).each do |helper_file|
		require File.expand_path(helper_file)
		mod_name = File.basename(helper_file, File.extname(helper_file)).classify
		begin
			mod = Object.const_get(mod_name)
		rescue NameError
			raise "Expected helpers/#{helper_file} to define #{mod_name}"
		end
		ErbAdapter.send(:include, mod)
	end
end

.sanitize_page(page) ⇒ Object



43
44
45
# File 'lib/fir/util.rb', line 43

def self.sanitize_page(page)
	page.gsub('../', '')
end

.split_path(path) ⇒ Object

returns [directories, name w/o extension, extension]



48
49
50
51
52
53
# File 'lib/fir/util.rb', line 48

def self.split_path(path)
	ext = File.extname(path)
	dirname = File.dirname(path)
	dirname = '' if dirname == '.'
	[dirname, File.basename(path, ext), ext]
end

.validate_configObject



55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/fir/util.rb', line 55

def self.validate_config
	unless @config
		raise 'Fir cannot start unless you call Fir.config in config.rb.'
	end
	missing_options = [:site_name, :perform_caching, :relative_url_root].inject([]) do |missing, opt|
		missing << opt if @config.send(opt).nil?
		missing
	end
	unless missing_options.empty?
		raise "Fir.config (in config.rb) is missing the following options: #{missing_options.join(', ')}"
	end
end