Module: RailsBuild

Defined in:
lib/rails_build.rb,
lib/rails_build/_lib.rb

Defined Under Namespace

Classes: Assassin, Configuration

Constant Summary collapse

VERSION =
'2.4.5'

Class Method Summary collapse

Class Method Details

.configObject



58
59
60
# File 'lib/rails_build.rb', line 58

def RailsBuild.config
  RailsBuild.configuration
end

.config_dump_pathObject



43
44
45
46
47
48
49
50
51
52
# File 'lib/rails_build.rb', line 43

def RailsBuild.config_dump_path
  case
    when ENV['RAILS_BUILD_CONFIG_DUMP']
      ENV['RAILS_BUILD_CONFIG_DUMP']
    when defined?(Rails)
      Rails.application.root.join('tmp/rails_build.json')
    else
      './tmp/rails_build.json'
  end.to_s
end

.config_pathObject



32
33
34
35
36
37
38
39
40
41
# File 'lib/rails_build.rb', line 32

def RailsBuild.config_path
  case
    when ENV['RAILS_BUILD_CONFIG']
      ENV['RAILS_BUILD_CONFIG']
    when defined?(Rails)
      Rails.application.root.join('config/rails_build.rb')
    else
      './config/rails_build.rb'
  end.to_s
end

.configurationObject



54
55
56
# File 'lib/rails_build.rb', line 54

def RailsBuild.configuration
  @configuration ||= Configuration.new
end

.configure(&block) ⇒ Object



6
7
8
# File 'lib/rails_build.rb', line 6

def RailsBuild.configure(&block)
  @configure = block
end

.dependenciesObject



39
40
41
42
43
44
45
46
47
# File 'lib/rails_build/_lib.rb', line 39

def dependencies
  {
    'parallel' =>
      ['parallel', '~> 1.26'],

    'getoptlong' =>
      ['getoptlong', '~> 0.2'],
  }
end

.descriptionObject



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/rails_build/_lib.rb', line 19

def description
  <<~____
    rails_build is a very small, fast enough, static site generator built
    on top of the rails you already know and love.

    it's been in production usage for close to a decade but i've been too
    busy to relase it until now.  also, #wtf is up with javascript land?!

    it has a small set of dependencies, namely the `parallel` gem, and
    requires absolutely minimal configuration.  it should be pretty darn
    self explanatory:
  ____
end

.dump_config!(path: config_path, dump: config_dump_path) ⇒ Object



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

def RailsBuild.dump_config!(path: config_path, dump: config_dump_path)
  config = RailsBuild.load_config!(path:)

  json = JSON.pretty_generate(config.as_json)

  dirname = File.dirname(dump)
  FileUtils.mkdir_p(dirname)
  IO.binwrite(dump, json)

  dump
end

.libdir(*args, &block) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/rails_build/_lib.rb', line 49

def libdir(*args, &block)
  @libdir ||= File.dirname(File.expand_path(__FILE__))
  args.empty? ? @libdir : File.join(@libdir, *args)
ensure
  if block
    begin
      $LOAD_PATH.unshift(@libdir)
      block.call
    ensure
      $LOAD_PATH.shift
    end
  end
end

.libsObject



33
34
35
36
37
# File 'lib/rails_build/_lib.rb', line 33

def libs
  %w[
    fileutils pathname thread socket timeout time uri etc securerandom logger json tempfile net/http
  ]
end

.load(*libs) ⇒ Object



63
64
65
66
# File 'lib/rails_build/_lib.rb', line 63

def load(*libs)
  libs = libs.join(' ').scan(/[^\s+]+/)
  libdir { libs.each { |lib| Kernel.load(lib) } }
end

.load_config!(path: config_path) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/rails_build.rb', line 22

def RailsBuild.load_config!(path: config_path)
  Kernel.load(path)

  if @configure
    @configure.call(RailsBuild.configuration)
  end

  RailsBuild.configuration
end

.load_dependencies!Object



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/rails_build/_lib.rb', line 68

def load_dependencies!
  libs.each do |lib|
    require lib
  end

  begin
    require 'rubygems'
  rescue LoadError
    nil
  end

  has_rubygems = defined?(gem)

  dependencies.each do |lib, dependency|
    gem(*dependency) if has_rubygems
    require(lib)
  end
end

.repoObject



9
10
11
# File 'lib/rails_build/_lib.rb', line 9

def repo
  'https://github.com/ahoward/rails_build'
end

.summaryObject



13
14
15
16
17
# File 'lib/rails_build/_lib.rb', line 13

def summary
  <<~____
    a small, simple, bullet proof, and fast enough static site generator built on top of the rails you already know and love
  ____
end

.versionObject



5
6
7
# File 'lib/rails_build/_lib.rb', line 5

def version
  VERSION
end