Module: SparkEngine

Extended by:
SparkEngine
Included in:
SparkEngine
Defined in:
lib/spark_engine/helpers/block_helper.rb,
lib/spark_engine.rb,
lib/spark_engine/data.rb,
lib/spark_engine/assets.rb,
lib/spark_engine/plugin.rb,
lib/spark_engine/command.rb,
lib/spark_engine/version.rb,
lib/spark_engine/scaffold.rb,
lib/spark_engine/middleware.rb,
lib/spark_engine/command/npm.rb,
lib/spark_engine/command/help.rb,
lib/spark_engine/sass/importer.rb,
lib/spark_engine/plugin/assets/svgs.rb,
lib/spark_engine/plugin/assets/asset.rb,
lib/spark_engine/helpers/asset_helpers.rb,
lib/spark_engine/helpers/layout_helpers.rb,
lib/spark_engine/plugin/assets/javascripts.rb,
lib/spark_engine/plugin/assets/stylesheets.rb

Overview

From: github.com/nachokb/block_helpers Inlined becuase the project is inactive and current forks aren’t published to RubyGems.org

Defined Under Namespace

Modules: Assets, Command, Data, Help, Helpers, NPM Classes: BlockHelper, Importer, Plugin, Scaffold, StaticAssets

Constant Summary collapse

VERSION =
"1.2.17"

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#pluginObject

Returns the value of attribute plugin.



14
15
16
# File 'lib/spark_engine.rb', line 14

def plugin
  @plugin
end

Instance Method Details

#at_gem_root?Boolean

Returns:

  • (Boolean)


81
82
83
# File 'lib/spark_engine.rb', line 81

def at_gem_root?
  !Dir['*.gemspec'].empty?
end

#at_rails_root?Boolean

Returns:

  • (Boolean)


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

def at_rails_root?
  File.exist?("bin/rails")
end

#dataObject



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

def data
  if production?
    @data ||= SparkEngine::Data.read
  else
    SparkEngine::Data.read
  end
end

#gem_pathObject



85
86
87
88
89
90
91
# File 'lib/spark_engine.rb', line 85

def gem_path
  if at_gem_root?
    Dir.pwd
  elsif at_rails_root?
    "../"
  end
end

#load_helpersObject



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

def load_helpers
  require "spark_engine/helpers/asset_helpers"
  require "spark_engine/helpers/layout_helpers"

  SparkEngine::Helpers.constants.each do |c|
    helper = SparkEngine::Helpers.const_get(c)
    ActionView::Base.send :include, helper if defined? ActionView::Base
  end
end

#load_pluginObject



74
75
76
77
78
79
# File 'lib/spark_engine.rb', line 74

def load_plugin
  plugin || if spec = plugin_spec
    require spec.name unless spec.name == 'spark_engine'
    return plugin
  end
end

#patch_railsObject



40
41
42
# File 'lib/spark_engine.rb', line 40

def patch_rails
  load_helpers
end

#plugin_gemspecObject



58
59
60
61
62
63
# File 'lib/spark_engine.rb', line 58

def plugin_gemspec
  if gem_path
    path = File.join(gem_path, "*.gemspec")
    Dir[path].first
  end
end

#plugin_specObject



65
66
67
68
69
70
71
72
# File 'lib/spark_engine.rb', line 65

def plugin_spec
  @plugin_spec ||= begin
    if file = plugin_gemspec
      spec = Gem::Specification.load(file)
      spec if spec.name != 'spark_engine'
    end
  end
end

#production?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/spark_engine.rb', line 16

def production?
  ENV['CI'] || ENV['RAILS_ENV'] == 'production' || ( defined?(Command) && Command.production? )
end

#rails_path(sub = nil) ⇒ Object



93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/spark_engine.rb', line 93

def rails_path(sub=nil)
  path = if at_rails_root?
    Dir.pwd
  else
    dir = Dir["**/bin/rails"]
    if !dir.empty?
      dir.first.split('/').first
    end
  end
  path = File.join(path, sub) if sub
  path
end

#register(plugin_module, options = {}, &block) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/spark_engine.rb', line 32

def register(plugin_module, options={}, &block)
  @plugin = plugin_module.new(options)
  if defined? Rails
    @plugin.create_engine(&block)
    patch_rails
  end
end