rafters 0.1.3 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ab336dc74cbb2a6920011c0f5b8db8d9f7dff797
4
- data.tar.gz: a8bfe2a5683ddbc020d8cde32f06af32e00b3f34
3
+ metadata.gz: 6eda33be9a4b9d6483e2ca5ab9cca57f42900f31
4
+ data.tar.gz: ee6926c5bb02bc6fda0884bba1a917040e072371
5
5
  SHA512:
6
- metadata.gz: e3fcf05f358dff0fc5c5addfa278716b181dd801b3bab36a77225b525d369b3800d487b553d4fcdf0c66cb76acc55f6aa9b47ffeca5624eeb264748ac0c4a997
7
- data.tar.gz: 6e2e5dd6e037c87d3429bc330d32087129b3347e6f10a99282e9134d346a43728bc0ff605f476c1fd1e411fe91598f24654c9d375113623e69995ceba5b5e9e6
6
+ metadata.gz: 37924228164a3e2507c090fd4b4d5200db0e95fd33b299bdf6b3f0f0f090636190b06c66f09dc3135c0e3b0bdc50755b2473bc6d192d87ade571f454c948ef11
7
+ data.tar.gz: 9a2ecc6cd6ffc2d08aa4105e365b6673b2a2b45796bc210563ead3d78e5b626b8842f64a30383e59760474b82af73983e5e2b992ff9aae59a5af6b43d0c6205c
@@ -11,8 +11,9 @@ module Rafters::Component
11
11
  @settings = settings
12
12
  end
13
13
 
14
- def name
15
- self.class.name.underscore
14
+ def name(without_postfix = false)
15
+ _name = self.class.name.underscore
16
+ without_postfix ? _name.gsub(/_component/, '') : _name
16
17
  end
17
18
 
18
19
  def identifier
@@ -27,18 +28,38 @@ module Rafters::Component
27
28
  end
28
29
  end
29
30
 
31
+ def source
32
+ @source ||= "#{name(true)}_#{settings.source}_source".camelize.constantize.new(self)
33
+ end
34
+
30
35
  def attributes
31
36
  return {} if self.class._attributes.nil?
32
37
 
33
38
  @_attributes ||= Hashie::Mash.new.tap do |_attributes|
34
- self.class._attributes.each do |name|
39
+ (self.class._attributes || []).each do |name|
35
40
  _attributes[name] = send(name)
36
41
  end
37
42
  end
38
43
  end
39
44
 
40
45
  def settings
41
- @_settings ||= Hashie::Mash.new(@settings.reverse_merge(self.class._defaults || {}))
46
+ @_settings ||= Hashie::Mash.new(@settings.reverse_merge(overrides).reverse_merge(defaults))
47
+ end
48
+
49
+ def defaults
50
+ @_defaults ||= Hashie::Mash.new.tap do |_defaults|
51
+ (self.class._defaults || {}).each do |name, value|
52
+ _defaults[name] = value.is_a?(Proc) ? value.call(self) : value
53
+ end
54
+ end
55
+ end
56
+
57
+ def overrides
58
+ @_overrides ||= Hashie::Mash.new.tap do |_overrides|
59
+ (controller(:params)[name(true)] || {}).each do |name, value|
60
+ _overrides[name] = value
61
+ end
62
+ end
42
63
  end
43
64
 
44
65
  def controller(variable_or_method_name)
@@ -47,7 +68,7 @@ module Rafters::Component
47
68
  elsif @controller.respond_to?(variable_or_method_name, true)
48
69
  @controller.send(variable_or_method_name)
49
70
  else
50
- raise ControllerMethodOrVariableMissing, "#{variable_or_method_name.to_s} not found in #{@controller.class.name}"
71
+ nil
51
72
  end
52
73
  end
53
74
 
@@ -91,7 +112,6 @@ module Rafters::Component
91
112
  end
92
113
  end
93
114
 
94
- class ControllerMethodOrVariableMissing < StandardError; end
95
115
  class SettingRequired < StandardError; end
96
116
  class InvalidSetting < StandardError; end
97
117
  end
@@ -14,6 +14,7 @@ class Rafters::Railtie < Rails::Railtie
14
14
  end
15
15
 
16
16
  initializer "rafters.set_autoload_paths", :before => :set_autoload_paths do |app|
17
+ app.config.autoload_paths += Dir[app.root.join("app", "components", "*", "*/")]
17
18
  app.config.autoload_paths += Dir[app.root.join("app", "components", "*/")]
18
19
  end
19
20
 
@@ -0,0 +1,13 @@
1
+ module Rafters::Source
2
+ extend ActiveSupport::Concern
3
+
4
+ included do
5
+ attr_accessor :component
6
+
7
+ delegate :controller, :settings, to: :component
8
+ end
9
+
10
+ def initialize(component)
11
+ @component = component
12
+ end
13
+ end
@@ -1,3 +1,3 @@
1
1
  module Rafters
2
- VERSION = "0.1.3"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/rafters.rb CHANGED
@@ -10,6 +10,7 @@ module Rafters
10
10
  autoload :Component
11
11
  autoload :ComponentContext
12
12
  autoload :ComponentRenderer
13
+ autoload :Source
13
14
  end
14
15
 
15
16
  def self.setup
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rafters
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Hite
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-10 00:00:00.000000000 Z
11
+ date: 2013-09-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -165,6 +165,7 @@ files:
165
165
  - lib/rafters/component_renderer.rb
166
166
  - lib/rafters/directive_processor.rb
167
167
  - lib/rafters/railtie.rb
168
+ - lib/rafters/source.rb
168
169
  - lib/rafters/version.rb
169
170
  - lib/tasks/rafters_tasks.rake
170
171
  - rafters.gemspec