Skip to content
Permalink
Browse files

Revert "Create Komponent::ComponentRenderer (#70)"

This reverts commit 1b1b448.
  • Loading branch information...
florentferry committed Mar 30, 2018
1 parent 437000b commit 5fd09f325d3a33340982457350c3900d8e0ae91f

This file was deleted.

Oops, something went wrong.
@@ -29,4 +29,5 @@ install:
- yarn

script:
- bundle exec rake test:all_with_coverage
- bundle exec rubocop
- bundle exec rake test
@@ -14,6 +14,4 @@ gem "rubocop", require: false
group :test do
gem "aruba"
gem "cucumber"
gem "simplecov", require: false
gem "coveralls", require: false
end
@@ -2,7 +2,6 @@
[![Build Status](https://travis-ci.org/komposable/komponent.svg?branch=master)](https://travis-ci.org/komposable/komponent)
[![Gem](https://img.shields.io/gem/v/komponent.svg)](https://github.com/komposable/komponent)
[![Dependency Status](https://beta.gemnasium.com/badges/github.com/komposable/komponent.svg)](https://beta.gemnasium.com/projects/github.com/komposable/komponent)
[![Coverage Status](https://coveralls.io/repos/github/komposable/komponent/badge.svg?branch=master)](https://coveralls.io/github/komposable/komponent?branch=master)

**Komponent** implements an opinionated way of organizing front-end code in Ruby on Rails, based on _components_.

@@ -1,33 +1,25 @@
# frozen_string_literal: true

require "bundler/gem_tasks"
require "rubocop/rake_task"
require "rake/testtask"
require "cucumber"
require "cucumber/rake/task"
require "coveralls/rake/task"
require 'cucumber'
require 'cucumber/rake/task'

namespace :test do
task all: [:rubocop, :unit, :cucumber]
task all_with_coverage: [:all, "coveralls:push"]

RuboCop::RakeTask.new
task all: [:unit, :cucumber]

Rake::TestTask.new(:unit) do |t|
t.libs << "test"
t.libs << "lib"
t.test_files = FileList["test/**/*_test.rb"]
t.verbose = true
t.warning = false
end

Cucumber::Rake::Task.new(:cucumber) do |t|
t.cucumber_opts = "--format pretty"
end

Coveralls::RakeTask.new
end

task test: "test:all"
task test: 'test:all'

task default: :test
@@ -1,3 +0,0 @@
# frozen_string_literal: true

require 'simplecov'
@@ -12,6 +12,5 @@

module MyApp
class Application < Rails::Application
config.i18n.load_path += Dir[config.root.join('frontend/components/**/*.yml')]
end
end

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.
@@ -9,5 +9,10 @@ def property(name, options = {})

def self.extended(component)
component.properties = {}
component.class_eval do
def block_given_to_component?
@block_given_to_component.present?
end
end
end
end
@@ -2,17 +2,60 @@

module KomponentHelper
def component(component, locals = {}, &block)
Komponent::ComponentRenderer.new(
controller,
).render(
component,
locals,
&block
)
component_path = Komponent::ComponentPathResolver.new.resolve(component)

parts = component.split("/")
component_name = parts.join("_")
component_path = component_path.join("#{component_name}_component")

require_dependency(component_path)

component_module = "#{component_name}_component".camelize.constantize
context = controller.view_context.dup

context.view_flow = view_flow

view_renderer = context.view_renderer = context.view_renderer.dup
lookup_context = view_renderer.lookup_context = view_renderer.lookup_context.dup
lookup_context.prefixes = ["components/#{component}"]

context.class_eval { prepend component_module }
context.class_eval { prepend Komponent::Translation }

capture_block = proc { capture(&block) } if block

context.instance_eval do
if component_module.respond_to?(:properties)
locals = locals.dup
component_module.properties.each do |name, options|
unless locals.has_key?(name)
if options.has_key?(:default)
locals[name] = options[:default]
elsif options[:required]
raise "Missing required component parameter: #{name}"
end
end
end
end

locals.each do |name, value|
instance_variable_set(:"@#{name}", locals[name])
end

define_singleton_method(:properties) { locals }

instance_variable_set(:"@block_given_to_component", block)
end

begin
context.render("components/#{component}/#{parts.join('_')}", &capture_block)
rescue ActionView::MissingTemplate
warn "[DEPRECATION WARNING] `#{parts.last}` filename in namespace is deprecated in favor of `#{parts.join('_')}`."
context.render("components/#{component}/#{parts.last}", &capture_block)
end
end
alias :c :component

# :nocov:
def render_partial(partial_name, locals = {}, &block)
warn "[DEPRECATION WARNING] `render_partial` is deprecated. Please use default `render` instead."

@@ -36,5 +79,4 @@ def render_partial(partial_name, locals = {}, &block)

rendered_partial
end
# :nocov:
end
@@ -1,10 +1,9 @@
# frozen_string_literal: true

require 'webpacker'
require 'komponent/component_helper'
require 'komponent/component_path_resolver'
require 'komponent/component_renderer'
require 'komponent/translation'
require 'komponent/core/component_helper'
require 'komponent/core/translation'
require 'komponent/core/component_path_resolver'

module Komponent
class Railtie < Rails::Railtie

This file was deleted.

Oops, something went wrong.
@@ -3,39 +3,13 @@
require 'test_helper'

class KomponentHelperTest < ActionView::TestCase
def test_helper_raises_component_missing_error
assert_raise Komponent::ComponentPathResolver::MissingComponentError do
component('missing')
end
end

def test_helper_renders_makes_locals_available_as_instance_variables
assert_equal \
%(<div class="world">🌎</div>),
component('world', world: "🌎").chomp
assert_equal %(<div class="world">🌎</div>), component('world', world: "🌎").chomp
end

def test_helper_makes_all_properties_accessible
assert_equal \
%(<div class="all">🌎 😎</div>),
component('all', world: "🌎", sunglasses: "😎").chomp
end

def test_helper_renders_localized_keys
I18n.locale = :en
assert_equal \
%(<div class="hello">Hello</div>),
component('hello').chomp

I18n.locale = :fr
assert_equal \
%(<div class="hello">Bonjour</div>),
component('hello').chomp
end

def test_helper_renders_default_property
assert_equal \
%(<div class="foo">Foobar</div>),
component('foo').chomp
end
end
@@ -1,7 +1,5 @@
# frozen_string_literal: true

require 'simplecov'

ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../fixtures/my_app/config/environment', __FILE__)
require 'rails/test_help'

0 comments on commit 5fd09f3

Please sign in to comment.
You can’t perform that action at this time.