component_library 1.0.1 → 2.0.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: cd5fe5f7f3c6f41062912135171378483084d10e
4
- data.tar.gz: 3583250c2c8052803fc4a449f54081613b9fe0b6
3
+ metadata.gz: f948028f3babe799c67e8dffd6789092339401db
4
+ data.tar.gz: e2aab31127f0e2de4a06633b5c50fe31755f29e7
5
5
  SHA512:
6
- metadata.gz: 10a1320e93de726c50c01aebc8e832afb628939957d80ed28753b789f2fc8bd76faacc6079089e5263a7d7b32b3a58c7497696a595ceae7d9b89d9355fa18ed8
7
- data.tar.gz: 5f2aacc65111c63f6321a7274b88cb582f3e3d8d23127bb71769d20f58750b1e53e42d241d0c0cf43e2ca58a5c54a8db0b6c257bba314de789fc061c1a8496fb
6
+ metadata.gz: cbdef274f682d103d9c77c12e236fc9ced05fead2ca036d104de9659e8c4c9b976637bdbd6f30308d2054a55dbfc7ae856ae3ad685b3b725a96a49e05b1c9528
7
+ data.tar.gz: da237b9fca36849ffb4f2e7c63d9371299dfa73993a6656ff1bd1f1d611ac32568b9b9f6aa8a524860376981bb18b56588b673d63ea1c5f4f2cddf732f9f3336
data/README.md CHANGED
@@ -24,7 +24,7 @@ And then execute:
24
24
  By default the component library will assume to use the application layout and CSS file (`application.html.erb` & `application.css`), in addition to some basic styles added by the gem itself. If you wish to override this feature and use a different stylesheet, change the root file path, or the url the library routes to, these can be configued inside an initializer.
25
25
 
26
26
  ```
27
- ComponentLibrary.setup do |config|
27
+ ComponentLibrary.configure do |config|
28
28
  config.application_css = "new_application_css"
29
29
  config.root_path = "new_component_library"
30
30
  config.root_directory = "new_view_directory"
@@ -33,6 +33,47 @@ By default the component library will assume to use the application layout and C
33
33
 
34
34
  If you want to use a totally different layout for your component library, simply create a new layout named `component_library.html.erb` in your layouts directory and change there as appropriate.
35
35
 
36
+ ## Multiconfiguration option
37
+
38
+ It is possible to allow multiple instances of a component library to be created - for example if you wanted to use the same components, but test different stylesheets at different urls:
39
+
40
+ ```
41
+ ComponentLibrary.configure do |config|
42
+ config.multiconfigure = [
43
+ {
44
+ root_directory: "theme_components",
45
+ root_path: "theme_1_components",
46
+ application_css: "theme_1_css"
47
+ },
48
+ {
49
+ root_directory: "theme_components",
50
+ root_path: "theme_2_components",
51
+ application_css: "theme_2_css"
52
+ }
53
+ ]
54
+ end
55
+ ```
56
+
57
+ Or if you want entirely different component libraries - for example a library for your public facing site, one for the admin section, and one for another part of your site...:
58
+
59
+ ```
60
+ ComponentLibrary.configure do |config|
61
+ config.multiconfigure = [
62
+ {
63
+ root_directory: "public_components",
64
+ root_path: "public-components",
65
+ application_css: "application_css"
66
+ },
67
+ {
68
+ root_directory: "admin_components",
69
+ root_path: "admin-components",
70
+ application_css: "admin_css"
71
+ },
72
+ ...
73
+ ]
74
+ end
75
+ ```
76
+
36
77
  ## Contributing
37
78
 
38
79
  1. Fork it ( https://github.com/richarcher/component_library/fork )
@@ -1,18 +1,30 @@
1
1
  class LibraryController < ApplicationController
2
+
3
+ before_action :assign_variables
4
+
2
5
  layout "component_library"
3
6
 
4
7
  def index
5
- dir = Dir.glob("#{Rails.root}/app/views/#{ComponentLibrary.root_directory}/**/*.erb").sort
6
- @component_template = 'componentpattern'
7
- @library = Library::Librarian.new(dir, ComponentLibrary.root_directory)
8
+ dir = Dir.glob("#{Rails.root}/app/views/#{@configuration[:root_directory]}/**/*.erb").sort
9
+
10
+ @library = Library::Librarian.new(dir, @configuration[:root_directory])
8
11
  end
9
12
 
10
13
  def show
11
14
  suffix = params[:format] == 'erb' ? ".erb" : "/**/*.erb"
12
- dir = Dir.glob("#{Rails.root}/app/views/#{ComponentLibrary.root_directory}/#{params[:path]}#{suffix}").sort
13
- @component_template = params[:view] == 'isolation' ? 'isolationpattern' : 'componentpattern'
14
- @library = Library::Librarian.new(dir, ComponentLibrary.root_directory, params[:path])
15
+ dir = Dir.glob("#{Rails.root}/app/views/#{@configuration[:root_directory]}/#{params[:path]}#{suffix}").sort
16
+
17
+ @library = Library::Librarian.new(dir, @configuration[:root_directory], params[:path])
18
+
15
19
  raise ActionController::RoutingError.new('Not Found') if @library.components.empty?
16
20
  end
17
21
 
22
+ private
23
+
24
+ def assign_variables
25
+ @root_path = params[:root_path]
26
+ @configuration = ComponentLibrary.configuration.for(@root_path)[0]
27
+ @component_template = params[:view] == 'isolation' ? 'isolationpattern' : 'componentpattern'
28
+ end
29
+
18
30
  end
@@ -2,7 +2,7 @@
2
2
  <html>
3
3
  <head>
4
4
  <title>Component</title>
5
- <%= stylesheet_link_tag ComponentLibrary.stylesheet_path, ComponentLibrary.application_css, media: 'all' %>
5
+ <%= stylesheet_link_tag ComponentLibrary.stylesheet_path, @configuration[:application_css], media: 'all' %>
6
6
  <%= javascript_include_tag ComponentLibrary.javascript_path %>
7
7
  <%= csrf_meta_tags %>
8
8
  <meta name="viewport" content="width=device-width, initial-scale=1">
@@ -2,7 +2,7 @@
2
2
  <% library.components.each do |component| %>
3
3
  <p class="pattern--title">
4
4
  <% component.paths.each do |path| %>
5
- /<%= link_to path[:name], component_path(path[:path]) %>
5
+ /<%= link_to path[:name], '#' %>
6
6
  <% end %>
7
7
  </p>
8
8
  <div class="pattern" id="<%= component.render.parameterize %>">
@@ -2,5 +2,5 @@
2
2
  <% if @library.components.any? %>
3
3
  <%= render partial: @component_template, locals: { library: @library } %>
4
4
  <% else %>
5
- <p>No html components found at <code>/app/view/<%= ComponentLibrary.root_directory %></code></p>
5
+ <p>No html components found at <code>/app/view/<%= ComponentLibrary.configuration.root_directory %></code></p>
6
6
  <% end %>
data/config/routes.rb CHANGED
@@ -1,4 +1,9 @@
1
1
  Rails.application.routes.draw do
2
- get "#{ComponentLibrary.root_path}/", to: 'library#index', as: "components"
3
- get "#{ComponentLibrary.root_path}/*path", to: 'library#show', as: "component"
2
+ clc = ComponentLibrary.configuration
3
+ get ':root_path/', to: 'library#index', constraints: lambda { |request|
4
+ clc.root_paths.any? { |root_path| request.original_fullpath.include?(root_path)}
5
+ }
6
+ get ':root_path/*path', to: 'library#show', constraints: lambda { |request|
7
+ clc.root_paths.any? { |root_path| request.original_fullpath.include?(root_path) }
8
+ }
4
9
  end
@@ -1,3 +1,3 @@
1
1
  module ComponentLibrary
2
- VERSION = "1.0.1"
2
+ VERSION = "2.0.0"
3
3
  end
@@ -1,15 +1,24 @@
1
1
  require "component_library/engine"
2
2
 
3
3
  module ComponentLibrary
4
+
4
5
  class << self
5
- mattr_accessor :root_directory, :root_path, :application_css
6
- self.root_directory = "component"
7
- self.root_path = "components"
8
- self.application_css = "application"
6
+ attr_accessor :configuration
9
7
  end
10
8
 
11
9
  def self.setup(&block)
12
- yield self
10
+ puts "DEPRECATION NOTICE: configuration via .setup will be removed in future versions of the Component Library gem. Please use .configure instead."
11
+ self.configuration ||= Configuration.new
12
+ yield(configuration)
13
+ end
14
+
15
+ def self.configure(&block)
16
+ self.configuration ||= Configuration.new
17
+ yield(configuration)
18
+ end
19
+
20
+ def self.reset
21
+ @configuration = Configuration.new
13
22
  end
14
23
 
15
24
  def self.stylesheet_path
@@ -19,4 +28,30 @@ module ComponentLibrary
19
28
  def self.javascript_path
20
29
  '_component_library/library'
21
30
  end
22
- end
31
+
32
+ class Configuration
33
+ attr_accessor :root_directory
34
+ attr_accessor :root_path
35
+ attr_accessor :application_css
36
+ attr_accessor :multiconfigure
37
+
38
+ def initialize
39
+ @root_path = "components"
40
+ @root_directory = "component"
41
+ @application_css = "application"
42
+ end
43
+
44
+ def root_paths
45
+ return multiconfigure.map{|mc| mc[:root_path]} if multiconfigure.present?
46
+ [@root_path]
47
+ end
48
+
49
+ def for(filter)
50
+ return multiconfigure.select {|mc| mc[:root_path] == filter } if multiconfigure.present?
51
+ [{ :root_path => @root_path, :root_directory => @root_directory, :application_css => @application_css }]
52
+ end
53
+
54
+
55
+ end
56
+
57
+ end
@@ -1,4 +1,5 @@
1
- ComponentLibrary.setup do |config|
1
+ ComponentLibrary.configure do |config|
2
+ config.application_css = 'application'
2
3
  config.root_path = '<%= file_name %>'
3
4
  config.root_directory = '<%= file_name %>'
4
5
  end
@@ -2,8 +2,7 @@
2
2
  <html>
3
3
  <head>
4
4
  <title>Component</title>
5
- <%= stylesheet_link_tag 'application', media: 'all' %>
6
- <%= stylesheet_link_tag ComponentLibrary.stylesheet_path, media: 'all' %>
5
+ <%= stylesheet_link_tag ComponentLibrary.stylesheet_path, @configuration[:application_css], media: 'all' %>
7
6
  <meta name="viewport" content="width=device-width, initial-scale=1">
8
7
  </head>
9
8
  <body>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: component_library
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rich Archer
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-04-29 00:00:00.000000000 Z
12
+ date: 2016-06-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sqlite3