Class: Docks::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/docks/build.rb

Defined Under Namespace

Classes: Config

Class Method Summary collapse

Class Method Details

.add_assets(assets, options) ⇒ Object



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/docks/build.rb', line 129

def self.add_assets(assets, options)
  root = /#{Regexp.escape(options.fetch(:root, "").to_s)}\/?/
  copy_to = case options[:type]
            when :styles then Docks.config.root + ASSETS_DIR + Docks.config.asset_folders.styles
            when :scripts then Docks.config.root + ASSETS_DIR + Docks.config.asset_folders.scripts
            when :templates then Docks.config.templates
            end

  [assets].flatten.each do |asset|
    asset = Pathname.new(asset)
    destination_file = copy_to + asset.to_s.sub(root, "")
    relative_path = destination_file.relative_path_from(Docks.config.root)
    exists = destination_file.exist?

    next if exists && FileUtils.identical?(asset, destination_file)

    destination_dir = destination_file.dirname
    FileUtils.mkdir_p(destination_dir)
    FileUtils.cp(asset, destination_dir)
    Messenger.file(relative_path, exists ? :updated : :created)
  end
end

.buildObject



96
97
98
99
100
101
102
103
104
# File 'lib/docks/build.rb', line 96

def self.build
  prepare_destination
  Messenger.file_header("Assets:")
  copy_theme_assets

  Messenger.file_header("Pages:")
  rendered_patterns = render_pattern_library
  remove_unused_directories(rendered_patterns)
end

.optionsObject



127
# File 'lib/docks/build.rb', line 127

def self.options; @options end

.parse(options = {}) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/docks/build.rb', line 81

def self.parse(options = {})
  cache = Cache.new
  cache.clear if options.fetch(:clear_cache, false)

  Grouper.group(Docks.config.sources).each do |identifier, group|
    if Cache.cached?(group)
      cache.no_update(identifier)
    else
      cache << Parser.parse(group)
    end
  end

  cache.dump
end

.setup(options) ⇒ Object



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/docks/build.rb', line 106

def self.setup(options)
  @options = options = OpenStruct.new(options)
  @assets_dir = File.join(Dir.pwd, Docks::ASSETS_DIR)
  FileUtils.mkdir_p(@assets_dir)

  if options.theme
    theme = Themes.for(options.theme)
    theme.configure(Docks.config) if theme && theme.respond_to?(:configure)
  end

  if Dir[CONFIG_FILE].empty?
    setup_config
  end

  Docks.configure
  Docks.config.root = Pathname.pwd

  return unless Docks.config.theme && Docks.config.theme.respond_to?(:setup)
  Docks.config.theme.setup(self)
end