Sha256: 313a220e76df2d104c81b0ea206f18985539e795e6c1d8bb1d1c97e595dcfdf7

Contents?: true

Size: 1.46 KB

Versions: 5

Compression:

Stored size: 1.46 KB

Contents

module Middleman
  module Gdpr
    class Extension < Extension
      # def initialize(app, options_hash={}, &block)
      #   super
      # end

      def after_configuration
        raise "\e[91mGDPR: Sprockets extension not activated. Please activate Sprockets in config.rb\e[39m" if sprockets.blank?
        raise "\e[91mGDPR: I18n extension not activated. Please activate I18n in config.rb\e[39m" if i18n.blank?

        ['source/stylesheets', 'source/javascripts', 'node_modules'].each do |path|
          sprockets.environment.append_path root + path
        end

        I18n.load_path.concat Dir[root + 'locales/*.yml']
      end

      def root
        self.class.root
      end

      helpers do
        def gdpr(partial)
          template = Middleman::Gdpr::Extension.template_for partial
          raise "GDPR: \"#{partial}\" partial doesn't exist" if template.blank?
          return ERB.new(template).result binding
        end
      end

      class << self
        def root
          Pathname.new(__dir__) + '../..'
        end

        def template_for(partial)
          partial = File.basename(partial.to_s)
            .sub(/\A_/, '')
            .sub(/\.(html|erb|html\.erb)\z/, '')

          path = root + "source/gdpr/_#{partial}.html.erb"

          return File.read path if File.exists? path
        end
      end

      private

      def sprockets
        @app.extensions[:sprockets]
      end

      def i18n
        @app.extensions[:i18n]
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
middleman-gdpr-1.1.0 lib/middleman-gdpr/extension.rb
middleman-gdpr-1.0.1 lib/middleman-gdpr/extension.rb
middleman-gdpr-1.0.0 lib/middleman-gdpr/extension.rb
middleman-gdpr-0.2.2 lib/middleman-gdpr/extension.rb
middleman-gdpr-0.2.1 lib/middleman-gdpr/extension.rb