Module: SparkEngine

Extended by:
SparkEngine
Included in:
SparkEngine
Defined in:
lib/spark_engine.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/config_data.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

Defined Under Namespace

Modules: Assets, Command, ConfigData, Help, Helpers, NPM, SassParser Classes: Importer, Plugin, Scaffold, StaticAssets

Constant Summary collapse

VERSION =
"1.2.1"

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)


78
79
80
# File 'lib/spark_engine.rb', line 78

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

#at_rails_root?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/spark_engine.rb', line 51

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

#config_dataObject



25
26
27
# File 'lib/spark_engine.rb', line 25

def config_data
  SparkEngine::ConfigData.read(SparkEngine.plugin.root, Rails.root)
end

#gem_pathObject



82
83
84
85
86
87
88
# File 'lib/spark_engine.rb', line 82

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

#load_helpersObject



41
42
43
44
45
46
47
48
49
# File 'lib/spark_engine.rb', line 41

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



71
72
73
74
75
76
# File 'lib/spark_engine.rb', line 71

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

#patch_railsObject



37
38
39
# File 'lib/spark_engine.rb', line 37

def patch_rails
  load_helpers
end

#plugin_gemspecObject



55
56
57
58
59
60
# File 'lib/spark_engine.rb', line 55

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

#plugin_specObject



62
63
64
65
66
67
68
69
# File 'lib/spark_engine.rb', line 62

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)


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

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

#rails_path(sub = nil) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/spark_engine.rb', line 90

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



29
30
31
32
33
34
35
# File 'lib/spark_engine.rb', line 29

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