source
stringclasses
1 value
repo
stringlengths
5
63
repo_url
stringlengths
24
82
path
stringlengths
5
167
language
stringclasses
1 value
license
stringclasses
5 values
stars
int64
10
51.4k
ref
stringclasses
23 values
size_bytes
int64
200
258k
text
stringlengths
137
258k
github
danielweinmann/unlock
https://github.com/danielweinmann/unlock
app/policies/initiative_policy.rb
Ruby
mit
49
master
341
class InitiativePolicy < ApplicationPolicy def publish? update? end def revert_to_draft? update? end def update_states_from_gateways? update? end def permitted_attributes if create? [:name, :first_text, :second_text, :image, :permalink, :currency, :minimum_value] else [...
github
danielweinmann/unlock
https://github.com/danielweinmann/unlock
app/controllers/initiatives_controller.rb
Ruby
mit
49
master
3,179
class InitiativesController < StateController before_action :set_initiative, except: %i[index new sitemap home] respond_to :html, except: [:sitemap] respond_to :xml, only: [:sitemap] respond_to :json, only: [:update, :show] after_action :verify_authorized, except: %i[home index sitemap] after_action :v...
github
danielweinmann/unlock
https://github.com/danielweinmann/unlock
app/controllers/users_controller.rb
Ruby
mit
49
master
547
class UsersController < ApplicationController before_action :set_user respond_to :html after_action :verify_policy_scoped, only: %i[] before_action :authenticate_user! def my_contributions authorize @user @contributions = @user.contributions.not_pending @active = @contributions.with_state(...
github
danielweinmann/unlock
https://github.com/danielweinmann/unlock
app/controllers/application_controller.rb
Ruby
mit
49
master
2,737
class ApplicationController < ActionController::Base include Pundit protect_from_forgery with: :exception before_action :configure_permitted_parameters, if: :devise_controller? helper_method :namespace, :add_headline_and_article!, :suppress_headline_and_article!, :add_headline_and_article?, :add_logo!, :suppre...
github
danielweinmann/unlock
https://github.com/danielweinmann/unlock
app/controllers/state_controller.rb
Ruby
mit
49
master
522
class StateController < ApplicationController private def transition_state(resource, transition, redirect_path = nil) authorize resource resource_name = resource.class.model_name.human if resource.send("can_#{transition}?") resource.send("#{transition}!") flash[:notice] = t('flash.actions....
github
danielweinmann/unlock
https://github.com/danielweinmann/unlock
app/controllers/initiatives/gateways_controller.rb
Ruby
mit
49
master
1,757
class Initiatives::GatewaysController < StateController before_action :set_initiative before_action :set_gateway, except: %i[index new create] respond_to :html after_action :verify_authorized, except: %i[index] after_action :verify_policy_scoped, only: %i[index] def index @gateways = policy_scope(Ga...
github
danielweinmann/unlock
https://github.com/danielweinmann/unlock
app/controllers/initiatives/contributions_controller.rb
Ruby
mit
49
master
1,540
class Initiatives::ContributionsController < ApplicationController before_action :set_initiative before_action :set_contribution, only: %i[update show] respond_to :html, except: [:update] respond_to :json, only: [:index, :update, :show] after_action :verify_authorized, except: %i[index] after_action :ver...
github
danielweinmann/unlock
https://github.com/danielweinmann/unlock
app/models/user.rb
Ruby
mit
49
master
1,006
class User < ActiveRecord::Base ONLY_DIGITS_ATTRIBUTES = %w(document phone_area_code phone_number address_zipcode) devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable has_many :initiatives has_many :contributions has_attached_file :image, styles: { medium...
github
danielweinmann/unlock
https://github.com/danielweinmann/unlock
app/models/initiative.rb
Ruby
mit
49
master
2,709
class Initiative < ActiveRecord::Base belongs_to :user has_many :contributions has_many :gateways translates :name, :first_text, :second_text has_attached_file :image, styles: { medium: "300x300>", thumb: "100x100>" } validates_attachment_content_type :image, content_type: /\Aimage\/.*\Z/ validates_...
github
danielweinmann/unlock
https://github.com/danielweinmann/unlock
app/models/contribution.rb
Ruby
mit
49
master
1,273
class Contribution < ActiveRecord::Base belongs_to :user belongs_to :initiative belongs_to :gateway store_accessor :gateway_data validates_presence_of :user, :initiative, :gateway, :value validates :value, numericality: { only_integer: true, greater_than_or_equal_to: :minimum_value }, allow_blank: true ...
github
danielweinmann/unlock
https://github.com/danielweinmann/unlock
app/models/gateway.rb
Ruby
mit
49
master
1,300
class Gateway < ActiveRecord::Base translates :title, :ordering belongs_to :initiative validates :module_name, uniqueness: { scope: :initiative_id } validates_presence_of :initiative, :module_name validates :ordering, numericality: { only_integer: true }, allow_blank: true store_accessor :settings afte...
github
danielweinmann/unlock
https://github.com/danielweinmann/unlock
app/decorators/contribution_decorator.rb
Ruby
mit
49
master
562
module ContributionDecorator def display_value @display_value ||= humanized_money_with_symbol Money.new(self.value * 100, self.initiative.currency), no_cents_if_whole: false end def next_invoice_date date = nil day = self.created_at.strftime('%d').to_i until date do date = Date.strptime(da...
github
danielweinmann/unlock
https://github.com/danielweinmann/unlock
app/decorators/initiative_decorator.rb
Ruby
mit
49
master
675
module InitiativeDecorator def display_currency(display_name = false) @display_currency ||= Money::Currency.new(self.currency) if display_name "#{@display_currency.symbol} - #{@display_currency.iso_code}" else @display_currency.symbol end end def total_value @total_value ||= self...
github
danielweinmann/unlock
https://github.com/danielweinmann/unlock
app/decorators/user_decorator.rb
Ruby
mit
49
master
303
module UserDecorator def display_name return self.full_name if self.name == self.email.match(/(.+)@/)[1] && self.full_name.present? self.name end def display_image if self.image.present? image_tag(self.image.url(:thumb)) else image_tag('user.svg') end end end
github
danielweinmann/unlock
https://github.com/danielweinmann/unlock
spec/spec_helper.rb
Ruby
mit
49
master
467
# The `.rspec` file also contains a few flags that are not defaults but that # users commonly want. # # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration RSpec.configure do |config| config.expect_with :rspec do |expectations| expectations.include_chain_clauses_in_custom_matcher_descriptions = true ...
github
danielweinmann/unlock
https://github.com/danielweinmann/unlock
spec/rails_helper.rb
Ruby
mit
49
master
707
ENV["RAILS_ENV"] ||= 'test' require 'spec_helper' require File.expand_path("../../config/environment", __FILE__) require 'rspec/rails' # Add additional requires below this line. Rails is not loaded until this point! Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f } # Checks for pending migrations b...
github
danielweinmann/unlock
https://github.com/danielweinmann/unlock
spec/models/user_spec.rb
Ruby
mit
49
master
1,262
require 'rails_helper' RSpec.describe User, type: :model do describe "asociations" do it{ is_expected.to have_many :initiatives } it{ is_expected.to have_many :contributions } end describe "#set_locale" do before do visitor_user.set_locale :pt end it "should change user locale" do ...
github
danielweinmann/unlock
https://github.com/danielweinmann/unlock
spec/models/initiative_spec.rb
Ruby
mit
49
master
729
require 'rails_helper' RSpec.describe Initiative, type: :model do describe "asociations" do it{ is_expected.to belong_to :user } it{ is_expected.to have_many :contributions } it{ is_expected.to have_many :gateways } end describe "validations" do it{ is_expected.to validate_presence_of :user } ...
github
danielweinmann/unlock
https://github.com/danielweinmann/unlock
spec/models/contribution_spec.rb
Ruby
mit
49
master
3,033
require 'rails_helper' RSpec.describe Contribution, type: :model do describe "asociations" do it{ is_expected.to belong_to :user } it{ is_expected.to belong_to :initiative } it{ is_expected.to belong_to :gateway } end describe "validations" do subject{ pending_contribution } it{ is_expected....
github
danielweinmann/unlock
https://github.com/danielweinmann/unlock
spec/models/gateway_spec.rb
Ruby
mit
49
master
3,129
require 'rails_helper' RSpec.describe Gateway, type: :model do describe "asociations" do it{ is_expected.to belong_to :initiative } end describe "validations" do it{ is_expected.to validate_presence_of :initiative } it{ is_expected.to validate_presence_of :module_name } it{ is_expected.to valida...
github
danielweinmann/unlock
https://github.com/danielweinmann/unlock
spec/controllers/contributions_controller_spec.rb
Ruby
mit
49
master
1,916
require 'rails_helper' RSpec.describe Initiatives::ContributionsController, type: :controller do render_views subject{ response } let(:user){ nil } let(:initiative) { unlock_initiative } let(:gateway) { initiative.gateways.first } before do allow(controller).to receive(:current_user).and_return(user...
github
danielweinmann/unlock
https://github.com/danielweinmann/unlock
spec/controllers/initiatives_controller_spec.rb
Ruby
mit
49
master
765
require 'rails_helper' RSpec.describe InitiativesController, type: :controller do subject{ response } let(:user){ nil } before do allow(controller).to receive(:current_user).and_return(user) end describe "GET index" do before do get :index end it{ is_expected.to redirect_to initiativ...
github
danielweinmann/unlock
https://github.com/danielweinmann/unlock
spec/support/seed_database.rb
Ruby
mit
49
master
1,961
RSpec.configure do |config| def get_user(name) @users ||= {} @users[name] ||= User.create!(email: "#{name}@bar.com", password: 'test123', password_confirmation: 'test123', locale: 'en', name: name.humanize) @users[name].reload end def get_initiative(permalink, user) @initiatives ||= {} @initi...
github
mcolyer/smartermeter
https://github.com/mcolyer/smartermeter
smartermeter.gemspec
Ruby
mit
49
master
4,202
## This is the rakegem gemspec template. Make sure you read and understand ## all of the comments. Some sections require modification, and others can ## be deleted if you don't need them. Once you understand the contents of ## this file, feel free to delete any comments that begin with two hash marks. ## You can find c...
github
mcolyer/smartermeter
https://github.com/mcolyer/smartermeter
Gemfile
Ruby
mit
49
master
282
source 'https://rubygems.org' gemspec # Used only in the Java client, which isn't distributed as a gem gem "nokogiri", ">= 1.4.4", :platforms => :jruby gem "nokogiri", ">= 1.4.4", :platforms => :ruby gem "profligacy", :platforms => :jruby gem "jruby-openssl", :platforms => :jruby
github
mcolyer/smartermeter
https://github.com/mcolyer/smartermeter
Rakefile
Ruby
mit
49
master
7,487
require 'rubygems' require 'rake' require 'date' ############################################################################# # # Helper functions # ############################################################################# def name @name ||= Dir['*.gemspec'].first.split('.').first end def version line = Fil...
github
mcolyer/smartermeter
https://github.com/mcolyer/smartermeter
installer/main.rb
Ruby
mit
49
master
557
# Used only to launch from a jar using rawr require 'rubygems' require 'jruby' # This is needed for nokogiri to function properly under jruby JRuby.objectspace=true require 'smartermeter' require 'smartermeter/daemon' require 'smartermeter/interfaces/swing' # Force character sets of all retrieved documents so that w...
github
mcolyer/smartermeter
https://github.com/mcolyer/smartermeter
lib/smartermeter.rb
Ruby
mit
49
master
292
require 'smartermeter/sample' require 'smartermeter/samples' require 'smartermeter/service' require 'smartermeter/daemon' require 'smartermeter/services/pachube' require 'smartermeter/services/brighterplanet' require 'smartermeter/interfaces/cli' module SmarterMeter VERSION = "0.4.6" end
github
mcolyer/smartermeter
https://github.com/mcolyer/smartermeter
lib/smartermeter/service.rb
Ruby
mit
49
master
3,352
require 'mechanize' require 'csv' require 'tempfile' require 'zip' require 'uri' module SmarterMeter # Provides access to the PG&E SmartMeter data through a ruby interface. This # class depends on the PG&E website to function the same that it does today, # so if something stops working its likely that something ...
github
mcolyer/smartermeter
https://github.com/mcolyer/smartermeter
lib/smartermeter/samples.rb
Ruby
mit
49
master
2,084
require 'date' require 'time' require 'nokogiri' module SmarterMeter # Represents a collection of samples. In some cases it's useful to operate on # groups of samples and this class provides that functionality. class Samples < Array # Parses the XML returned by PG&E and creates a Samples collection. # ...
github
mcolyer/smartermeter
https://github.com/mcolyer/smartermeter
lib/smartermeter/sample.rb
Ruby
mit
49
master
1,275
require 'date' require 'time' module SmarterMeter # Represents a single hourly sample taken from the PG&E hourly electricity # data. It's the most basic data unit of SmarterMeter. class Sample attr_accessor :time, :kwh # Creates a new Sample. # # @param [Time] time the start of the sample period...
github
mcolyer/smartermeter
https://github.com/mcolyer/smartermeter
lib/smartermeter/daemon.rb
Ruby
mit
49
master
6,237
require 'fileutils' require 'crypt/blowfish' require 'yaml' require 'date' require 'base64' module SmarterMeter # @private class Daemon def initialize(interface) @ui = interface end # Loads the configuration, and starts # # Never returns. def start configure run end ...
github
mcolyer/smartermeter
https://github.com/mcolyer/smartermeter
lib/smartermeter/services/brighterplanet.rb
Ruby
mit
49
master
2,102
require 'restclient' require 'json' require 'erb' module SmarterMeter module Services # Allows users to calculate the carbon produced by their energy usage by # accessing the Brighter Planet CM1 Electricity API. # # More details can be found here: # http://carbon.brighterplanet.com/models/electri...
github
mcolyer/smartermeter
https://github.com/mcolyer/smartermeter
lib/smartermeter/services/pachube.rb
Ruby
mit
49
master
1,571
require 'net/https' module SmarterMeter module Services class Pachube def initialize(ui, config) @ui = ui @config = config raise "The Pachube token must be configured" unless @config[:api_key] raise "The Pachube feed id must be configured" unless @config[:feed_id] ra...
github
mcolyer/smartermeter
https://github.com/mcolyer/smartermeter
lib/smartermeter/interfaces/cli.rb
Ruby
mit
49
master
1,395
require 'logger' module SmarterMeter module Interfaces class CLI def initialize(options) @options = options end # Returns a logger like interface to log errors and warnings to. def log return @logger if @logger @logger = Logger.new STDOUT if @options[:deb...
github
mcolyer/smartermeter
https://github.com/mcolyer/smartermeter
lib/smartermeter/interfaces/swing.rb
Ruby
mit
49
master
15,946
require 'logger' require 'profligacy/swing' require 'profligacy/lel' module SmarterMeter # @private module Interfaces class Swing include_package "java.awt" LogFile = File.expand_path("~/.smartermeter.log") def initialize # TODO: Implement a way to update the settings #setti...
github
mcolyer/smartermeter
https://github.com/mcolyer/smartermeter
spec/spec_helper.rb
Ruby
mit
49
master
368
require 'rubygems' require 'bundler/setup' Bundler.require(:default) require 'rspec' require 'vcr' $:.unshift File.join(File.dirname(__FILE__), '..', 'lib') require 'smartermeter' $FIXTURES_DIR = File.expand_path(File.join(File.dirname(__FILE__), "fixtures")) VCR.configure do |c| c.cassette_library_dir = 'spec/fix...
github
mcolyer/smartermeter
https://github.com/mcolyer/smartermeter
spec/samples_spec.rb
Ruby
mit
49
master
850
require 'spec_helper' describe SmarterMeter::Samples do before(:all) do @data = File.read(File.join($FIXTURES_DIR, 'data.xml')) @date_present = DateTime.new(2013, 4, 10, 0, 0, 0, -7) end subject { SmarterMeter::Samples.parse_espi(@data) } it "can calculate the total number of kilowatt hours used" do ...
github
mcolyer/smartermeter
https://github.com/mcolyer/smartermeter
spec/daemon_spec.rb
Ruby
mit
49
master
470
require 'spec_helper' describe SmarterMeter::Daemon do subject { SmarterMeter::Daemon.new(nil) } it "can handle a password of length 1" do subject.instance_variable_set(:@config, {}) subject.send(:password=, "1") subject.send(:password).should == "1" end it "can handle a password of length 9" do ...
github
mcolyer/smartermeter
https://github.com/mcolyer/smartermeter
spec/services/pachube_spec.rb
Ruby
mit
49
master
878
$:.unshift File.join(File.dirname(__FILE__), "..") require 'spec_helper' describe SmarterMeter::Services::Pachube do before(:each) do @ui = mock("UI") @subject = SmarterMeter::Services::Pachube.new(@ui, :api_key => "secret", ...
github
mcolyer/smartermeter
https://github.com/mcolyer/smartermeter
spec/services/brighterplanet_spec.rb
Ruby
mit
49
master
1,013
$:.unshift File.join(File.dirname(__FILE__), "..") require 'spec_helper' describe SmarterMeter::Services::BrighterPlanet do it "can determine kilograms of carbon produced from the number of killowatt hours" do VCR.use_cassette('brighterplanet', :record => :new_episodes) do subject.calculate_kg_carbon(1).sh...
github
discourse/discourse-steam-login
https://github.com/discourse/discourse-steam-login
plugin.rb
Ruby
mit
49
main
729
# frozen_string_literal: true # name: discourse-steam-login # about: Allows users to login to your forum using Steam Authentication. # meta_topic_id: 18153 # version: 2.0.1 # author: J. de Faye, tgxworld # omniauth-openid is not included in core since v2.4.0.beta10 unless defined?(OmniAuth::Strategies::OpenID) gem ...
github
discourse/discourse-steam-login
https://github.com/discourse/discourse-steam-login
lib/auth/steam_authenticator.rb
Ruby
mit
49
main
565
# frozen_string_literal: true class Auth::SteamAuthenticator < ::Auth::ManagedAuthenticator def name "steam" end def enabled? SiteSetting.enable_steam_logins end def can_revoke? SiteSetting.steam_logins_allow_revoke end def register_middleware(omniauth) omniauth.provider :steam, ...
github
discourse/discourse-steam-login
https://github.com/discourse/discourse-steam-login
lib/validators/enable_steam_logins_validator.rb
Ruby
mit
49
main
389
# frozen_string_literal: true class EnableSteamLoginsValidator def initialize(opts = {}) @opts = opts end def valid_value?(val) return true if val == "f" return false if SiteSetting.steam_web_api_key.blank? true end def error_message if SiteSetting.steam_web_api_key.blank? I18n.t(...
github
discourse/discourse-steam-login
https://github.com/discourse/discourse-steam-login
spec/lib/auth/steam_authenticator_spec.rb
Ruby
mit
49
main
507
# frozen_string_literal: true describe Auth::SteamAuthenticator do describe "#can_revoke?" do it "should be false be default" do authenticator = Auth::SteamAuthenticator.new expect(authenticator.can_revoke?).to eq(false) end it "should be true when steam_logins_allow_revoke site settings is...
github
discourse/discourse-steam-login
https://github.com/discourse/discourse-steam-login
spec/integration/steam_auth_spec.rb
Ruby
mit
49
main
4,790
# frozen_string_literal: true describe "Steam OpenID 2.0" do let(:web_api_key) { "abcdef11223344" } let(:steam_user_id) { "894923402340234" } before do # jack up OpenID logger min severity to remove noisy info messages OpenID::Util.logger.level = 100 SiteSetting.steam_web_api_key = web_api_key S...
github
discourse/discourse-steam-login
https://github.com/discourse/discourse-steam-login
spec/components/validators/enable_steam_logins_validator_spec.rb
Ruby
mit
49
main
957
# frozen_string_literal: true RSpec.describe EnableSteamLoginsValidator do subject(:validator) { described_class.new } describe "#valid_value?" do describe "when steam_web_api_key has not been set" do it "should return true when value is false" do expect(validator.valid_value?("f")).to eq(true) ...
github
discourse/discourse-steam-login
https://github.com/discourse/discourse-steam-login
db/migrate/20190510055357_migrate_steam_auth_data.rb
Ruby
mit
49
main
549
# frozen_string_literal: true class MigrateSteamAuthData < ActiveRecord::Migration[5.2] def up execute <<~SQL INSERT INTO user_associated_accounts ( provider_name, provider_uid, user_id, created_at, updated_at ) SELECT 'steam', replace(key, 'steam_uid_', ''), ...
github
patbenatar/rbexy
https://github.com/patbenatar/rbexy
Appraisals
Ruby
mit
49
master
300
appraise "rails-7-0" do gem "rails", "~> 7.0.0" gem "sqlite3", "~> 1.4" end appraise "rails-7-1" do gem "rails", "~> 7.1.0" end appraise "rails-7-2" do gem "rails", "~> 7.2.0" end appraise "rails-8-0" do gem "rails", "~> 8.0.0" end appraise "rails-8-1" do gem "rails", "~> 8.1.0" end
github
patbenatar/rbexy
https://github.com/patbenatar/rbexy
rbexy.gemspec
Ruby
mit
49
master
1,927
require_relative 'lib/rbexy/version' Gem::Specification.new do |spec| spec.name = "rbexy" spec.version = Rbexy::VERSION spec.authors = ["Nick Giancola"] spec.email = ["patbenatar@gmail.com"] spec.summary = "A Ruby template language inspired by JSX" spec.homepage = "...
github
patbenatar/rbexy
https://github.com/patbenatar/rbexy
spec/compiler_spec.rb
Ruby
mit
49
master
899
require "active_support/core_ext/string/strip" RSpec.describe "rbx->ruby integration tests" do describe "debuggers" do it "compiles them to quiet output and adds a newline so the binding isn't placed into the output_buffer call" do template_string = <<-RBX.strip_heredoc {binding.pry} RBX ...
github
patbenatar/rbexy
https://github.com/patbenatar/rbexy
spec/spec_helper.rb
Ruby
mit
49
master
1,990
require "bundler/setup" require "pry" require "rspec-html-matchers" require "rbexy" require "memory_profiler" # Rails dummy app for integration tests ENV["RAILS_ENV"] ||= "test" require File.expand_path('../dummy/config/environment.rb', __FILE__) require "rspec/rails" module PerfHelpers def self.results @result...
github
patbenatar/rbexy
https://github.com/patbenatar/rbexy
spec/rbexy_spec.rb
Ruby
mit
49
master
18,803
require "active_support/core_ext/string/strip" require "active_support/all" require "action_view" RSpec.describe Rbexy do it "has a version number" do expect(Rbexy::VERSION).not_to be nil end it "handles simple nested html" do template_string = <<-RBX.strip_heredoc.strip <div> <h1>Hello wo...
github
patbenatar/rbexy
https://github.com/patbenatar/rbexy
spec/integration/rbx_view_spec.rb
Ruby
mit
49
master
811
RSpec.describe RbxViewController, type: :controller do render_views it "renders rbx files in app/views/" do get :index expect(response.body).to have_tag("h1", text: "Hello from rbx view") expect(response.body).to have_tag("div > h2", text: "Subheading") expect(response.body).to have_tag("div > p",...
github
patbenatar/rbexy
https://github.com/patbenatar/rbexy
spec/integration/controller_context_spec.rb
Ruby
mit
49
master
263
RSpec.describe ContextController, type: :controller do render_views it "allows the controller to add to the component context with create_context" do get :index expect(response.body).to have_tag("h1", text: "Hello context from controller") end end
github
patbenatar/rbexy
https://github.com/patbenatar/rbexy
spec/integration/component_spec.rb
Ruby
mit
49
master
5,594
RSpec.describe ApplicationController, type: :controller do render_views controller do; end let(:view_context) { controller.view_context } it "renders an rbx template" do expect(BasicTemplateComponent.new(view_context).render_in) .to have_tag("h1", text: "Hello basic template component") end it ...
github
patbenatar/rbexy
https://github.com/patbenatar/rbexy
spec/integration/component_namespaces_spec.rb
Ruby
mit
49
master
646
RSpec.describe ApplicationController, type: :controller do render_views controller do; end let(:view_context) { controller.view_context } before do Rbexy.configuration.element_resolver.component_namespaces = { Rails.root.join("app", "components", "auto_namespacing") => %w[AutoNamespacing] } en...
github
patbenatar/rbexy
https://github.com/patbenatar/rbexy
spec/integration/caching/before_changes_spec.rb
Ruby
mit
49
master
1,436
# NOTE: These specs are only meant to run as a part of bin/test, # where this file warms the cache, and then after_changes_spec.rb # runs next to test source changes against a warm cache. RSpec.describe CachingController, type: :request, retry: 5 do before(:each) { Thread.current[:cache_misses] = 0 } before(:all) ...
github
patbenatar/rbexy
https://github.com/patbenatar/rbexy
spec/integration/caching/after_changes_spec.rb
Ruby
mit
49
master
1,776
# NOTE: These specs are only meant to run as a part of bin/test, # where before_changes_spec.rb has run first to warm the cache RSpec.describe CachingController, type: :request, retry: 5 do before(:each) { Thread.current[:cache_misses] = 0 } after(:all) { Rails.cache.clear } describe "fragment caching using `<R...
github
patbenatar/rbexy
https://github.com/patbenatar/rbexy
spec/lib/rbexy/component_resolver_spec.rb
Ruby
mit
49
master
3,908
RSpec.describe Rbexy::ComponentResolver do describe "#component_class" do it "resolves strings to constants ending with Component" do subject = Rbexy::ComponentResolver.new redefine { ButtonComponent = Class.new } result = subject.component_class("Button", Rbexy::Template.new("")) expect(...
github
patbenatar/rbexy
https://github.com/patbenatar/rbexy
spec/lib/rbexy/lexer_spec.rb
Ruby
mit
49
master
25,565
require "active_support/core_ext/string/strip" RSpec.describe Rbexy::Lexer do it "tokenizes text" do subject = Rbexy::Lexer.new(Rbexy::Template.new("Hello world"), Rbexy::ComponentResolver.new) expect(subject.tokenize).to eq [[:TEXT, "Hello world"]] end it "tokenizes html tags" do subject = Rbexy::L...
github
patbenatar/rbexy
https://github.com/patbenatar/rbexy
spec/lib/rbexy/parser_spec.rb
Ruby
mit
49
master
9,437
RSpec.describe Rbexy::Parser do it "handles :TEXT" do subject = Rbexy::Parser.new([[:TEXT, "Hello world"]]) result = subject.parse.children expect(result.first).to be_a Rbexy::Nodes::Text expect(result.first.content).to eq "Hello world" end it "parses declarations" do subject = Rbexy::Parser....
github
patbenatar/rbexy
https://github.com/patbenatar/rbexy
spec/lib/rbexy/nodes/util_spec.rb
Ruby
mit
49
master
233
RSpec.describe Rbexy::Nodes::Util do describe ".escape_string" do it "escapes single quotes" do result = described_class.escape_string("You're cool, eh?") expect(result).to eq "You\\'re cool, eh?" end end end
github
patbenatar/rbexy
https://github.com/patbenatar/rbexy
spec/lib/rbexy/nodes/text_spec.rb
Ruby
mit
49
master
315
RSpec.describe Rbexy::Nodes::Text do describe "#precompile" do it "converts to raw" do result = Rbexy::Nodes::Text.new("Some text").precompile expect(result.length).to eq 1 expect(result.first).to be_a Rbexy::Nodes::Raw expect(result.first.content).to eq "Some text" end end end
github
patbenatar/rbexy
https://github.com/patbenatar/rbexy
spec/lib/rbexy/nodes/html_attr_spec.rb
Ruby
mit
49
master
677
RSpec.describe Rbexy::Nodes::HTMLAttr do context "with AST transforms" do it "allows the registered transforms to mutate the node" do transformer = Rbexy::ASTTransformer.new transformer.register(Rbexy::Nodes::HTMLAttr) { |node, context| node.name = "#{node.name}-t1" } transformer.register(Rbexy:...
github
patbenatar/rbexy
https://github.com/patbenatar/rbexy
spec/lib/rbexy/nodes/expression_group_spec.rb
Ruby
mit
49
master
939
RSpec.describe Rbexy::Nodes::ExpressionGroup do describe "precompile->compile" do it "doesn't try to output a debugger and adds a newline to ensure binding is in the right place" do subject = described_class.new([Rbexy::Nodes::Expression.new("debugger")]) result = subject.precompile.map(&:compile).joi...
github
patbenatar/rbexy
https://github.com/patbenatar/rbexy
spec/lib/rbexy/rails/rbx_dependency_tracker_spec.rb
Ruby
mit
49
master
1,416
RSpec.describe Rbexy::Rails::RbxDependencyTracker do describe "#dependencies" do it "returns the paths to all sub-component templates for a given template" do redefine do Sub1Component = Class.new(Rbexy::Component) Sub2Component = Class.new(Rbexy::Component) end template = doubl...
github
patbenatar/rbexy
https://github.com/patbenatar/rbexy
spec/lib/rbexy/rails/component_template_resolver_spec.rb
Ruby
mit
49
master
3,206
RSpec.describe Rbexy::Rails::ComponentTemplateResolver do describe "#find_all" do context "rbx" do it "returns the rbx template matching the given component path" do subject = described_class.new(Rails.root.join("app/components")) template_path = Rbexy::Component::TemplatePath.new("template_...
github
patbenatar/rbexy
https://github.com/patbenatar/rbexy
spec/lib/rbexy/refinements/array/map_type_when_neighboring_type_spec.rb
Ruby
mit
49
master
567
RSpec.describe Rbexy::Refinements::Array::MapTypeWhenNeighboringType do using Rbexy::Refinements::Array::MapTypeWhenNeighboringType it "yields the item for mapping if its type matches match_type and one of its neighbors matches neighbor_type" do original = ["welcome", 1, "hello", { foo: "bar" }, "world", 2, { ...
github
patbenatar/rbexy
https://github.com/patbenatar/rbexy
spec/lib/rbexy/refinements/array/insert_between_types_spec.rb
Ruby
mit
49
master
433
RSpec.describe Rbexy::Refinements::Array::InsertBetweenTypes do using Rbexy::Refinements::Array::InsertBetweenTypes it "adds an element between every pair of given types" do original = [1, "hello", { foo: "bar" }, "world", 2, { baz: "bip" }, "!"] result = original.insert_between_types(Hash, String) { "+" }...
github
patbenatar/rbexy
https://github.com/patbenatar/rbexy
spec/lib/rbexy/refinements/array/find_map_spec.rb
Ruby
mit
49
master
800
RSpec.describe Rbexy::Refinements::Array::FindMap do using Rbexy::Refinements::Array::FindMap it "returns the mapped value of the first truthy result from the block" do result = [1, 2, 3, 4].find_map do |value| if value == 1 false elsif value == 2 nil elsif value == 3 ...
github
patbenatar/rbexy
https://github.com/patbenatar/rbexy
spec/dummy/app/controllers/perf_test_controller.rb
Ruby
mit
49
master
362
class PerfTestController < ActionController::Base layout false helper_method :time def index end def time times = 100.times.map do start = Time.now yield (Time.now.to_f - start.to_f) * 1000 end avg_duration = (times.sum.to_f / times.count).round(2) "<div>Avg time (ms): #...
github
patbenatar/rbexy
https://github.com/patbenatar/rbexy
spec/dummy/config/routes.rb
Ruby
mit
49
master
526
Rails.application.routes.draw do get "rbx_view" => "rbx_view#index" get "controller_context" => "context#index" get "perf_test", to: "perf_test#index" get "utf8", to: "rbx_view#utf8" get "nested_splat", to: "rbx_view#nested_splat" get "caching/inline", to: "caching#inline" get "caching/component", to: "ca...
github
patbenatar/rbexy
https://github.com/patbenatar/rbexy
spec/dummy/config/application.rb
Ruby
mit
49
master
1,236
require_relative "boot" require "rails" # Pick the frameworks you want: require "active_model/railtie" require "active_job/railtie" require "active_record/railtie" require "active_storage/engine" require "action_controller/railtie" require "action_mailer/railtie" require "action_view/railtie" require "action_cable/eng...
github
patbenatar/rbexy
https://github.com/patbenatar/rbexy
spec/dummy/config/environments/test.rb
Ruby
mit
49
master
1,935
# The test environment is used exclusively to run your application's # test suite. You never need to work with it otherwise. Remember that # your test database is "scratch space" for the test suite and is wiped # and recreated between test runs. Don't rely on the data there! Rails.application.configure do # Settings...
github
patbenatar/rbexy
https://github.com/patbenatar/rbexy
lib/rbexy.rb
Ruby
mit
49
master
1,526
require "rbexy/version" require "ostruct" require "active_support/inflector" require "active_support/concern" require "active_support/core_ext/enumerable" require "action_view" require "rbexy/rails/engine" if defined?(::Rails) module Rbexy autoload :Lexer, "rbexy/lexer" autoload :Parser, "rbexy/parser" autoload...
github
patbenatar/rbexy
https://github.com/patbenatar/rbexy
lib/rbexy/parser.rb
Ruby
mit
49
master
4,767
module Rbexy class Parser class ParseError < StandardError; end attr_reader :tokens attr_accessor :position def initialize(tokens) @tokens = tokens @position = 0 end def parse validate_tokens! Nodes::Root.new(parse_tokens) end def parse_tokens results ...
github
patbenatar/rbexy
https://github.com/patbenatar/rbexy
lib/rbexy/configuration.rb
Ruby
mit
49
master
713
module Rbexy class Configuration attr_accessor :element_resolver attr_accessor :template_paths attr_accessor :enable_context attr_accessor :debug attr_accessor :component_rendering_templates attr_accessor :transforms def template_paths @template_paths ||= [] end def element...
github
patbenatar/rbexy
https://github.com/patbenatar/rbexy
lib/rbexy/lexer.rb
Ruby
mit
49
master
10,640
module Rbexy class Lexer class SyntaxError < StandardError def initialize(lexer) super( "Invalid syntax: `#{lexer.scanner.peek(20)}`\n" + "Stack: #{lexer.stack}\n" + "Tokens: #{lexer.tokens}" ) end end Patterns = OpenStruct.new( open_express...
github
patbenatar/rbexy
https://github.com/patbenatar/rbexy
lib/rbexy/template.rb
Ruby
mit
49
master
237
module Rbexy class Template attr_reader :source, :identifier Anonymous = Class.new(String).new.freeze def initialize(source, identifier = Anonymous) @source = source @identifier = identifier end end end
github
patbenatar/rbexy
https://github.com/patbenatar/rbexy
lib/rbexy/runtime.rb
Ruby
mit
49
master
920
module Rbexy class Runtime include ActionView::Context include ActionView::Helpers::TagHelper include ComponentContext def self.tag_builder @tag_builder ||= TagBuilder.new(new) end def self.splat_attrs(attrs_hash) tag_builder.tag_options(attrs_hash)&.html_safe end def se...
github
patbenatar/rbexy
https://github.com/patbenatar/rbexy
lib/rbexy/component.rb
Ruby
mit
49
master
2,741
require "active_support/core_ext/class/attribute" module Rbexy class Component < ActionView::Base autoload :BacktraceCleaner, "rbexy/component/backtrace_cleaner" class TemplatePath < String def to_s self end def split(*args) super.map { |s| TemplatePath.new(s) } end ...
github
patbenatar/rbexy
https://github.com/patbenatar/rbexy
lib/rbexy/cache_component.rb
Ruby
mit
49
master
357
module Rbexy class CacheComponent < Rbexy::Component def setup(key:) @key = key end def call @current_template = view_context.instance_variable_get(:@current_template) capture do cache @key, virtual_path: @current_template.virtual_path do @output_buffer << content ...
github
patbenatar/rbexy
https://github.com/patbenatar/rbexy
lib/rbexy/nodes.rb
Ruby
mit
49
master
801
module Rbexy module Nodes autoload :Util, "rbexy/nodes/util" autoload :AbstractNode, "rbexy/nodes/abstract_node" autoload :Root, "rbexy/nodes/root" autoload :Raw, "rbexy/nodes/raw" autoload :Text, "rbexy/nodes/text" autoload :ExpressionGroup, "rbexy/nodes/expression_group" autoload :Expres...
github
patbenatar/rbexy
https://github.com/patbenatar/rbexy
lib/rbexy/ast_transformer.rb
Ruby
mit
49
master
374
module Rbexy class ASTTransformer attr_reader :registry def initialize clear! end def register(*node_classes, &block) node_classes.each { |k| (registry[k] ||= []) << block } end def transform(node, context) registry[node.class]&.each { |t| t.call(node, context) } end ...
github
patbenatar/rbexy
https://github.com/patbenatar/rbexy
lib/rbexy/component_context.rb
Ruby
mit
49
master
401
module Rbexy module ComponentContext def rbexy_context @rbexy_context ||= [{}] end def create_context(name, value) rbexy_context.last[name] = value end def use_context(name) index = rbexy_context.rindex { |c| c.has_key?(name) } index ? rbexy_context[index][name] :...
github
patbenatar/rbexy
https://github.com/patbenatar/rbexy
lib/rbexy/component_resolver.rb
Ruby
mit
49
master
2,736
module Rbexy class ComponentResolver using Rbexy::Refinements::Array::FindMap KNOWN_HTML_ELEMENTS = %w( a abbr acronym address animate animateMotion animateTransform applet area article aside audio b base basefont bdi bdo bgsound big blink blockquote body br button canvas caption center circle ci...
github
patbenatar/rbexy
https://github.com/patbenatar/rbexy
lib/rbexy/rails.rb
Ruby
mit
49
master
395
module Rbexy autoload :Component, "rbexy/component" autoload :CacheComponent, "rbexy/cache_component" module Rails autoload :Engine, "rbexy/rails/engine" autoload :ControllerHelper, "rbexy/rails/controller_helper" autoload :ComponentTemplateResolver, "rbexy/rails/component_template_resolver" auto...
github
patbenatar/rbexy
https://github.com/patbenatar/rbexy
lib/rbexy/component/backtrace_cleaner.rb
Ruby
mit
49
master
1,476
module Rbexy class Component class BacktraceCleaner attr_reader :backtrace def initialize(backtrace) @backtrace = backtrace @found_templates = {} end def call backtrace .reject(&method(:internal_implementation_detail?)) .map(&method(:strip_rbx_...
github
patbenatar/rbexy
https://github.com/patbenatar/rbexy
lib/rbexy/refinements/array.rb
Ruby
mit
49
master
313
module Rbexy module Refinements module Array autoload :FindMap, "rbexy/refinements/array/find_map" autoload :InsertBetweenTypes, "rbexy/refinements/array/insert_between_types" autoload :MapTypeWhenNeighboringType, "rbexy/refinements/array/map_type_when_neighboring_type" end end end
github
patbenatar/rbexy
https://github.com/patbenatar/rbexy
lib/rbexy/refinements/array/find_map.rb
Ruby
mit
49
master
237
module Rbexy module Refinements module Array module FindMap refine ::Array do def find_map lazy.map { |i| yield(i) }.reject { |v| !v }.first end end end end end end
github
patbenatar/rbexy
https://github.com/patbenatar/rbexy
lib/rbexy/refinements/array/map_type_when_neighboring_type.rb
Ruby
mit
49
master
699
module Rbexy module Refinements module Array module MapTypeWhenNeighboringType refine ::Array do def map_type_when_neighboring_type(map_type, neighboring_type, &block) map.with_index do |curr, i| prev_i = i - 1 next_i = i + 1 if !curr....
github
patbenatar/rbexy
https://github.com/patbenatar/rbexy
lib/rbexy/refinements/array/insert_between_types.rb
Ruby
mit
49
master
759
module Rbexy module Refinements module Array module InsertBetweenTypes refine ::Array do def insert_between_types(type1, type2, &block) map.with_index do |curr, i| prev_i = i - 1 if prev_i >= 0 && InsertBetweenTypes.one_of_each_type?([self[prev_i], ...
github
patbenatar/rbexy
https://github.com/patbenatar/rbexy
lib/rbexy/nodes/expression.rb
Ruby
mit
49
master
224
module Rbexy module Nodes class Expression < AbstractNode attr_accessor :content def initialize(content) @content = content end def compile content end end end end
github
patbenatar/rbexy
https://github.com/patbenatar/rbexy
lib/rbexy/nodes/abstract_element.rb
Ruby
mit
49
master
274
module Rbexy module Nodes class AbstractElement < AbstractNode attr_accessor :name, :members, :children def initialize(name, members, children) @name = name @members = members || [] @children = children end end end end
github
patbenatar/rbexy
https://github.com/patbenatar/rbexy
lib/rbexy/nodes/root.rb
Ruby
mit
49
master
361
module Rbexy module Nodes class Root < AbstractNode attr_accessor :children def initialize(children) @children = children end def precompile Root.new(compact(children.map(&:precompile).flatten)) end def compile "#{children.map(&:compile).join}@output_...
github
patbenatar/rbexy
https://github.com/patbenatar/rbexy
lib/rbexy/nodes/html_element.rb
Ruby
mit
49
master
1,209
module Rbexy module Nodes class HTMLElement < AbstractElement # Referenced from https://html.spec.whatwg.org/#void-elements HTML_VOID_ELEMENTS = %w(area base br col embed hr img input link meta source track wbr) def precompile nodes = [] if void? && children.length == 0 ...
github
patbenatar/rbexy
https://github.com/patbenatar/rbexy
lib/rbexy/nodes/raw.rb
Ruby
mit
49
master
462
module Rbexy module Nodes class Raw < AbstractNode attr_reader :content, :template OUTPUT = "@output_buffer.safe_concat('%s'.freeze);" EXPR_STRING = "'%s'.html_safe.freeze" def initialize(content, template: OUTPUT) @content = content @template = template end ...
github
patbenatar/rbexy
https://github.com/patbenatar/rbexy
lib/rbexy/nodes/declaration.rb
Ruby
mit
49
master
259
module Rbexy module Nodes class Declaration < AbstractNode attr_accessor :content def initialize(content) @content = content end def precompile [Raw.new(Util.escape_string(content))] end end end end
github
patbenatar/rbexy
https://github.com/patbenatar/rbexy
lib/rbexy/nodes/component_element.rb
Ruby
mit
49
master
1,851
module Rbexy module Nodes class ComponentElement < AbstractElement attr_reader :template OUTPUT = "@output_buffer.safe_concat(%s);" EXPR_STRING = "%s.html_safe" def initialize(*args, template: OUTPUT) super(*args) @template = template end def precompile ...