repo_name
stringlengths
6
97
path
stringlengths
3
341
text
stringlengths
8
1.02M
boost/consyncful
lib/consyncful.rb
# frozen_string_literal: true require 'consyncful/version' require 'mongoid' require 'contentful' require 'consyncful/base' require 'consyncful/sync' require 'consyncful/railtie' if defined?(Rails) module Consyncful # Handles Rails configurations for Consynful class Configuration attr_accessor :contentful_...
boost/consyncful
spec/consyncful/persisted_item_spec.rb
<reponame>boost/consyncful<gh_stars>1-10 # frozen_string_literal: true require 'spec_helper' RSpec.describe Consyncful::PersistedItem do let(:stats) { instance_double('Consyncful::Stats') } let(:sync_id) { rand(100..200) } let(:persisted_item) { Consyncful::PersistedItem.new(item, sync_id, stats) } context '...
boost/consyncful
spec/consyncful/base_spec.rb
# frozen_string_literal: true require 'spec_helper' RSpec.describe Consyncful::Base do class self::TestContentfulType < Consyncful::Base contentful_model_name 'fooBar' references_many :foos references_one :bar end class self::TestContentfulType2 < Consyncful::Base contentful_model_name 'Baz' ...
boost/consyncful
lib/consyncful/base.rb
<gh_stars>1-10 # frozen_string_literal: true module Consyncful ## # Provides common functionality of Mongoid models created from contentful # entries class Base include Mongoid::Document include Mongoid::Attributes::Dynamic cattr_accessor :model_map store_in collection: -> { Consyncful.config...
boost/consyncful
spec/consyncful/item_mapper_spec.rb
# frozen_string_literal: true require 'spec_helper' RSpec.describe Consyncful::ItemMapper do let(:entry_json) do { 'sys' => { 'space' => { 'sys' => { 'type' => 'Link', 'linkType' => 'Space', 'id' => 'spaceId' } }, 'id' => 'itemID', 'type' => 'Entry', 'createdAt' => '2019-02...
boost/consyncful
lib/consyncful/sync.rb
<filename>lib/consyncful/sync.rb # frozen_string_literal: true require 'rainbow' require 'consyncful/item_mapper' require 'consyncful/persisted_item' require 'consyncful/stats' require 'hooks' module Consyncful ## # A mongoid model that stores the state of a syncronisation feed. Stores the # next URL provided b...
boost/consyncful
lib/consyncful/persisted_item.rb
# frozen_string_literal: true module Consyncful ## # Takes a mapped item from Contentful and creates/updates/deletes # the relevant model in the local database. class PersistedItem DEFAULT_LOCALE = 'en-NZ' def initialize(item, sync_id, stats) @item = item @sync_id = sync_id @stats = ...
boost/consyncful
lib/consyncful/version.rb
<filename>lib/consyncful/version.rb # frozen_string_literal: true module Consyncful VERSION = '0.6.1' end
boost/consyncful
lib/consyncful/railtie.rb
# frozen_string_literal: true # Adds Consyncful task to Rails class Consyncful::Railtie < Rails::Railtie rake_tasks do load 'consyncful/tasks/consyncful.rake' end end
boost/consyncful
spec/consyncful/sync_spec.rb
<gh_stars>1-10 # frozen_string_literal: true require 'spec_helper' RSpec.describe Consyncful::Sync do describe '.drop_stale' do let(:sync1) { Consyncful::Sync.create } let(:sync2) { Consyncful::Sync.create } let!(:record1) { Consyncful::Base.create(sync_id: sync1.id) } let!(:record2) { Consyncful::B...
zhaozixiao/rubyMe
todoItems/app/graphql/todo_items_schema.rb
<reponame>zhaozixiao/rubyMe<gh_stars>0 class TodoItemsSchema < GraphQL::Schema mutation(Types::MutationType) query(Types::QueryType) # For batch-loading (see https://graphql-ruby.org/dataloader/overview.html) use GraphQL::Dataloader # GraphQL-Ruby calls this when something goes wrong while running a query: ...
zhaozixiao/rubyMe
todoItems/app/graphql/types/mutation_type.rb
module Types class MutationType < Types::BaseObject field :create_todo, mutation: Mutations::CreateTodo field :update_todo, mutation: Mutations::UpdateTodo field :create_user, mutation: Mutations::CreateUser field :signin_user, mutation: Mutations::SignInUser end end
zhaozixiao/rubyMe
todoItems/app/graphql/mutations/update_todo.rb
<reponame>zhaozixiao/rubyMe<gh_stars>0 require 'time' module Mutations class UpdateTodo < BaseMutation # arguments passed to the `resolve` method argument :user, String, required: true argument :id, ID, required: true argument :description, String, required: false argument :status, String, requir...
zhaozixiao/rubyMe
todoItems/db/migrate/20211213064402_add_status_to_todos.rb
<reponame>zhaozixiao/rubyMe class AddStatusToTodos < ActiveRecord::Migration[6.1] def change execute <<-SQL CREATE TYPE todo_status AS ENUM ('ACTIVE', 'COMPLETE', 'DELETED'); SQL add_column :todos, :status, :todo_status, null: false, default: "ACTIVE" end end
zhaozixiao/rubyMe
todoItems/app/graphql/types/query_type.rb
<reponame>zhaozixiao/rubyMe<gh_stars>0 module Types class QueryType < Types::BaseObject # Add `node(id: ID!) and `nodes(ids: [ID!]!)` include GraphQL::Types::Relay::HasNodeField include GraphQL::Types::Relay::HasNodesField # Add root-level fields here. # They will be entry points for queries on y...
zhaozixiao/rubyMe
todoItems/app/graphql/mutations/create_todo.rb
module Mutations class CreateTodo < BaseMutation # arguments passed to the `resolve` method argument :description, String, required: true argument :reference, String, required: true # return type from the mutation type Types::TodoType def resolve(description: nil, reference: nil) Todo....
zhaozixiao/rubyMe
todoItems/db/migrate/20211213071401_add_meta_data_to_todos.rb
class AddMetaDataToTodos < ActiveRecord::Migration[6.1] def change add_column :todos, :created_by, :string add_column :todos, :updated_by, :string add_column :todos, :deleted_at, :timestamp add_column :todos, :deleted_by, :string end end
zhaozixiao/rubyMe
todoItems/app/graphql/types/todo_type.rb
<gh_stars>0 module Types class TodoType < Types::BaseObject field :id, ID, null: false field :description, String, null: false field :reference, String, null: false field :status, String, null: false end end
zhaozixiao/rubyMe
todoItems/app/models/todo.rb
<reponame>zhaozixiao/rubyMe<filename>todoItems/app/models/todo.rb class Todo < ApplicationRecord enum status: { active: "ACTIVE", complete: "COMPLETE", deleted: "DELETED" } end
shem8/jekyll-seo-script
jekyll-seo.rb
<gh_stars>10-100 #!/usr/bin/env ruby # Purpose: A simple script to identify SEO problems in jekyll blog posts # License: http://github.com/bhardin/jekyll-seo/license.txt require 'optparse' require 'nokogiri' heading = []; title = []; url = []; content = []; meta_description = []; temp = []; options = {} optparse = ...
unindented/unindented-rails
spec/lib/kramdown_processor_spec.rb
describe KramdownProcessor do subject do KramdownProcessor.new(enable_coderay: false) end describe '#process' do it 'converts a bunch of Markdown to HTML' do body = Capybara.string(subject.process(<<-eos # Foo eos )) expect(body).to have_xpath('//h1') end it 'recognizes ...
unindented/unindented-rails
lib/kramdown_processor.rb
<reponame>unindented/unindented-rails<gh_stars>0 require 'kramdown' class KramdownProcessor DEFAULT_OPTS = { } def initialize(opts = {}) @opts = DEFAULT_OPTS.merge(opts) end def process(str) convert_to_html(fix_fenced_blocks(str)) end private def fix_fenced_blocks(str) str.gsub(/^```/,...
unindented/unindented-rails
spec/decorators/tags_decorator_spec.rb
describe TagsDecorator do describe '#cloud_list' do it 'generates a tag cloud' do tags = FactoryGirl.create_list(:tag, 2) contents = FactoryGirl.create_list(:content, 2) contents.each_with_index do |content, index| content.tags << tags[index % tags.length] end cloud = T...
unindented/unindented-rails
db/migrate/20131201000001_create_contents.rb
<filename>db/migrate/20131201000001_create_contents.rb class CreateContents < ActiveRecord::Migration def change create_table :contents do |t| t.string :title, null: false t.string :author t.boolean :published, null: false, default: true t.boolean :featured, null: false...
unindented/unindented-rails
app/controllers/feeds_controller.rb
class FeedsController < ApplicationController respond_to :atom, :tile def show @contents = Content .categorized([:articles, :experiments]) .includes(:tags) .limit(6) .decorate respond_with @contents end end
unindented/unindented-rails
spec/models/extension_spec.rb
describe Extension do describe '#valid?' do it 'fails with no name' do expect(FactoryGirl.build(:extension, name: nil)).to have(1).error_on(:name) end it 'fails with duplicate name' do extension = FactoryGirl.create(:extension) expect(FactoryGirl.build(:extension, name: extension.name)...
unindented/unindented-rails
app/models/content_tag.rb
class ContentTag < ActiveRecord::Base belongs_to :content belongs_to :tag end
unindented/unindented-rails
features/support/env.rb
require 'simplecov' require 'cucumber/rails' require 'rspec/expectations' ActionController::Base.allow_rescue = false DatabaseCleaner.strategy = :transaction Cucumber::Rails::Database.javascript_strategy = :truncation Capybara.javascript_driver = :poltergeist
unindented/unindented-rails
spec/routing/articles_routing_spec.rb
describe ArticlesController do describe 'routing' do it 'routes `/articles` to #show' do expect(get '/articles/').to route_to('articles#show') end it 'routes `/articles/2013` to #show' do expect(get '/articles/2013/').to route_to( 'articles#show', year: '2013') end it 'route...
unindented/unindented-rails
lib/tasks/build.rake
require 'open3' namespace :build do desc 'Generate a mirror of the site' task :mirror => :environment do env = Rails.env port = SETTINGS.build.port rails_cmd = "RAILS_ENV=#{env} rails server --port #{port}" rm_cmd = "rm -rf build/localhost:#{port}/" wget_cmd = "wget --content-on-...
unindented/unindented-rails
app/models/extension.rb
<reponame>unindented/unindented-rails class Extension < ActiveRecord::Base default_scope { order(:name) } has_many :content_extensions has_many :contents, through: :content_extensions validates :name, presence: true, uniqueness: true before_save :update_locator def to_param self.locator end pr...
unindented/unindented-rails
lib/tasks/contents.rake
require 'content_loader' namespace :contents do desc 'Load all contents into the database' task :load => :environment do src = Rails.root.join('contents').to_s ContentLoader.new.load(src) end desc 'Reset the contents of the database' task :reset => ['db:migrate', 'db:reset', 'contents:load'] end de...
unindented/unindented-rails
app/views/feeds/show.tile.builder
tile_feed do |feed| feed.binding(template: 'TileSquare150x150Text04', fallback: 'TileSquareImage') do content = @contents.first feed.text(content.title, id: '1') end if @contents.length > 0 feed.binding(template: 'TileWide310x150Text09', fallback: 'TileWideImage') do content = @contents.first fee...
unindented/unindented-rails
config/locales/en.rb
<filename>config/locales/en.rb { en: { date: { formats: { year: "%Y", month: "%B, %Y", day: lambda { |date, _| "%B #{date.day.ordinalize}, %Y" } } } } }
unindented/unindented-rails
spec/factories/extensions.rb
FactoryGirl.define do sequence :extension_name do |n| "extension#{n}" end factory(:extension) do name { FactoryGirl.generate(:extension_name) } end end
unindented/unindented-rails
config/environments/development.rb
<reponame>unindented/unindented-rails Rails.application.configure do config.cache_classes = false config.eager_load = false config.assets.debug = false config.consider_all_requests_local = true config.action_controller.perform_caching = false config.action_controller.default_url_options = { trai...
unindented/unindented-rails
db/migrate/20131201000002_create_tags.rb
<filename>db/migrate/20131201000002_create_tags.rb class CreateTags < ActiveRecord::Migration def change create_table :tags do |t| t.string :name, null: false t.string :locator, null: false, index: true end end end
unindented/unindented-rails
config/initializers/i18n.rb
module I18n class JustRaiseExceptionHandler < ExceptionHandler def call(exception, locale, key, options) if exception.is_a?(MissingTranslation) && key.to_s != 'i18n.plural.rule' raise exception.to_exception else super end end end end I18n.exception_handler = I18n::JustRais...
unindented/unindented-rails
app/models/content_extension.rb
<filename>app/models/content_extension.rb class ContentExtension < ActiveRecord::Base belongs_to :content belongs_to :extension end
unindented/unindented-rails
app/controllers/archives_controller.rb
class ArchivesController < ApplicationController respond_to :html def show category = controller_name info = params.slice(:year, :month, :day).merge(category: category) page = params[:page] @date = PartialDate.new(info) .decorate @contents = Content .categorized(category) ...
unindented/unindented-rails
config/routes.rb
Rails.application.routes.draw do archive_constraint = { year: /\d{4}/, month: /\d{2}/, day: /\d{2}/, page: /\d+/ } filename_constraint = { filename: /.+\.[a-z]+/ } root to: 'home#show' resource :feed, only: [:show] resource :articles, only: [:show], format: false do get '(:year(/:month(/:day)))(/page...
unindented/unindented-rails
spec/factories/partial_dates.rb
FactoryGirl.define do factory(:partial_date) do ignore do date { Date.today - Random.rand(3333) } end category { %w{articles experiments}[Random.rand(2)] } year { date.year } end end
unindented/unindented-rails
spec/decorators/contents_decorator_spec.rb
<gh_stars>0 describe ContentsDecorator do let!(:contents) { FactoryGirl.create_list(:content, 3) } describe '#title' do it 'returns the title of the site' do feed = Content.all.decorate expect(feed.title).to eq(helpers.title_text) end end describe '#author' do it 'returns the subtitle...
unindented/unindented-rails
app/models/partial_date.rb
<reponame>unindented/unindented-rails<filename>app/models/partial_date.rb class PartialDate include ActiveAttr::Model attribute :category, type: String attribute :year, type: Integer attribute :month, type: Integer attribute :day, type: Integer validates :category, :year, presence: true def...
unindented/unindented-rails
lib/content_loader.rb
class ContentLoader def load(folder) Dir.chdir(Rails.root.join(folder)) do Dir.glob('**/index.metadata') do |filename| Content.create!(extract_data(filename)) end end end private def extract_data(filename) [ :extract_data_from_filename!, :extract_data_from_yaml!, ...
unindented/unindented-rails
config/environments/production.rb
Rails.application.configure do config.cache_classes = true config.eager_load = true config.serve_static_assets = true config.static_cache_control = "public, max-age=#{1.year.to_i}" config.assets.js_compressor = :uglifier config.assets.css_compressor = :sass config.assets.compile = true config.as...
unindented/unindented-rails
app/models/concerns/processable.rb
module Processable extend ActiveSupport::Concern included do processor = BodyProcessor.new({ kramdown: SETTINGS.processors.kramdown_as_a_hash.deep_symbolize_keys, nokogiri: SETTINGS.processors.nokogiri_as_a_hash.deep_symbolize_keys, pygments: SETTINGS.processors.pygments_as_a_hash.deep_symbol...
unindented/unindented-rails
app/helpers/application_helper.rb
module ApplicationHelper extend TextHelper extend LinkHelper extend MetaHelper extend MicrosoftHelper extend TwitterHelper extend ScriptHelper end
unindented/unindented-rails
app/decorators/tags_decorator.rb
<filename>app/decorators/tags_decorator.rb class TagsDecorator < CollectionDecorator delegate :current_page, :total_pages, :limit_value def cloud_list(classes = %w{s m l}) return if length == 0 max = max_by(&:count) items = reduce('') do |memo, tag| index = ((classes.size - 1.0) * tag.count / ma...
unindented/unindented-rails
app/controllers/tags_controller.rb
<gh_stars>0 class TagsController < ApplicationController respond_to :html def index @tags = Tag .counts .decorate respond_with @tags, layout: 'tags' end def show locator = params[:locator] page = params[:page] @tag = Tag .find_by!(locator: locator) .decorate ...
unindented/unindented-rails
spec/controllers/feeds_controller_spec.rb
<gh_stars>0 describe FeedsController do describe 'GET show :atom' do context 'without contents' do it 'has a 200 status code' do get :show, format: :atom expect(response.status).to eq(200) end end context 'with contents' do let!(:contents) { FactoryGirl.create_list(:con...
unindented/unindented-rails
app/controllers/articles_controller.rb
<reponame>unindented/unindented-rails<filename>app/controllers/articles_controller.rb class ArticlesController < ArchivesController end
unindented/unindented-rails
app/models/tag.rb
class Tag < ActiveRecord::Base default_scope { order(:name) } has_many :content_tags has_many :contents, through: :content_tags validates :name, presence: true, uniqueness: true before_save :update_locator def self.counts select(['tags.*', 'count(content_tags.tag_id) as count']) .joins(:conte...
unindented/unindented-rails
app/controllers/application_controller.rb
class ApplicationController < ActionController::Base protect_from_forgery rescue_from ActiveRecord::RecordNotFound, with: :render_404 rescue_from Errno::ENOENT, with: :render_404 def render_404 respond_to do |format| format.html { render 'errors/404', layout: 'errors', status: :not_fo...
unindented/unindented-rails
app/helpers/text_helper.rb
<filename>app/helpers/text_helper.rb module TextHelper def host_text SETTINGS.host end def website_text SETTINGS.website end def author_text SETTINGS.author end def email_text SETTINGS.email end def twitter_text SETTINGS.twitter end def github_text SETTINGS.github e...
unindented/unindented-rails
spec/lib/body_processor_spec.rb
describe BodyProcessor do subject do BodyProcessor.new( kramdown: { enable_coderay: false }, nokogiri: { css: 'table' }, pygments: { misc: { cssclass: 'highlighted' } } ) end describe '#process' do it 'processes the body of a content' do body = Capybara.string(subject.process...
unindented/unindented-rails
config/initializers/session_store.rb
Rails.application.config.session_store :cookie_store, key: '_website_session'
unindented/unindented-rails
spec/routing/home_routing_spec.rb
describe HomeController do describe 'routing' do it 'routes `/` to #show' do expect(get '/').to route_to('home#show') end end describe 'named routes' do it 'routes `root_path` to #show' do expect(get root_path).to route_to('home#show') end end end
unindented/unindented-rails
db/schema.rb
# encoding: UTF-8 # This file is auto-generated from the current state of the database. Instead # of editing this file, please use the migrations feature of Active Record to # incrementally modify your database, and then regenerate this schema definition. # # Note that this schema.rb definition is the authoritative sou...
unindented/unindented-rails
app/models/concerns/taggable.rb
<reponame>unindented/unindented-rails<filename>app/models/concerns/taggable.rb module Taggable extend ActiveSupport::Concern included do has_many :content_tags has_many :tags, through: :content_tags end def tags_list self.tags.map(&:name) end def tags_list=(names) self.tags = (names || []...
unindented/unindented-rails
app/helpers/link_helper.rb
<reponame>unindented/unindented-rails module LinkHelper def email_link(text = email_text, opts = {}) link_to(text, email_url(email_text, opts)) end def github_link(text = "@#{github_text}", opts = {}) link_to(text, github_url(github_text, opts)) end def twitter_link(text = "@#{twitter_text}", opts ...
unindented/unindented-rails
spec/decorators/partial_date_decorator_spec.rb
<reponame>unindented/unindented-rails<gh_stars>0 describe PartialDateDecorator do describe '#localize' do it 'returns a year' do date = FactoryGirl.build(:partial_date, year: 2013).decorate expect(date.localize).to eq('2013') end it 'returns a year and a month' do date = FactoryGirl.bu...
unindented/unindented-rails
lib/icon_generator.rb
<gh_stars>0 class IconGenerator def ico(png, options = {}) options[:sizes].each do |name, size| ico = yield(name, options) convert_with_image_magick(png, ico, size) end end def png(svg, options = {}) options[:sizes].each do |name, size| png = yield(name, options) convert_with...
unindented/unindented-rails
config/initializers/mime_types.rb
<reponame>unindented/unindented-rails Mime::Type.register('image/svg+xml', :svg) unless Mime::Type.lookup_by_extension(:svg)
unindented/unindented-rails
features/step_definitions/common_steps.rb
Transform /^(\d+)$/ do |number| number.to_i end Transform(/^table:.+$/) do |table| table.map_headers! do |header| header.underscore.to_sym end table.map_column!(:tags, false) do |tags| tags.split(/\s*,\s*/).map do |tag_name| Tag.find_or_create_by!(name: tag_name) end end table.map_column!...
unindented/unindented-rails
spec/models/partial_date_spec.rb
describe PartialDate do describe '#valid?' do it 'fails with no category' do expect(FactoryGirl.build(:partial_date, category: nil)).to have(1).error_on(:category) end it 'fails with no year' do expect(FactoryGirl.build(:partial_date, year: nil)).to have(1).error_on(:year) end end d...
unindented/unindented-rails
app/decorators/partial_date_decorator.rb
<gh_stars>0 class PartialDateDecorator < ModelDecorator delegate_all def localize array = to_a format = [:year, :month, :day][array.length - 1] l(Date.new(*array), format: format) end def route convert_to_route(to_a) end def parent_route convert_to_route(to_a[0...-1]) end privat...
unindented/unindented-rails
spec/helpers/url_helper_spec.rb
<gh_stars>0 describe UrlHelper do describe '#absolute_url' do before { allow(SETTINGS).to receive(:host) { 'http://www.foo.com' } } it 'returns the absolute URL for the specified path' do url = helper.absolute_url('/bar') expect(url).to eq('http://www.foo.com/bar') end end describe '#cu...
unindented/unindented-rails
spec/lib/nokogiri_processor_spec.rb
<filename>spec/lib/nokogiri_processor_spec.rb describe NokogiriProcessor do let(:html) do <<-eos <h1>Foo</h1> eos end context 'with a CSS selector' do subject do NokogiriProcessor.new(css: 'h1') do |nodes| nodes.wrap '<div class="header"></div>' end end describe '#proce...
unindented/unindented-rails
lib/tasks/cucumber.rake
<gh_stars>0 unless ARGV.any? {|a| a =~ /^gems/} vendored_cucumber_bin = Dir["#{Rails.root}/vendor/{gems,plugins}/cucumber*/bin/cucumber"].first $LOAD_PATH.unshift(File.dirname(vendored_cucumber_bin) + '/../lib') unless vendored_cucumber_bin.nil? begin require 'cucumber/rake/task' namespace :cucumber do Cucum...
unindented/unindented-rails
app/decorators/model_decorator.rb
class ModelDecorator < Draper::Decorator include Draper::LazyHelpers end
unindented/unindented-rails
spec/models/content_spec.rb
describe Content do describe '#valid?' do it 'fails with no title' do expect(FactoryGirl.build(:content, title: nil)).to have(1).error_on(:title) end it 'fails with no body' do expect(FactoryGirl.build(:content, body: nil)).to have(1).error_on(:body) end it 'fails with no path' do ...
unindented/unindented-rails
app/helpers/url_helper.rb
<reponame>unindented/unindented-rails module UrlHelper def absolute_url(path, opts = {}) url_with_params("#{host_text}#{path}", opts) end def current_url(opts = {}) url_with_params("#{host_text}#{request.original_fullpath}", opts) end def email_url(email = email_text, opts = {}) url_with_params...
unindented/unindented-rails
spec/routing/experiments_routing_spec.rb
describe ExperimentsController do describe 'routing' do it 'routes `/experiments` to #show' do expect(get '/experiments/').to route_to('experiments#show') end it 'routes `/experiments/2013` to #show' do expect(get '/experiments/2013/').to route_to( 'experiments#show', year: '2013') ...
unindented/unindented-rails
app/helpers/twitter_helper.rb
module TwitterHelper def twitter_card_meta_tag(name, value, options = {}) tag(:meta, { name: "twitter:#{name}", content: value }.merge!(options.symbolize_keys)) end end
unindented/unindented-rails
lib/body_processor.rb
<filename>lib/body_processor.rb require 'kramdown_processor' require 'nokogiri_processor' require 'pygments_processor' class BodyProcessor def initialize(opts = {}) @kramdown = KramdownProcessor.new(opts[:kramdown]) @nokogiri = NokogiriProcessor.new(opts[:nokogiri]) do |nodes| nodes.wrap '<div class="...
unindented/unindented-rails
spec/rails_helper.rb
ENV['RAILS_ENV'] ||= 'test' require 'simplecov' require 'spec_helper' require File.expand_path('../../config/environment', __FILE__) require 'rspec/rails' require 'capybara/rails' require 'capybara/rspec' Capybara.javascript_driver = :poltergeist Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f } ...
unindented/unindented-rails
lib/body_summarizer.rb
<reponame>unindented/unindented-rails require 'nokogiri' class BodySummarizer DEFAULT_OPTS = { xpath: './/p', range: 0...2 } def initialize(opts = {}) @opts = DEFAULT_OPTS.merge(opts) end def summarize_text(html) summarize(html).map(&:text).join(' ') end def summarize_html(html) s...
unindented/unindented-rails
app/decorators/tag_decorator.rb
class TagDecorator < ModelDecorator delegate_all def route tag_path(self) end def parent_route tags_path end end
unindented/unindented-rails
config/initializers/settings.rb
config = RecursiveOpenStruct.new(YAML.load_file(Rails.root.join('config', 'settings.yml'))) SETTINGS = config.send(Rails.env)
unindented/unindented-rails
spec/models/content_extendable_spec.rb
describe Content do describe '#extensions_list' do let(:extensions) do extensions = [] extensions << FactoryGirl.build(:extension, name: 'Foo') extensions << FactoryGirl.build(:extension, name: 'Bar') end it 'returns an empty array when there are no extensions' do content = Facto...
unindented/unindented-rails
spec/helpers/meta_helper_spec.rb
<reponame>unindented/unindented-rails describe MetaHelper do describe '#humans_link_tag' do it 'returns a link to a `humans.txt` file' do link = Capybara.string(helper.humans_link_tag('/humans.txt')) expect(link).to have_xpath("//link[@rel='help']", visible: false) expect(link).to have_xpath("/...
unindented/unindented-rails
app/helpers/open_graph_helper.rb
<filename>app/helpers/open_graph_helper.rb module OpenGraphHelper def open_graph_meta_tag(name, value, options = {}) tag(:meta, { property: "og:#{name}", content: value }.merge!(options.symbolize_keys)) end end
unindented/unindented-rails
spec/decorators/tag_decorator_spec.rb
<gh_stars>0 describe TagDecorator do describe '#route' do it 'returns the route for the tag' do tag = FactoryGirl.create(:tag).decorate expect(tag.route).to eq(helpers.tag_path(tag.locator)) end end describe '#parent_route' do it 'returns the parent route for the tag' do tag = Fact...
unindented/unindented-rails
features/support/matchers/have_before.rb
<reponame>unindented/unindented-rails RSpec::Matchers.define(:have_before) do |earlier_content, later_content| match do |page| page.body.index(earlier_content) < page.body.index(later_content) end end
unindented/unindented-rails
app/helpers/script_helper.rb
<reponame>unindented/unindented-rails<gh_stars>0 module ScriptHelper def webfonts_script_tag config = content_tag(:script) do %Q{ var WebFontConfig = #{webfonts_config}; }.html_safe end library = javascript_include_tag(webfonts_url, async: true) (config + library).html_safe end ...
unindented/unindented-rails
app/models/content.rb
<reponame>unindented/unindented-rails class Content < ActiveRecord::Base include Taggable include Extendable include Processable include Summarizable paginates_per 6 default_scope -> { published.order(date: :desc, title: :asc) } scope :prioritized, -> { reorder(featured: :desc, date: :desc, title:...
unindented/unindented-rails
spec/controllers/errors_controller_spec.rb
<reponame>unindented/unindented-rails describe ErrorsController do describe 'GET show' do context 'with a 404 error' do it 'has a 200 status code' do get :show, error: '404' expect(response.status).to eq(200) end end context 'with a 500 error' do it 'has a 200 status co...
unindented/unindented-rails
app/controllers/home_controller.rb
<gh_stars>0 class HomeController < ApplicationController respond_to :html def show @about = Content .find_by!(locator: 'about') .decorate @contents = Content .categorized([:articles, :experiments]) .prioritized .limit(6) .decorate respond_with @contents, layout: 'ho...
unindented/unindented-rails
spec/lib/body_summarizer_spec.rb
describe BodySummarizer do let(:html) do <<-eos <h1>Foo</h1> <p>Bar</p> <p>Baz</p> <p>Qux</p> eos end context 'without options' do subject do BodySummarizer.new end describe '#summarize_text' do it 'extracts the text from the first two paragraphs' do abstract = subject....
unindented/unindented-rails
spec/models/tag_spec.rb
describe Tag do describe '.counts' do it 'returns the content count for each tag' do tags = FactoryGirl.create_list(:tag, 2) contents = FactoryGirl.create_list(:content, 2) contents.first.tags << [tags.first] contents.last.tags << [tags.first, tags.last] counts = Tag.counts.re...
unindented/unindented-rails
spec/helpers/microsoft_helper_spec.rb
describe MicrosoftHelper do describe '#msft_app_name_meta_tag' do it 'returns a Microsoft App meta tag with the application name' do meta = Capybara.string(helper.msft_app_name_meta_tag('FooBar')) expect(meta).to have_xpath("//meta[@name='application-name']", visible: false) expect(meta).to hav...
unindented/unindented-rails
app/decorators/collection_decorator.rb
class CollectionDecorator < Draper::CollectionDecorator include Draper::LazyHelpers end
unindented/unindented-rails
db/migrate/20131201000005_create_content_extensions.rb
<reponame>unindented/unindented-rails class CreateContentExtensions < ActiveRecord::Migration def change create_table :content_extensions do |t| t.belongs_to :content, null: false, index: true t.belongs_to :extension, null: false, index: true end end end
unindented/unindented-rails
app/helpers/microsoft_helper.rb
<reponame>unindented/unindented-rails module MicrosoftHelper def msft_app_name_meta_tag(name, options = {}) tag(:meta, { name: 'application-name', content: name }.merge!(options.symbolize_keys)) end def msft_app_config_meta_tag(path, options = {}) tag(:meta, { name: 'msapplic...
unindented/unindented-rails
spec/helpers/link_helper_spec.rb
<gh_stars>0 describe LinkHelper do describe '#email_link' do before { allow(SETTINGS).to receive(:email) { '<EMAIL>' } } context 'without text' do it 'returns a link with the configured email address' do link = Capybara.string(helper.email_link) expect(link).to have_xpath("//a[@href='m...
unindented/unindented-rails
app/helpers/meta_helper.rb
module MetaHelper def humans_link_tag(source, options = {}) tag(:link, { rel: 'help', type: 'text/plain', href: source }.merge!(options.symbolize_keys)) end def icon_link_tag(format, url_options = {}, tag_options = {}) tag(:link, { rel: 'icon', type: Mime::Type.lookup...
unindented/unindented-rails
spec/controllers/tags_controller_spec.rb
describe TagsController do describe 'GET index' do let!(:tags) { FactoryGirl.create_list(:tag, 2) } it 'has a 200 status code' do get :index expect(response.status).to eq(200) end end describe 'GET show' do let!(:tag) { FactoryGirl.create(:tag, name: 'FooBar') } context 'with i...
unindented/unindented-rails
app/models/concerns/extendable.rb
<gh_stars>0 module Extendable extend ActiveSupport::Concern included do has_many :content_extensions has_many :extensions, through: :content_extensions end def extensions_list self.extensions.map(&:name) end def extensions_list=(names) self.extensions = (names || []).map { |name| Extensio...
unindented/unindented-rails
lib/nokogiri_processor.rb
require 'nokogiri' class NokogiriProcessor DEFAULT_OPTS = { } def initialize(opts = {}, &block) @opts = DEFAULT_OPTS.merge(opts).select { |key, value| [:css, :xpath].include?(key) } @block = block end def process(str) doc = ::Nokogiri::HTML::DocumentFragment.parse(str) @block.call(doc.css...