atomic_assets 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 35dbe7d9e03f577cab1e3cd74ea37b6745ba57e8
4
- data.tar.gz: b04fbd65a48dc6d7966564d57122a34b69d2e21d
3
+ metadata.gz: 9282dbd2270b21313b2a119723945138d68ff916
4
+ data.tar.gz: 5c97958fc460d611ac706fd010e9143189088910
5
5
  SHA512:
6
- metadata.gz: b6bdb2cdc9c2ab90c6c0e558f92709a1928d75ed1c60d432a5355affbdaa648c2b959632dad58278209cbe20f84f8a28400bf9aea0c767049309af0f5ce62cd9
7
- data.tar.gz: 2c3f740d7ac07dd2257b04eb15e5ec0ce7c40779b7d9c4374a33c7e77ac9803dc229321571106284ce030d65e2ef2741395aabd68a12805383ebdab33bfb20f3
6
+ metadata.gz: 43284631249e8939bfc91324a0d2db32c0205cf281e8c745e3c7b57d30f70b582f5709f66d494bfa83fb70934cbe5d4721187f1389dba484f3566a26641aed92
7
+ data.tar.gz: 8951815aadf85ac246e2836a888c4f38285f77d00143bb161789ea46d725debae65fa55af48c7a42fe856ef43c6953da947bfc21bef42681c4bc3ea62dd86cd7
@@ -0,0 +1,15 @@
1
+ require 'draper'
2
+
3
+ module AtomicAssets
4
+ class Component
5
+ include Draper::ViewHelpers
6
+
7
+ include Deserialize
8
+ include Helper
9
+ include Initialize
10
+ include Render
11
+ include Serialize
12
+
13
+ attr_accessor :options
14
+ end
15
+ end
@@ -0,0 +1,22 @@
1
+ require 'yaml'
2
+
3
+ module AtomicAssets
4
+ module Deserialize
5
+ def self.included(base)
6
+ base.extend(ClassMethods)
7
+ end
8
+
9
+ module ClassMethods
10
+ def from_yaml(yaml_string)
11
+ preload_components(yaml_string)
12
+ YAML.load(yaml_string)
13
+ end
14
+
15
+ private
16
+
17
+ def preload_components(yaml_string)
18
+ yaml_string.scan(/(?<=\!ruby\/object:)\w+/).uniq.map(&:constantize)
19
+ end
20
+ end
21
+ end
22
+ end
@@ -1,14 +1,21 @@
1
1
  module AtomicAssets
2
2
  module Helper
3
3
  def component(name, options = {}, &block)
4
- if block_given?
5
- if block.arity == 0
6
- options[:content] = capture(&block)
7
- else
8
- block.call(options)
9
- end
10
- end
11
- render partial: "components/#{name}", locals: { options: options }
4
+ component_class(name).new(options, &block)
5
+ end
6
+
7
+ private
8
+
9
+ def build_component_class(name)
10
+ klass = Class.new(AtomicAssets::Component)
11
+ Object.const_set(name, klass)
12
+ end
13
+
14
+ def component_class(name)
15
+ klass = "#{name}_component".classify
16
+ klass.constantize
17
+ rescue NameError
18
+ build_component_class(klass)
12
19
  end
13
20
  end
14
21
  end
@@ -0,0 +1,15 @@
1
+ module AtomicAssets
2
+ module Initialize
3
+ def initialize(options = {}, &block)
4
+ raise ArgumentError unless options.is_a? Hash
5
+ capture_block(options, &block) if block_given?
6
+ @options = options
7
+ end
8
+
9
+ private
10
+
11
+ def capture_block(options, &block)
12
+ options.merge!(content: h.capture(&block))
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,19 @@
1
+ module AtomicAssets
2
+ class Railtie < Rails::Railtie
3
+ initializer "atomic_assets.setup_autoload_path" do |app|
4
+ app.config.autoload_paths += %w(app/components)
5
+ end
6
+
7
+ initializer "atomic_assets.setup_action_controller" do |app|
8
+ ActiveSupport.on_load :action_controller do
9
+ include AtomicAssets::Helper
10
+ end
11
+ end
12
+
13
+ initializer "atomic_assets.setup_action_view" do |app|
14
+ ActiveSupport.on_load :action_view do
15
+ include AtomicAssets::Helper
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,41 @@
1
+ module AtomicAssets
2
+ module Render
3
+ COMPONENT_PATH = 'components'
4
+ PARTIALS_DEPRECATED = 'Using view partial component templates will be removed in atomic_assets-0.1.0. Please remove leading underscores from your template file names.'
5
+
6
+ def render
7
+ render_template
8
+ rescue ActionView::MissingTemplate => error
9
+ raise error unless error.path == component_name
10
+ render_partial
11
+ end
12
+
13
+ def template_path
14
+ File.join(COMPONENT_PATH, component_name)
15
+ end
16
+
17
+ def to_s
18
+ render
19
+ end
20
+
21
+ private
22
+
23
+ def component_name
24
+ self.class.name.underscore.gsub(/_component$/, '')
25
+ end
26
+
27
+ def local_options
28
+ options.merge(options: options)
29
+ end
30
+
31
+ def render_partial
32
+ output = h.render(partial: template_path, locals: local_options)
33
+ ActiveSupport::Deprecation.warn(PARTIALS_DEPRECATED)
34
+ output
35
+ end
36
+
37
+ def render_template
38
+ h.render(template: template_path, locals: local_options)
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,9 @@
1
+ require 'yaml'
2
+
3
+ module AtomicAssets
4
+ module Serialize
5
+ def to_yaml
6
+ YAML.dump(self)
7
+ end
8
+ end
9
+ end
data/lib/atomic_assets.rb CHANGED
@@ -1,5 +1,8 @@
1
+ require 'atomic_assets/deserialize'
1
2
  require 'atomic_assets/helper'
3
+ require 'atomic_assets/initialize'
4
+ require 'atomic_assets/render'
5
+ require 'atomic_assets/serialize'
6
+ require 'atomic_assets/railtie' if defined?(Rails)
2
7
 
3
- module ApplicationHelper
4
- include AtomicAssets::Helper
5
- end
8
+ require 'atomic_assets/component'
metadata CHANGED
@@ -1,15 +1,85 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: atomic_assets
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Don Humphreys
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-07 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2015-06-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: draper
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec-core
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec-expectations
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec-mocks
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.3'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec-support
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.3'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.3'
13
83
  description: Organize, style, and consume atomically designed assets in Ruby on Rails.
14
84
  email: dhumphreys88@gmail.com
15
85
  executables: []
@@ -17,8 +87,14 @@ extensions: []
17
87
  extra_rdoc_files: []
18
88
  files:
19
89
  - lib/atomic_assets.rb
90
+ - lib/atomic_assets/component.rb
91
+ - lib/atomic_assets/deserialize.rb
20
92
  - lib/atomic_assets/helper.rb
21
- homepage:
93
+ - lib/atomic_assets/initialize.rb
94
+ - lib/atomic_assets/railtie.rb
95
+ - lib/atomic_assets/render.rb
96
+ - lib/atomic_assets/serialize.rb
97
+ homepage: http://github.com/dhumphreys/atomic_assets
22
98
  licenses: []
23
99
  metadata: {}
24
100
  post_install_message:
@@ -37,9 +113,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
37
113
  version: '0'
38
114
  requirements: []
39
115
  rubyforge_project:
40
- rubygems_version: 2.2.2
116
+ rubygems_version: 2.4.5
41
117
  signing_key:
42
118
  specification_version: 4
43
119
  summary: Atomic Assets
44
120
  test_files: []
45
- has_rdoc: