erb_component 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 223e207e1ff4bdd26ad16c9fda8ff8b804506ced105a6cf8242e7c872ba2780d
4
+ data.tar.gz: 318703247572e8a03b39a414287f5c6430fc65c5f4ee33402a79ea479242b4e7
5
+ SHA512:
6
+ metadata.gz: 4d272a5d9824698fbf27fdc85519061f433cb1fc36a1ad27bb3c6723cadc83dbde7bbb0693493a34b17047c7838a5f42fbb2e2f308ac5edf292becb7ea049d2d
7
+ data.tar.gz: 5e2f784830f8fc862a1a326f8d6af5dcff7066ece78a161a546db7cec25ec2df7f86489d361b009d5c5f4dcc3447f15d56e29792117a94e69f344228b53362dc
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in erb_component.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Arthur Karganyan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,40 @@
1
+ # ErbComponent
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/erb_component`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'erb_component'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install erb_component
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/erb_component.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/erb_component ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "erb_component"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,28 @@
1
+ require_relative "lib/erb_component/version"
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "erb_component"
5
+ spec.version = ErbComponent::VERSION
6
+ spec.authors = ["Arthur Karganyan"]
7
+ spec.email = ["arthur.karganyan@gmail.com"]
8
+
9
+ spec.summary = "React-style front-end components but for ERB?"
10
+ spec.description = "React-style front-end components but for ERB?"
11
+ spec.homepage = "https://github.com/arthurkarganyan/erb_component"
12
+ spec.license = "MIT"
13
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
14
+
15
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = "https://github.com/arthurkarganyan/erb_component"
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ spec.files = Dir.chdir(File.expand_path("..", __FILE__)) do
23
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
+ end
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+ end
@@ -0,0 +1,3 @@
1
+ require "erb_component/version"
2
+
3
+ autoload :ErbComponent, "erb_component/erb_component"
@@ -0,0 +1,42 @@
1
+ require "erb_component/version"
2
+ require 'erb'
3
+
4
+ class ErbComponent
5
+ class Error < StandardError; end
6
+
7
+ attr_reader :params, :path, :parent
8
+
9
+ def initialize(opts = {})
10
+ @params = opts[:params] || {}
11
+ @path = opts[:path]
12
+ @parent = self.class.superclass == ErbComponent ? nil : self.class.superclass.new(opts)
13
+ end
14
+
15
+ def render
16
+ str = ERB.new(template).result(binding)
17
+ parent ? parent.render.gsub("{{VIEW}}", str) : str
18
+ end
19
+
20
+ def self.render(opts = {})
21
+ new(opts).render
22
+ end
23
+
24
+ def template
25
+ a = "components/#{self.class.name.underscore}.erb"
26
+ return File.read a if File.exists? a
27
+ fail 'not found'
28
+ end
29
+
30
+ def method_missing(m, *args, &block)
31
+ possible_const = "#{self.class}::#{m}"
32
+ clazz = if Kernel.const_defined?(possible_const)
33
+ Kernel.const_get possible_const
34
+ else
35
+ Kernel.const_get m.to_s
36
+ end
37
+ opts = {path: path, params: params}
38
+ opts.merge!(args[0]) if args.size > 0
39
+ component = clazz.new(opts)
40
+ component.render
41
+ end
42
+ end
@@ -0,0 +1,3 @@
1
+ class ErbComponent
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,57 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: erb_component
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Arthur Karganyan
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-11-18 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: React-style front-end components but for ERB?
14
+ email:
15
+ - arthur.karganyan@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".gitignore"
21
+ - Gemfile
22
+ - LICENSE.txt
23
+ - README.md
24
+ - Rakefile
25
+ - bin/erb_component
26
+ - erb_component.gemspec
27
+ - lib/erb_component.rb
28
+ - lib/erb_component/erb_component.rb
29
+ - lib/erb_component/version.rb
30
+ homepage: https://github.com/arthurkarganyan/erb_component
31
+ licenses:
32
+ - MIT
33
+ metadata:
34
+ allowed_push_host: https://rubygems.org
35
+ homepage_uri: https://github.com/arthurkarganyan/erb_component
36
+ source_code_uri: https://github.com/arthurkarganyan/erb_component
37
+ post_install_message:
38
+ rdoc_options: []
39
+ require_paths:
40
+ - lib
41
+ required_ruby_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: 2.3.0
46
+ required_rubygems_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ requirements: []
52
+ rubyforge_project:
53
+ rubygems_version: 2.7.6
54
+ signing_key:
55
+ specification_version: 4
56
+ summary: React-style front-end components but for ERB?
57
+ test_files: []