-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
44 changed files
with
588 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
; top-most EditorConfig file | ||
root = true | ||
|
||
; Unix-style newlines | ||
[*] | ||
end_of_line = LF | ||
indent_style = space | ||
indent_size = 2 | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# frozen_string_literal: true | ||
|
||
module Komponent | ||
class StyleguideController < ::ApplicationController | ||
layout 'komponent' | ||
rescue_from ActionView::MissingTemplate, with: :missing_template | ||
|
||
def index; end | ||
|
||
def show | ||
@component = Komponent::Component.find(params[:id]) | ||
end | ||
|
||
private | ||
|
||
def missing_template | ||
render 'komponent/styleguide/missing_template', status: :not_found | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<h1>Styleguide</h1> | ||
|
||
<% if komponent_components.any? %> | ||
<p>Select one of the components from the side to view its examples and documentation.</p> | ||
<% else %> | ||
<h2><span>Hint:</span>You haven't created any components yet</h2> | ||
<p>You can generate your first component by running:</p> | ||
<pre>rails generate component component-name</pre> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<h1>Examples missing</h1> | ||
|
||
<p>Please create <code><%= @component.path %>/_examples.html.<%= Rails.application.config.app_generators.rails[:template_engine] || :erb %></code> file.</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<%= render partial: @component.examples_view %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Styleguide</title> | ||
<%= javascript_pack_tag 'komponent' %> | ||
<%= stylesheet_pack_tag 'komponent', media: 'all' %> | ||
<%= csrf_meta_tags %> | ||
</head> | ||
<body> | ||
<%= c 'komponent/header' %> | ||
<%= c 'komponent/sidebar' %> | ||
<%= c 'komponent/container' do %> | ||
<%= yield %> | ||
<% end %> | ||
<%= c 'komponent/footer' %> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
Komponent::Engine.routes.draw do | ||
resources :styleguide, only: %i[index show] #, path: Komponent.configuration.styleguide_path | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<h1><%= @component_name %></h1> | ||
|
||
<%%= cdoc "<%= component_name %>" %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
%h1 <%= @component_name %> | ||
|
||
= cdoc "<%= component_name %>" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
h1 <%= @component_name %> | ||
|
||
= cdoc "<%= component_name %>" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'komponent/component' | ||
require File.expand_path('../utils', __FILE__) | ||
|
||
module Komponent | ||
module Generators | ||
class ExamplesGenerator < Rails::Generators::Base | ||
include Utils | ||
|
||
source_root File.expand_path('../../component/templates', __FILE__) | ||
|
||
def create_examples_files | ||
Komponent::Component.all.each do |name, component| | ||
create_examples_view_file(name) | ||
end | ||
end | ||
|
||
protected | ||
|
||
def split_name(name) | ||
name.split(/[:,::,\/]/).reject(&:blank?).map(&:underscore) | ||
end | ||
|
||
def component_path(component_name) | ||
path_parts = [default_path, 'components', *split_name(component_name)] | ||
|
||
Pathname.new(path_parts.join('/')) | ||
end | ||
|
||
private | ||
|
||
def create_examples_view_file(component_name) | ||
@component_name = split_name(component_name).last.underscore | ||
|
||
template "examples.html.#{template_engine}.erb", component_path(component_name) + "_examples.html.#{template_engine}" | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# frozen_string_literal: true | ||
|
||
require File.expand_path('../utils', __FILE__) | ||
|
||
module Komponent | ||
module Generators | ||
class StyleguideGenerator < Rails::Generators::Base | ||
include Utils | ||
|
||
source_root File.expand_path('../templates/styleguide', __FILE__) | ||
|
||
def check_komponent_dependency | ||
unless komponent_already_installed? | ||
raise Thor::Error, dependencies_not_met_error_message | ||
end | ||
end | ||
|
||
def copy_styleguide_components | ||
directory 'components', components_directory.join('komponent') | ||
end | ||
|
||
def create_komponent_pack | ||
template 'packs/komponent.js', komponent_pack_path | ||
end | ||
|
||
def append_to_application_routes | ||
route 'mount Komponent::Engine => \'/\' if Rails.env.development?' | ||
end | ||
|
||
protected | ||
|
||
def komponent_pack_path | ||
komponent_root_directory.join('packs', 'komponent.js') | ||
end | ||
|
||
def dependencies_not_met_error_message | ||
'Seems you don\'t have komponent installed in your project. Please install komponent, and follow instructions at https://github.com/komposable/komponent' | ||
end | ||
end | ||
end | ||
end |
3 changes: 3 additions & 0 deletions
3
...erators/komponent/templates/styleguide/components/container/_komponent_container.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<div class="komponent-container"> | ||
<%= yield %> | ||
</div> |
17 changes: 17 additions & 0 deletions
17
lib/generators/komponent/templates/styleguide/components/container/komponent_container.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* stylelint-disable value-list-comma-newline-after */ | ||
|
||
.komponent-container { | ||
font-size: 16px; | ||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, | ||
Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif; | ||
margin: 40px 60px 0 300px; | ||
|
||
.komponent-code { | ||
background-color: #333; | ||
color: #fff; | ||
margin: 10px 0; | ||
padding: 10px; | ||
} | ||
} | ||
|
||
/* stylelint-enable */ |
1 change: 1 addition & 0 deletions
1
lib/generators/komponent/templates/styleguide/components/container/komponent_container.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import "./komponent_container.css"; |
5 changes: 5 additions & 0 deletions
5
...tors/komponent/templates/styleguide/components/container/komponent_container_component.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
module KomponentContainerComponent | ||
extend ComponentHelper | ||
end |
3 changes: 3 additions & 0 deletions
3
lib/generators/komponent/templates/styleguide/components/footer/_komponent_footer.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<div class="komponent-footer"> | ||
Built with <%= link_to "Komponent", "http://komponent.io", target: "_blank" %> | ||
</div> |
Oops, something went wrong.