componentize 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 07f13b0a8419f2b8b8d410543721092ac6bb83fb
4
+ data.tar.gz: 871e45a645e2e4e69f4cfc2b536e0d1b48ebce8f
5
+ SHA512:
6
+ metadata.gz: d88eef098d5b091bf07628aa245f3a0786e68b0f5d405241efdc4bb5f6c7ec1836de55df33d747f33efca5c3ac8a55fc6912f7004c80bfa27c9294482901a784
7
+ data.tar.gz: 9b59116198d980fb673d1db4ad1866d1a174491c73986055a967de470e8cba3559e3b897dcd4eb5780eb19be7e679b311f6c166ae7eddb64aaf17cbf7e992a5d
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.gem
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in componentize.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Kyle Shevlin
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.
@@ -0,0 +1,73 @@
1
+ # Componentize
2
+
3
+ Rails generator for inline and block level "components". Generates a view file, SCSS partial, and adds the right `@import` to the `base.scss` file.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'componentize'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ ```
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+
21
+ ```
22
+ $ gem install componentize
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ ```
28
+ rails generate component <NAME> [options]
29
+ ```
30
+
31
+ ## Options
32
+
33
+ | Option | Type | Description | Default Value |
34
+ |---|---|---|---|
35
+ | --format | String | File extension format. Can be `erb`, `slim`, or `haml` | `erb` |
36
+ | --block | Boolean | Whether component is inline or block level | `false` |
37
+
38
+ ## Full Example
39
+
40
+ ```
41
+ rails generate component my-block-component --format slim --block
42
+ ```
43
+
44
+ ## Including Components in Views
45
+
46
+ Inline component:
47
+
48
+ ```erb
49
+ <%= render 'my_component', foo: 'bar' %>
50
+ ```
51
+
52
+ Block component:
53
+
54
+ ```erb
55
+ <%= render layout: 'my_section', locals: { foo: 'bar' } do %>
56
+ <%# Content goes here and is rendered in the block's yield %>
57
+ <% end %>
58
+ ```
59
+
60
+ ## Development
61
+
62
+ 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.
63
+
64
+ 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).
65
+
66
+ ## Contributing
67
+
68
+ Bug reports and pull requests are welcome on GitHub at https://github.com/kyleshevlin/componentize.
69
+
70
+ ## License
71
+
72
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
73
+
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "componentize"
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
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'componentize/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "componentize"
8
+ spec.version = Componentize::VERSION
9
+ spec.authors = ["Kyle Shevlin"]
10
+ spec.email = ["kyle.a.shevlin@gmail.com"]
11
+ spec.summary = %q{Generator for inline and block level Rails components. Similar to Ember's component generator.}
12
+ spec.description = %q{Generator for inline and block level Rails components. Similar to Ember's component generator.}
13
+ spec.homepage = "https://github.com/kyleshevlin/componentize"
14
+ spec.license = "MIT"
15
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
16
+ spec.bindir = "exe"
17
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.12"
21
+ spec.add_development_dependency "rake", "~> 10.0"
22
+ spec.add_development_dependency "rails", ">= 3.1"
23
+ end
@@ -0,0 +1,5 @@
1
+ require "componentize/engine"
2
+ require "componentize/version"
3
+
4
+ module Componentize
5
+ end
@@ -0,0 +1,4 @@
1
+ module Componentize
2
+ class Engine < ::Rails::Engine
3
+ end
4
+ end
@@ -0,0 +1,3 @@
1
+ module Componentize
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,19 @@
1
+ Description:
2
+ Generates a Slim and SCSS file for your component and adds the file import to base.scss
3
+
4
+ Example:
5
+ rails generate component my-component
6
+
7
+ This will create:
8
+ app/assets/stylesheets/blocks/_my_component.scss
9
+ app/views/application/_my_component.html.erb
10
+
11
+ And this will add the following to base.scss:
12
+ @import 'blocks/my_component';
13
+
14
+ Options
15
+ --block, Boolean, default: false; Will designate this component as a block component and add
16
+ a yield to the view file.
17
+
18
+ --format, String, default: 'erb'; Will set the extension format for the view file. Acceptable
19
+ options are: 'erb', 'slim', and 'haml'
@@ -0,0 +1,52 @@
1
+ require 'rails/generators/named_base'
2
+ require 'fileutils'
3
+
4
+ class ComponentGenerator < Rails::Generators::NamedBase
5
+ source_root File.expand_path('../templates', __FILE__)
6
+
7
+ class_option :format, type: :string, default: 'erb'
8
+ class_option :block, type: :boolean, default: false
9
+
10
+ def set_component_name_variable
11
+ @component_name = component_name
12
+ end
13
+
14
+ def set_extension
15
+ @extension = validate_extension_format(options[:format])
16
+ end
17
+
18
+ def create_component_files
19
+ create_view_file
20
+ create_sass_file
21
+ update_base_imports_file
22
+ end
23
+
24
+ private
25
+
26
+ def component_name
27
+ file_name.gsub(/-/, '_')
28
+ end
29
+
30
+ def validate_extension_format(format)
31
+ whitelist = ['erb', 'slim', 'haml']
32
+ return whitelist.include?(format) ? format : 'erb'
33
+ end
34
+
35
+ def create_view_file
36
+ created_file_name = "app/views/application/_#{component_name}.html.#{@extension}"
37
+ template_type = options[:block] ? 'block_template' : 'inline_template'
38
+
39
+ template "#{@extension}/#{template_type}.html.#{@extension}", created_file_name
40
+ end
41
+
42
+ def create_sass_file
43
+ style_dir = options[:block] ? 'sections' : 'blocks'
44
+ template 'component_stylesheet_template.scss', "app/assets/stylesheets/#{style_dir}/_#{component_name}.scss"
45
+ end
46
+
47
+ def update_base_imports_file
48
+ FileUtils.touch('app/assets/stylesheets/base.scss')
49
+ style_dir = options[:block] ? 'sections' : 'blocks'
50
+ append_to_file 'app/assets/stylesheets/base.scss', "@import '#{style_dir}/#{component_name}';\n"
51
+ end
52
+ end
@@ -0,0 +1,7 @@
1
+ //////////////////////////////
2
+ // <%= @component_name %>
3
+ //////////////////////////////
4
+
5
+ .<%= @component_name %> {
6
+
7
+ }
@@ -0,0 +1,8 @@
1
+ <%%
2
+ # Ruby code goes here
3
+ %>
4
+
5
+ <div class="<%= @component_name %>">
6
+ <!-- Markup goes here -->
7
+ <%%= yield %>
8
+ </div>
@@ -0,0 +1,7 @@
1
+ <%%
2
+ # Ruby code goes here
3
+ %>
4
+
5
+ <div class="<%= @component_name %>">
6
+ <!-- Markup goes here -->
7
+ </div>
@@ -0,0 +1,5 @@
1
+ - # Ruby code goes here
2
+
3
+ .<%= @component_name %>
4
+ / Markup goes here
5
+ = yield
@@ -0,0 +1,4 @@
1
+ - # Ruby code goes here
2
+
3
+ .<%= @component_name %>
4
+ / Markup goes here
@@ -0,0 +1,6 @@
1
+ ruby:
2
+ # Ruby code goes here
3
+
4
+ .<%= @component_name %>
5
+ / Markup goes here
6
+ == yield
@@ -0,0 +1,5 @@
1
+ ruby:
2
+ # Ruby code goes here
3
+
4
+ .<%= @component_name %>
5
+ / Markup goes here
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: componentize
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Kyle Shevlin
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-06-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rails
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '3.1'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '3.1'
55
+ description: Generator for inline and block level Rails components. Similar to Ember's
56
+ component generator.
57
+ email:
58
+ - kyle.a.shevlin@gmail.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - bin/console
69
+ - bin/setup
70
+ - componentize.gemspec
71
+ - lib/componentize.rb
72
+ - lib/componentize/engine.rb
73
+ - lib/componentize/version.rb
74
+ - lib/generators/component/USAGE
75
+ - lib/generators/component/component_generator.rb
76
+ - lib/generators/component/templates/component_stylesheet_template.scss
77
+ - lib/generators/component/templates/erb/block_template.html.erb
78
+ - lib/generators/component/templates/erb/inline_template.html.erb
79
+ - lib/generators/component/templates/haml/block_template.html.haml
80
+ - lib/generators/component/templates/haml/inline_template.html.haml
81
+ - lib/generators/component/templates/slim/block_template.html.slim
82
+ - lib/generators/component/templates/slim/inline_template.html.slim
83
+ homepage: https://github.com/kyleshevlin/componentize
84
+ licenses:
85
+ - MIT
86
+ metadata: {}
87
+ post_install_message:
88
+ rdoc_options: []
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ requirements: []
102
+ rubyforge_project:
103
+ rubygems_version: 2.4.8
104
+ signing_key:
105
+ specification_version: 4
106
+ summary: Generator for inline and block level Rails components. Similar to Ember's
107
+ component generator.
108
+ test_files: []