Sha256: ba796abd4e742651e12626cb0cb092500152acd3b6e8ec8a65d6027cdfca9132

Contents?: true

Size: 1.12 KB

Versions: 15

Compression:

Stored size: 1.12 KB

Contents

# encoding: utf-8

require 'epuber-stylus'


module Epuber
  class Compiler
    module FileTypes
      require_relative 'source_file'

      class StylusFile < SourceFile
        # @param [Compiler::CompilationContext] compilation_context
        #
        def process(compilation_context)
          return if destination_file_up_to_date?

          Stylus.define('__is_debug', !compilation_context.release_build)
          Stylus.define('__is_verbose_mode', compilation_context.verbose?)
          Stylus.define('__target_name', compilation_context.target.name)
          Stylus.define('__book_title', compilation_context.book.title)
          Stylus.define('__const', compilation_context.target.constants)

          write_compiled(Stylus.compile(File.new(abs_source_path)))

          update_metadata!
        end

        def find_dependencies
          self.class.find_imports(File.read(abs_source_path))
        end

        # @return [Array<String>]
        #
        def self.find_imports(content)
          content.to_enum(:scan, /^\s*@import ("|')([^'"]*)("|')/).map { Regexp.last_match[2] }
        end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
epuber-0.6.0 lib/epuber/compiler/file_types/stylus_file.rb
epuber-0.5.7 lib/epuber/compiler/file_types/stylus_file.rb
epuber-0.5.6 lib/epuber/compiler/file_types/stylus_file.rb
epuber-0.5.5 lib/epuber/compiler/file_types/stylus_file.rb
epuber-0.5.4 lib/epuber/compiler/file_types/stylus_file.rb
epuber-0.5.3 lib/epuber/compiler/file_types/stylus_file.rb
epuber-0.5.2 lib/epuber/compiler/file_types/stylus_file.rb
epuber-0.5.1 lib/epuber/compiler/file_types/stylus_file.rb
epuber-0.5.0 lib/epuber/compiler/file_types/stylus_file.rb
epuber-0.5.0.beta.5 lib/epuber/compiler/file_types/stylus_file.rb
epuber-0.5.0.beta.4 lib/epuber/compiler/file_types/stylus_file.rb
epuber-0.5.0.beta.3 lib/epuber/compiler/file_types/stylus_file.rb
epuber-0.5.0.beta.2 lib/epuber/compiler/file_types/stylus_file.rb
epuber-0.5.0.beta lib/epuber/compiler/file_types/stylus_file.rb
epuber-0.4.0 lib/epuber/compiler/file_types/stylus_file.rb