Sha256: fd974822a00cc9aece948c1b4bd736d97c096d8d1eff3a7a60689c67543cbd98

Contents?: true

Size: 1.62 KB

Versions: 1

Compression:

Stored size: 1.62 KB

Contents

require 'pugin/version'

module Pugin
  ASSET_VERSION = '1.4.1'.freeze
  ASSET_LOCATION_URL = ENV.fetch('ASSET_LOCATION_URL', 'https://s3-eu-west-1.amazonaws.com/web1devci.pugin-website')

  class << self
  	# Inspired by bootsrap-sass
  	def load!
  		if rails?
  			register_rails_files
  		elsif sinatra?
  			add_i18n_paths
  		elsif sprockets?
  			register_sprockets
			end

			# Try and load HAML, raising an error if we are not able to
			begin
				require 'haml'
			rescue LoadError => e
				raise(LoadError, "pugin requires the 'haml' gem. Please check it is in your Gemfile - #{e.message}")
			end
		end

		# Paths
		def gem_path
			@gem_path ||= File.expand_path '..', File.dirname(__FILE__)
		end

		def images_path
			File.join assets_path, 'images'
		end

		def javascripts_path
			File.join assets_path, 'javascripts'
		end

		def stylesheets_path
			File.join assets_path, 'stylesheets'
		end

		def views_path
			File.join gem_path, 'app', 'views'
		end

		def assets_path
			@assets_path ||= File.join gem_path, 'app', 'assets'
		end

		# Environment detection helpers
		def rails?
			defined?(::Rails)
		end

		def sinatra?
			defined?(::Sinatra)
		end

		def sprockets?
			defined?(::Sprockets)
		end

		private

		def register_rails_files
			require 'pugin/engine'
      require 'pugin/railtie'
		end

		def add_i18n_paths
			require 'i18n'
			I18n.load_path += Dir[File.join(gem_path, 'config', 'locales', '*.yml')]
		end

		def register_sprockets
			Sprockets.append_path(images_path)
			Sprockets.append_path(javascripts_path)
			Sprockets.append_path(stylesheets_path)
			Sprockets.append_path(views_path)
		end
	end
end

Pugin.load!

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pugin-0.6.2 lib/pugin.rb