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
mizzy/specinfra
https://github.com/mizzy/specinfra
lib/specinfra/helper/detect_os/redhat.rb
Ruby
mit
300
master
980
class Specinfra::Helper::DetectOs::Redhat < Specinfra::Helper::DetectOs def detect # Fedora also has an /etc/redhat-release so the Fedora check must # come before the RedHat check if run_command('ls /etc/fedora-release').success? line = run_command('cat /etc/redhat-release').stdout if line =~ ...
github
mizzy/specinfra
https://github.com/mizzy/specinfra
lib/specinfra/helper/detect_os/clearlinux.rb
Ruby
mit
300
master
394
class Specinfra::Helper::DetectOs::Clearlinux < Specinfra::Helper::DetectOs def detect swupd_info = run_command('swupd info') if swupd_info.success? release = nil swupd_info.stdout.each_line do |line| release = line.gsub(/\s+/, '').split(':').last if line =~ /^Installed version:/ end...
github
mizzy/specinfra
https://github.com/mizzy/specinfra
lib/specinfra/helper/detect_os/plamo.rb
Ruby
mit
300
master
205
class Specinfra::Helper::DetectOs::Plamo < Specinfra::Helper::DetectOs def detect if run_command('ls /usr/lib/setup/Plamo-*').success? { :family => 'plamo', :release => nil } end end end
github
mizzy/specinfra
https://github.com/mizzy/specinfra
lib/specinfra/helper/detect_os/debian.rb
Ruby
mit
300
master
2,405
class Specinfra::Helper::DetectOs::Debian < Specinfra::Helper::DetectOs def detect if (debian_version = run_command('cat /etc/debian_version')) && debian_version.success? distro = nil release = nil codename = nil if (lsb_release = run_command("lsb_release -irc")) && lsb_release.success?...
github
mizzy/specinfra
https://github.com/mizzy/specinfra
lib/specinfra/helper/detect_os/guix.rb
Ruby
mit
300
master
290
class Specinfra::Helper::DetectOs::Guix < Specinfra::Helper::DetectOs def detect if run_command('ls /etc/os-release').success? line = run_command('cat /etc/os-release').stdout if line =~ /ID=guix/ { :family => 'guix', :release => nil } end end end end
github
mizzy/specinfra
https://github.com/mizzy/specinfra
lib/specinfra/helper/detect_os/esxi.rb
Ruby
mit
300
master
279
class Specinfra::Helper::DetectOs::Esxi < Specinfra::Helper::DetectOs def detect if run_command('vmware -v').success? line = run_command('vmware -v').stdout if line =~ /VMware ESXi (.*)/ { :family => 'esxi', :release => $1 } end end end end
github
mizzy/specinfra
https://github.com/mizzy/specinfra
lib/specinfra/helper/detect_os/photon.rb
Ruby
mit
300
master
406
class Specinfra::Helper::DetectOs::Photon < Specinfra::Helper::DetectOs def detect if run_command('ls /etc/os-release').success? line = run_command('cat /etc/os-release').stdout if line =~ /ID=photon/ family = 'photon' if line =~ /VERSION_ID=(\d+\.\d+|\d+)/ release = $1 ...
github
mizzy/specinfra
https://github.com/mizzy/specinfra
lib/specinfra/helper/detect_os/darwin.rb
Ruby
mit
300
master
327
class Specinfra::Helper::DetectOs::Darwin < Specinfra::Helper::DetectOs def detect if ( uname = run_command('uname -sr').stdout ) && uname =~ /Darwin/i if uname =~ /([\d.]+)$/ { :family => 'darwin', :release => $1 } else { :family => 'darwin', :release => nil } end end e...
github
mizzy/specinfra
https://github.com/mizzy/specinfra
lib/specinfra/helper/detect_os/aix.rb
Ruby
mit
300
master
389
class Specinfra::Helper::DetectOs::Aix < Specinfra::Helper::DetectOs def detect if run_command('uname -s').stdout =~ /AIX/i line = run_command('uname -rvp').stdout if line =~ /(\d+)\s+(\d+)\s+(.*)/ then { :family => 'aix', :release => "#{$2}.#{$1}", :arch => $3 } else { :family =...
github
mizzy/specinfra
https://github.com/mizzy/specinfra
lib/specinfra/helper/detect_os/coreos.rb
Ruby
mit
300
master
620
class Specinfra::Helper::DetectOs::Coreos < Specinfra::Helper::DetectOs def detect if run_command('ls /etc/coreos/update.conf').success? distro = nil release = nil lsb_release = run_command("cat /etc/lsb-release") if lsb_release.success? lsb_release.stdout.each_line do |line| ...
github
mizzy/specinfra
https://github.com/mizzy/specinfra
lib/specinfra/helper/detect_os/devuan.rb
Ruby
mit
300
master
806
class Specinfra::Helper::DetectOs::Devuan < Specinfra::Helper::DetectOs def detect if (devuan_version = run_command('cat /etc/devuan_version')) && devuan_version.success? distro = nil release = nil if (lsb_release = run_command("lsb_release -ir")) && lsb_release.success? lsb_release.std...
github
mizzy/specinfra
https://github.com/mizzy/specinfra
lib/specinfra/helper/detect_os/poky.rb
Ruby
mit
300
master
251
class Specinfra::Helper::DetectOs::Poky < Specinfra::Helper::DetectOs def detect if ( uname = run_command('uname -r').stdout ) && uname =~ /poky/i { :family => 'poky', :release => run_command('cat /etc/version').stdout } end end end
github
mizzy/specinfra
https://github.com/mizzy/specinfra
lib/specinfra/helper/detect_os/alpine.rb
Ruby
mit
300
master
270
class Specinfra::Helper::DetectOs::Alpine < Specinfra::Helper::DetectOs def detect if run_command('ls /etc/alpine-release').success? release = run_command('cat /etc/alpine-release').stdout { :family => 'alpine', :release => release } end end end
github
mizzy/specinfra
https://github.com/mizzy/specinfra
lib/specinfra/host_inventory/mount.rb
Ruby
mit
300
master
739
module Specinfra class HostInventory class Mount < Base def get cmd = backend.command.get(:get_inventory_mount) ret = backend.run_command(cmd) if ret.exit_status == 0 parse(ret.stdout) else nil end end def parse(ret) mounts = []...
github
mizzy/specinfra
https://github.com/mizzy/specinfra
lib/specinfra/host_inventory/fqdn.rb
Ruby
mit
300
master
305
module Specinfra class HostInventory class Fqdn < Base def get cmd = backend.command.get(:get_inventory_fqdn) result = backend.run_command(cmd) if result.exit_status == 0 result.stdout.strip else nil end end end end end
github
mizzy/specinfra
https://github.com/mizzy/specinfra
lib/specinfra/host_inventory/kernel.rb
Ruby
mit
300
master
692
module Specinfra class HostInventory class Kernel < Base def get kernel = {} kernel['machine'] = backend.os_info[:arch] cmd = backend.command.get(:get_inventory_kernel) ret = backend.run_command(cmd) if ret.exit_status == 0 kernel = kernel.merge(parse_uname...
github
mizzy/specinfra
https://github.com/mizzy/specinfra
lib/specinfra/host_inventory/cpu.rb
Ruby
mit
300
master
2,791
module Specinfra class HostInventory class Cpu < Base def get cmd = backend.command.get(:get_inventory_cpu) ret = backend.run_command(cmd) if ret.exit_status == 0 parse(ret.stdout) else nil end end def parse(cmd_ret) cpuinfo =...
github
mizzy/specinfra
https://github.com/mizzy/specinfra
lib/specinfra/host_inventory/hostname.rb
Ruby
mit
300
master
313
module Specinfra class HostInventory class Hostname < Base def get cmd = backend.command.get(:get_inventory_hostname) result = backend.run_command(cmd) if result.exit_status == 0 result.stdout.strip else nil end end end end end
github
mizzy/specinfra
https://github.com/mizzy/specinfra
lib/specinfra/host_inventory/filesystem.rb
Ruby
mit
300
master
858
module Specinfra class HostInventory class Filesystem < Base def get cmd = backend.command.get(:get_inventory_filesystem) ret = backend.run_command(cmd) if ret.exit_status == 0 parse(ret.stdout) else nil end end def parse(ret) f...
github
mizzy/specinfra
https://github.com/mizzy/specinfra
lib/specinfra/host_inventory/ohai.rb
Ruby
mit
300
master
394
module Specinfra class HostInventory class Ohai < Base def get begin require 'json' rescue LoadError return nil end begin ret = backend.run_command('ohai --log_level error') rescue StandardError nil end ret.exi...
github
mizzy/specinfra
https://github.com/mizzy/specinfra
lib/specinfra/host_inventory/user.rb
Ruby
mit
300
master
706
module Specinfra class HostInventory class User < Base def get cmd = backend.command.get(:get_inventory_user) ret = backend.run_command(cmd) if ret.exit_status == 0 parse(ret.stdout) else nil end end def parse(cmd_ret) users = ...
github
mizzy/specinfra
https://github.com/mizzy/specinfra
lib/specinfra/host_inventory/base.rb
Ruby
mit
300
master
222
module Specinfra class HostInventory class Base def initialize(host_inventory) @host_inventory = host_inventory end def backend @host_inventory.backend end end end end
github
mizzy/specinfra
https://github.com/mizzy/specinfra
lib/specinfra/host_inventory/block_device.rb
Ruby
mit
300
master
923
module Specinfra class HostInventory class BlockDevice < Base # examples: # /sys/block/sda/size 10000 # /sys/block/sr0/device/model CD-ROM BLOCK_DEVICE_REGEX = %r|\A/sys/block/(\w+)/(\w+)(?:/(\w+))?\t(.+)\z| def get cmd = backend.command.get(:get_inventory_block_device) ...
github
mizzy/specinfra
https://github.com/mizzy/specinfra
lib/specinfra/host_inventory/domain.rb
Ruby
mit
300
master
309
module Specinfra class HostInventory class Domain < Base def get cmd = backend.command.get(:get_inventory_domain) result = backend.run_command(cmd) if result.exit_status == 0 result.stdout.strip else nil end end end end end
github
mizzy/specinfra
https://github.com/mizzy/specinfra
lib/specinfra/host_inventory/virtualization.rb
Ruby
mit
300
master
1,519
module Specinfra class HostInventory class Virtualization < Base def get res = {} ## docker if backend.run_command('grep -Eqa \'docker(/|-[0-9a-f]+)\' /proc/1/cgroup||test -e /.dockerinit').success? res[:system] = 'docker' return res end ## OpenVZ...
github
mizzy/specinfra
https://github.com/mizzy/specinfra
lib/specinfra/host_inventory/group.rb
Ruby
mit
300
master
767
module Specinfra class HostInventory class Group < Base def get cmd = backend.command.get(:get_inventory_group) ret = backend.run_command(cmd) if ret.exit_status == 0 parse(ret.stdout) else nil end end def parse(cmd_ret) groups...
github
mizzy/specinfra
https://github.com/mizzy/specinfra
lib/specinfra/host_inventory/facter.rb
Ruby
mit
300
master
318
module Specinfra class HostInventory class Facter < Base require 'yaml' def get begin ret = backend.run_command('facter --puppet --yaml') rescue StandardError nil end ret.exit_status == 0 ? YAML.load(ret.stdout) : nil end end end end
github
mizzy/specinfra
https://github.com/mizzy/specinfra
lib/specinfra/host_inventory/memory.rb
Ruby
mit
300
master
3,191
module Specinfra class HostInventory class Memory < Base def get cmd = backend.command.get(:get_inventory_memory) ret = backend.run_command(cmd) if ret.exit_status == 0 parse(ret.stdout) else nil end end def parse(ret) memory = ...
github
mizzy/specinfra
https://github.com/mizzy/specinfra
lib/specinfra/backend/base.rb
Ruby
mit
300
master
1,225
require 'singleton' require 'specinfra/command_result' module Specinfra module Backend class Base def self.instance @instance ||= self.new end def self.clear @instance = nil end def initialize(config = {}) @config = config @example = nil end ...
github
mizzy/specinfra
https://github.com/mizzy/specinfra
lib/specinfra/backend/cmd.rb
Ruby
mit
300
master
2,373
require 'open3' module Specinfra module Backend class Cmd < Base include PowerShell::ScriptHelper def os_info { :family => 'windows', :release => nil, :arch => nil, :cygwin => `echo $0`.include?("sh") } end def run_command(cmd, opts={}) script = create_script(cmd) ...
github
mizzy/specinfra
https://github.com/mizzy/specinfra
lib/specinfra/backend/dockercli.rb
Ruby
mit
300
master
865
# frozen_string_literal: true module Specinfra module Backend # Docker command line transport class Dockercli < Exec def build_command(cmd) docker_cmd = %w[docker exec] docker_cmd << '--interactive' if get_config(:interactive_shell) docker_cmd << '--tty' if get_config(:request_p...
github
mizzy/specinfra
https://github.com/mizzy/specinfra
lib/specinfra/backend/docker.rb
Ruby
mit
300
master
3,908
module Specinfra module Backend class Docker < Exec def initialize(config = {}) super begin require 'docker' unless defined?(::Docker) rescue LoadError fail "Docker client library is not available. Try installing `docker-api' gem." end ::Docker.u...
github
mizzy/specinfra
https://github.com/mizzy/specinfra
lib/specinfra/backend/exec.rb
Ruby
mit
300
master
4,531
require 'singleton' require 'fileutils' require 'shellwords' require 'sfl' if Specinfra.ruby_is_older_than?(1, 9, 0) module Specinfra module Backend class Exec < Base def run_command(cmd, opts={}) cmd = build_command(cmd) cmd = add_pre_command(cmd) stdout, stderr, exit_status = with...
github
mizzy/specinfra
https://github.com/mizzy/specinfra
lib/specinfra/backend/winrm.rb
Ruby
mit
300
master
1,269
module Specinfra module Backend class Winrm < Base include PowerShell::ScriptHelper def os_info { :family => 'windows', :release => nil, :arch => nil } end def run_command(cmd, opts={}) script = create_script(cmd) winrm = get_config(:winrm) stdout, stderr...
github
mizzy/specinfra
https://github.com/mizzy/specinfra
lib/specinfra/backend/ssh.rb
Ruby
mit
300
master
5,297
# -*- coding: utf-8 -*- require 'specinfra/backend/exec' require 'net/ssh' require 'net/scp' module Specinfra module Backend class Ssh < Exec def run_command(cmd, opt={}) cmd = build_command(cmd) cmd = add_pre_command(cmd) if get_config(:ssh_without_env) ret = ssh_exec!(c...
github
mizzy/specinfra
https://github.com/mizzy/specinfra
lib/specinfra/backend/jexec.rb
Ruby
mit
300
master
1,136
module Specinfra module Backend class Jexec < Exec def initialize(config = {}) super(config) jname = get_config(:jail_name) jroot = `jls -j #{jname} path`.strip fail 'fail to get jail path!' if jroot.to_s.empty? set_config(:jail_root, jroot) end def send_...
github
mizzy/specinfra
https://github.com/mizzy/specinfra
lib/specinfra/backend/lxd.rb
Ruby
mit
300
master
1,055
# frozen_string_literal: true require 'singleton' require 'fileutils' require 'shellwords' require 'sfl' if Specinfra.ruby_is_older_than?(1, 9, 0) module Specinfra module Backend # LXD transport class Lxd < Exec def build_command(cmd) lxc_cmd = %W[lxc exec #{instance}] lxc_cmd << '-t' ...
github
mizzy/specinfra
https://github.com/mizzy/specinfra
lib/specinfra/backend/dockerfile.rb
Ruby
mit
300
master
672
module Specinfra module Backend class Dockerfile < Specinfra::Backend::Base def initialize(config = {}) super @lines = [] ObjectSpace.define_finalizer(self) { if get_config(:dockerfile_finalizer).nil? puts @lines else get_config(:dockerfil...
github
mizzy/specinfra
https://github.com/mizzy/specinfra
lib/specinfra/backend/lxc.rb
Ruby
mit
300
master
1,034
module Specinfra module Backend class Lxc < Exec def initialize(config = {}) super begin require 'lxc/extra' unless defined?(::LXC::Extra) rescue LoadError fail "LXC client library is not available. Try installing `lxc-extra' gem" end end def...
github
mizzy/specinfra
https://github.com/mizzy/specinfra
lib/specinfra/backend/telnet.rb
Ruby
mit
300
master
2,614
# -*- coding: utf-8 -*- require 'specinfra/backend/exec' require 'net/telnet' module Specinfra module Backend class Telnet < Exec def run_command(cmd, opt={}) cmd = build_command(cmd) cmd = add_pre_command(cmd) ret = with_env do telnet_exec!(cmd) end if @ex...
github
mizzy/specinfra
https://github.com/mizzy/specinfra
lib/specinfra/backend/shell_script.rb
Ruby
mit
300
master
512
require 'singleton' module Specinfra module Backend class ShellScript < Base def initialize(config = {}) super @lines = [ "#!/bin/sh", "" ] ObjectSpace.define_finalizer(self, Writer.new(@lines)) end def run_command(cmd, opts={}) @lines << cmd CommandRes...
github
mizzy/specinfra
https://github.com/mizzy/specinfra
lib/specinfra/backend/powershell/script_helper.rb
Ruby
mit
300
master
2,153
require 'base64' module Specinfra module Backend module PowerShell module ScriptHelper def build_command(cmd) path = get_config(:path) if path cmd.strip! cmd = <<-EOF $env:path = "#{path};$env:path" #{cmd} EOF end cmd end ...
github
mizzy/specinfra
https://github.com/mizzy/specinfra
lib/specinfra/backend/powershell/command.rb
Ruby
mit
300
master
870
module Specinfra module Backend module PowerShell class Command attr_reader :import_functions, :script def initialize &block @import_functions = [] @script = "" instance_eval(&block) if block_given? end def using *functions functions.e...
github
mizzy/specinfra
https://github.com/mizzy/specinfra
examples/multiple_backends.rb
Ruby
mit
300
master
1,471
require 'specinfra' require 'pp' a = Specinfra::Backend::Exec.new ssh_options = Net::SSH::Config.for(ENV['SSH_HOST'], [ENV['SSH_CONFIG']]) b = Specinfra::Backend::Ssh.new( :host => ssh_options[:host_name], :ssh_options => ssh_options, ) threads = [a, b].map do |backend| Thread.start(backend) do |backend| r...
github
ankane/vega-ruby
https://github.com/ankane/vega-ruby
vega.gemspec
Ruby
bsd-3-clause
300
master
547
require_relative "lib/vega/version" Gem::Specification.new do |spec| spec.name = "vega" spec.version = Vega::VERSION spec.summary = "Interactive charts for Ruby, powered by Vega and Vega-Lite" spec.homepage = "https://github.com/ankane/vega-ruby" spec.license = "BSD-3-Clause" ...
github
ankane/vega-ruby
https://github.com/ankane/vega-ruby
Rakefile
Ruby
bsd-3-clause
300
master
1,176
require "bundler/gem_tasks" require "rake/testtask" Rake::TestTask.new do |t| t.pattern = "test/**/*_test.rb" end task default: :test def download_package(name, version) require "fileutils" require "tmpdir" puts "Downloading #{name} #{version}" Dir.chdir(Dir.mktmpdir) do system "npm", "pack", "#{name}...
github
ankane/vega-ruby
https://github.com/ankane/vega-ruby
lib/vega.rb
Ruby
bsd-3-clause
300
master
784
# stdlib require "erb" require "json" require "securerandom" # modules require_relative "vega/method_helpers" require_relative "vega/base_chart" require_relative "vega/chart" require_relative "vega/lite_chart" require_relative "vega/spec" require_relative "vega/helper" require_relative "vega/version" # integrations r...
github
ankane/vega-ruby
https://github.com/ankane/vega-ruby
lib/vega/helper.rb
Ruby
bsd-3-clause
300
master
902
module Vega module Helper def vega_chart(chart, nonce: true) unless chart.is_a?(Vega::BaseChart) || chart.is_a?(Hash) raise TypeError, "expected Vega chart or spec" end if nonce == true # Secure Headers also defines content_security_policy_nonce but it takes an argument ...
github
ankane/vega-ruby
https://github.com/ankane/vega-ruby
lib/vega/chart.rb
Ruby
bsd-3-clause
300
master
729
module Vega class Chart < BaseChart # https://vega.github.io/vega/docs/specification/ scalar_methods \ :description, :background, :width, :height, :padding, :autosize, :title, :encode hash_methods \ :config, :usermeta array_methods \ :signals, :scales, :projections, :axes, :l...
github
ankane/vega-ruby
https://github.com/ankane/vega-ruby
lib/vega/engine.rb
Ruby
bsd-3-clause
300
master
463
module Vega class Engine < ::Rails::Engine # for assets # for importmap initializer "vega.importmap" do |app| if app.config.respond_to?(:assets) && defined?(Importmap) && defined?(Sprockets) app.config.assets.precompile << "vega-embed.js" app.config.assets.precompile << "vega-interp...
github
ankane/vega-ruby
https://github.com/ankane/vega-ruby
lib/vega/method_helpers.rb
Ruby
bsd-3-clause
300
master
931
module Vega module MethodHelpers private def scalar_methods(*methods) methods.each do |method| define_method("#{method}!") do |value| @spec[method] = value self end immutable_method(method) end end def hash_methods(*methods) methods.each ...
github
ankane/vega-ruby
https://github.com/ankane/vega-ruby
lib/vega/spec.rb
Ruby
bsd-3-clause
300
master
4,073
module Vega class Spec def initialize(spec) spec = spec.spec if spec.respond_to?(:spec) raise ArgumentError, "Expected Hash, not #{spec.class.name}" unless spec.is_a?(Hash) @spec = spec.transform_keys!(&:to_s) end def to_html(nonce: nil) html, js = generate_output nonce_html...
github
ankane/vega-ruby
https://github.com/ankane/vega-ruby
lib/vega/lite_chart.rb
Ruby
bsd-3-clause
300
master
917
module Vega class LiteChart < BaseChart # https://vega.github.io/vega-lite/docs/spec.html scalar_methods \ :background, :padding, :autosize, :title, :name, :description, :width, :height, :mark, :spec, :repeat hash_methods \ :config, :usermeta, :projection, :datasets, :encoding, :facet, :resol...
github
ankane/vega-ruby
https://github.com/ankane/vega-ruby
lib/vega/base_chart.rb
Ruby
bsd-3-clause
300
master
1,699
module Vega class BaseChart extend MethodHelpers def initialize @spec = { "$schema": @schema, width: "container", height: "container" # maybe add later # config: {mark: {tooltip: true}} } end def embed_options!(value) usermeta!(embedOptions: ...
github
ankane/vega-ruby
https://github.com/ankane/vega-ruby
test/chart_test.rb
Ruby
bsd-3-clause
300
master
3,531
require_relative "test_helper" class ChartTest < Minitest::Test def test_data_inline values = [{x: "A", y: 1}, {x: "B", y: 2}] expected = {values: values} assert_equal expected, Vega.lite.data(values).spec[:data] assert_equal expected, Vega.lite.data(values: values).spec[:data] end def test_data...
github
ankane/vega-ruby
https://github.com/ankane/vega-ruby
test/export_test.rb
Ruby
bsd-3-clause
300
master
974
require_relative "test_helper" class ExportTest < Minitest::Test def setup skip unless ENV["TEST_EXPORT"] end def test_to_png assert_match "\x89PNG".b, chart.to_png end def test_to_svg assert_match "<svg", chart.to_svg end def test_to_pdf assert_match "%PDF", chart.to_pdf end def ...
github
ankane/vega-ruby
https://github.com/ankane/vega-ruby
test/helper_test.rb
Ruby
bsd-3-clause
300
master
1,177
require_relative "test_helper" class HelperTest < Minitest::Test include Vega::Helper def test_chart assert_match "vegaEmbed", vega_chart(Vega.lite) end def test_spec assert_match "vegaEmbed", vega_chart(Vega.lite.spec) end def test_nonce_chart with_nonce do assert_match '<script nonce...
github
lokka/lokka
https://github.com/lokka/lokka
init.rb
Ruby
mit
300
main
214
# frozen_string_literal: true $LOAD_PATH.unshift File.dirname(__FILE__) $LOAD_PATH.unshift File.join(File.dirname(__FILE__), 'lib') require 'rubygems' require 'bundler' Bundler.setup require 'lokka' I18n.reload!
github
lokka/lokka
https://github.com/lokka/lokka
lokka.gemspec
Ruby
mit
300
main
1,263
# frozen_string_literal: true Gem::Specification.new do |s| s.name = 'lokka' s.version = '1.0.0' s.required_ruby_version = '>= 3.3' s.authors = ['Masaki KOMAGATA', 'Teppei Machida'] s.date = '2024-01-01' s.description = 'CMS written in Ruby for cloud computing.' s.email = 'komagata@gmail.com' s.execut...
github
lokka/lokka
https://github.com/lokka/lokka
Gemfile
Ruby
mit
300
main
997
# frozen_string_literal: true source 'https://rubygems.org' ruby '>= 3.2' gem 'activerecord', '~> 8.1' gem 'activesupport', '~> 8.1' gem 'aws-sdk-s3' gem 'builder' gem 'bundler' gem 'coderay' gem 'haml', '~> 6.0' gem 'kaminari', '~> 1.2' gem 'kaminari-activerecord' gem 'kramdown' gem 'marcel' gem 'nokogiri' gem 'padr...
github
lokka/lokka
https://github.com/lokka/lokka
Rakefile
Ruby
mit
300
main
1,860
# frozen_string_literal: true require './init' require 'rake/testtask' task default: ['test:setup', 'db:delete', :test] desc 'Migrate the Lokka database' task 'db:migrate' do puts 'Upgrading Database...' Lokka::Database.new.connect.migrate end desc 'Execute seed script' task 'db:seed' do puts 'Initializing Da...
github
lokka/lokka
https://github.com/lokka/lokka
lib/lokka.rb
Ruby
mit
300
main
3,631
# frozen_string_literal: true require 'rubygems' require 'pathname' require 'erb' require 'ostruct' require 'digest/sha1' require 'csv' module Lokka class NoTemplateError < StandardError; end class << self ## # Root directory. # # @return [String] path for lokka application root directory. de...
github
lokka/lokka
https://github.com/lokka/lokka
lib/lokka/app.rb
Ruby
mit
300
main
2,371
# frozen_string_literal: true require 'lokka' module Lokka class App < Sinatra::Base include Padrino::Helpers::TranslationHelpers configure :development do register Sinatra::Reloader end configure :development, :test do set :host_authorization, { permitted_hosts: [] } end conf...
github
lokka/lokka
https://github.com/lokka/lokka
lib/lokka/importer.rb
Ruby
mit
300
main
3,553
# frozen_string_literal: true module Lokka module Importer class WordPress DEFAULT_PASSWORD = 'test' def initialize(file) @file = file end def import doc = Nokogiri::XML(@file.read.gsub('', '')) doc.xpath('/rss/channel', 'content' => 'http://pur...
github
lokka/lokka
https://github.com/lokka/lokka
lib/lokka/database.rb
Ruby
mit
300
main
1,299
# frozen_string_literal: true module Lokka class Database MODELS = %w[site option user entry category comment snippet tag tagging field_name field].freeze def connect config = Lokka.database_config ActiveRecord::Base.establish_connection(config) self end def load_fixture(path, mod...
github
lokka/lokka
https://github.com/lokka/lokka
lib/lokka/before.rb
Ruby
mit
300
main
1,011
# frozen_string_literal: true module Lokka module Before def self.registered(app) app.before do @site = RequestStore[:site] ||= Site.first @title = @site.title locales = Lokka.parse_http(request.env['HTTP_ACCEPT_LANGUAGE']) locales.map! do |locale| locale =~ /-/ ?...
github
lokka/lokka
https://github.com/lokka/lokka
lib/lokka/migrator.rb
Ruby
mit
300
main
5,646
# frozen_string_literal: true require 'json' module Lokka # Migrates data from a legacy DataMapper-based Lokka database # to the new ActiveRecord schema using a two-step dump/import approach. # # Step 1 - Dump (run on old environment): # rake db:dump_dm SOURCE=path/to/old/database.sqlite3 # Produces d...
github
lokka/lokka
https://github.com/lokka/lokka
lib/lokka/kaminari_pager_adapter.rb
Ruby
mit
300
main
563
# frozen_string_literal: true # Compatibility layer for old DataMapper pager API # Used in templates like: @posts.pager.next_page module KaminariPagerAdapter class Pager def initialize(relation) @relation = relation end def next_page @relation.next_page end def previous_page @...
github
lokka/lokka
https://github.com/lokka/lokka
lib/lokka/models/markup.rb
Ruby
mit
300
main
994
# frozen_string_literal: true module Markup class << self attr_accessor :engine_list def use_engine(name, text) @engine_list.each do |engine| return engine[2].call(text).html_safe if engine[0] == name end text.html_safe end end @engine_list = [ ['html', 'HTML', ->(text...
github
lokka/lokka
https://github.com/lokka/lokka
lib/lokka/models/site.rb
Ruby
mit
300
main
726
# frozen_string_literal: true class Site < ActiveRecord::Base SORT_COLUMNS = %w[id created_at updated_at].freeze ORDERS = %w[asc desc].freeze def per_page super.presence || '10' end def default_sort super.presence || 'created_at' end def default_order super.presence || 'desc' end def ...
github
lokka/lokka
https://github.com/lokka/lokka
lib/lokka/models/option.rb
Ruby
mit
300
main
856
# frozen_string_literal: true class Option < ActiveRecord::Base self.primary_key = 'name' validates :name, presence: true def self.method_missing(method, *args) attribute = method.to_s # Only handle simple option names; delegate everything else to super return super unless attribute =~ /\A[a-z][a-...
github
lokka/lokka
https://github.com/lokka/lokka
lib/lokka/models/entry.rb
Ruby
mit
300
main
5,713
# frozen_string_literal: true class Entry < ActiveRecord::Base belongs_to :user belongs_to :category, optional: true has_many :comments, dependent: :destroy has_many :taggings, as: :taggable, dependent: :destroy has_many :tags, through: :taggings has_many :fields, dependent: :destroy validates :title, p...
github
lokka/lokka
https://github.com/lokka/lokka
lib/lokka/models/field_name.rb
Ruby
mit
300
main
472
# frozen_string_literal: true class FieldName < ActiveRecord::Base validates :name, presence: true, uniqueness: true validate :validate_if_entry_respond_to def self.get(id) find_by(id: id) end private def validate_if_entry_respond_to entry = Entry.new return unless entry.respond_to?(name, tr...
github
lokka/lokka
https://github.com/lokka/lokka
lib/lokka/models/tag.rb
Ruby
mit
300
main
324
# frozen_string_literal: true class Tag < ActiveRecord::Base has_many :taggings, dependent: :destroy validates :name, presence: true, uniqueness: true def link "/tags/#{name}/" end end ## # Retrieving Tag. # # @param [String] Tag name # @return [Tag] Tag instance def Tag(name) Tag.find_by(name: name) ...
github
lokka/lokka
https://github.com/lokka/lokka
lib/lokka/models/category.rb
Ruby
mit
300
main
1,026
# frozen_string_literal: true class Category < ActiveRecord::Base belongs_to :parent, class_name: 'Category', optional: true has_many :children, class_name: 'Category', foreign_key: :parent_id, dependent: :nullify has_many :entries validates :title, presence: true, uniqueness: true validates :slug, uniquene...
github
lokka/lokka
https://github.com/lokka/lokka
lib/lokka/models/user.rb
Ruby
mit
300
main
1,948
# frozen_string_literal: true class User < ActiveRecord::Base has_many :entries validates :name, presence: true, uniqueness: true, length: { in: 3..40 } validates :email, presence: true, uniqueness: true, length: { in: 5..40 }, format: { with: /\A[^@\s]+@[^@\s]+\z/ } validates :password, l...
github
lokka/lokka
https://github.com/lokka/lokka
lib/lokka/models/comment.rb
Ruby
mit
300
main
704
# frozen_string_literal: true class Comment < ActiveRecord::Base MODERATED = 0 APPROVED = 1 SPAM = 2 belongs_to :entry default_scope { order(created_at: :desc) } validates :name, presence: true validates :body, presence: true validates :email, format: { with: /\A[^@\s]*@?[^@\s]*\z/ }, allow_bl...
github
lokka/lokka
https://github.com/lokka/lokka
lib/lokka/models/snippet.rb
Ruby
mit
300
main
284
# frozen_string_literal: true class Snippet < ActiveRecord::Base validates :name, presence: true, uniqueness: true validates :body, presence: true def edit_link "/admin/#{self.class.to_s.tableize}/#{id}/edit" end end def Snippet(name) Snippet.find_by(name: name) end
github
lokka/lokka
https://github.com/lokka/lokka
lib/lokka/models/theme.rb
Ruby
mit
300
main
470
# frozen_string_literal: true class Theme attr_reader :name, :root_dir, :root_path, :dir, :path, :i18n_dir def initialize(root_dir, root_path) @root_dir = root_dir @root_path = "#{root_path}/theme" site = Site.first @name = site.theme @dir = "#{@root_dir}/#{@name}" @path = "#{@root_path}/#...
github
lokka/lokka
https://github.com/lokka/lokka
lib/lokka/helpers/render_helper.rb
Ruby
mit
300
main
1,408
# frozen_string_literal: true module Lokka module RenderHelper def render_detect(*names) render_detect_with_options(names) end def render_detect_with_options(names, options = {}) ret = '' options[:layout] = 'layout' names.each do |name| out = render_any(name, options) ...
github
lokka/lokka
https://github.com/lokka/lokka
lib/lokka/helpers/helpers.rb
Ruby
mit
300
main
12,937
# frozen_string_literal: true module Lokka module Helpers include Rack::Utils # Override padrino's localize to work with i18n 1.14+ keyword args def localize(object, **) I18n.localize(object, **) end alias l localize alias h escape_html # Mark string as safe for HTML output (no e...
github
lokka/lokka
https://github.com/lokka/lokka
lib/lokka/app/entries.rb
Ruby
mit
300
main
5,555
# frozen_string_literal: true module Lokka class App # index get '/' do @theme_types << :index @theme_types << :entries @posts = Post.published. order(@site.default_order_query_operator). page(params[:page]).per(@site.per_page) @posts = apply_continu...
github
lokka/lokka
https://github.com/lokka/lokka
lib/lokka/app/api.rb
Ruby
mit
300
main
15,398
# frozen_string_literal: true require 'json' module Lokka module Api def self.registered(app) app.helpers Helpers app.before '/api/v1/*' do content_type :json # /api/v1/token uses name/password auth, not Bearer token pass if request.path_info == '/api/v1/token' && request.p...
github
lokka/lokka
https://github.com/lokka/lokka
lib/lokka/app/admin.rb
Ruby
mit
300
main
13,917
# frozen_string_literal: true module Lokka class App get '/admin/' do erb :'admin/index', layout: :'admin/layout' end get '/admin/login' do erb :'admin/login', layout: false end post '/admin/login' do @user = User.authenticate(params[:name], params[:password]) if @user ...
github
lokka/lokka
https://github.com/lokka/lokka
test/factories.rb
Ruby
mit
300
main
4,327
# frozen_string_literal: true FactoryBot.define do create_time = update_time = Time.parse('2011-01-09T05:39:08Z') xmas = Time.parse('2011-12-25T19:00:00Z') newyear = Time.parse('2012-01-01T00:00:00Z') factory :site do title { 'Test Site' } description { 'description...' } dashboard { %q(<p>Welcome...
github
lokka/lokka
https://github.com/lokka/lokka
test/test_helper.rb
Ruby
mit
300
main
1,030
# frozen_string_literal: true require 'simplecov' SimpleCov.start do add_filter 'test/' add_filter 'public/' add_filter 'i18n/' add_filter 'db/' add_filter 'coverage/' add_filter 'tmp/' add_filter 'log/' end ENV['RACK_ENV'] = ENV['LOKKA_ENV'] = 'test' require File.join(File.dirname(__FILE__), '..', 'i...
github
lokka/lokka
https://github.com/lokka/lokka
test/api_test.rb
Ruby
mit
300
main
6,716
# frozen_string_literal: true require_relative 'test_helper' class ApiTest < LokkaTestCase def setup super @site = create(:site) @user = create(:user, name: 'apiuser', email: 'api@example.com') @user.generate_api_token! @token = @user.api_token end def auth_header { 'HTTP_AUTHORIZATION'...
github
lokka/lokka
https://github.com/lokka/lokka
test/unit/category_test.rb
Ruby
mit
300
main
344
# frozen_string_literal: true require_relative '../test_helper' class CategoryTest < LokkaTestCase def test_creating_new_category_with_blank_slug create(:category) assert_equal 1, Category.count end def test_creating_two_new_categories_with_blank_slug create_list(:category, 2) assert_equal 2, C...
github
lokka/lokka
https://github.com/lokka/lokka
test/unit/snippet_test.rb
Ruby
mit
300
main
241
# frozen_string_literal: true require_relative '../test_helper' class SnippetTest < LokkaTestCase def test_edit_link_with_id_one snippet = build(:snippet, id: 1) assert_equal '/admin/snippets/1/edit', snippet.edit_link end end
github
lokka/lokka
https://github.com/lokka/lokka
test/unit/tag_test.rb
Ruby
mit
300
main
334
# frozen_string_literal: true require_relative '../test_helper' class TagTest < LokkaTestCase def setup super @tag = create(:tag, name: 'lokka') end def test_link_returns_correct_path assert_equal '/tags/lokka/', @tag.link end def test_tag_name_returns_instance assert_equal @tag, Tag('lokk...
github
lokka/lokka
https://github.com/lokka/lokka
test/unit/helpers_test.rb
Ruby
mit
300
main
2,522
# frozen_string_literal: true require_relative '../test_helper' class HelpersTest < LokkaTestCase def test_gravatar_image_url_with_email assert_equal 'http://www.gravatar.com/avatar/55502f40dc8b7c769880b10874abc9d0', gravatar_image_url('test@example.com') end def test_gravatar_image_url_wi...
github
lokka/lokka
https://github.com/lokka/lokka
test/unit/user_test.rb
Ruby
mit
300
main
1,837
# frozen_string_literal: true require_relative '../test_helper' class UserTest < LokkaTestCase def test_new_user_saves_successfully user = User.new( name: 'Johnny', email: 'johnny@example.com', password: 'password', password_confirmation: 'password' ) assert user.save end de...
github
lokka/lokka
https://github.com/lokka/lokka
test/unit/post_test.rb
Ruby
mit
300
main
3,647
# frozen_string_literal: true require_relative '../test_helper' class PostTest < LokkaTestCase # with slug def test_post_with_slug_has_correct_link post = build(:post_with_slug) assert_equal '/welcome-lokka', post.link end def test_post_with_slug_and_permalink_enabled Option.permalink_format = '/...
github
lokka/lokka
https://github.com/lokka/lokka
test/integration/login_test.rb
Ruby
mit
300
main
886
# frozen_string_literal: true require_relative '../test_helper' require_relative '../support/custom_assertions' class LoginTest < LokkaTestCase include CustomAssertions::LoginFailed def setup super create(:site) create(:user, name: 'test') end def test_valid_login_redirects_to_admin post '/a...
github
lokka/lokka
https://github.com/lokka/lokka
test/integration/app_test.rb
Ruby
mit
300
main
8,326
# frozen_string_literal: true require_relative '../test_helper' require_relative '../support/integration_helper' class AppTest < LokkaTestCase include InSiteContext def test_index_shows_site_title get '/' assert_match 'Test Site', last_response.body end def test_entries_sorted_by_created_at_descendi...
github
lokka/lokka
https://github.com/lokka/lokka
test/integration/admin/file_upload_test.rb
Ruby
mit
300
main
835
# frozen_string_literal: true require_relative '../../test_helper' require_relative '../../support/admin_helper' class AdminFileUploadTest < LokkaTestCase include AdminLoginContext def test_get_admin_file_upload_shows_form get '/admin/file_upload' assert last_response.ok? assert_match '<form', last_r...
github
lokka/lokka
https://github.com/lokka/lokka
test/integration/admin/comments_test.rb
Ruby
mit
300
main
2,377
# frozen_string_literal: true require_relative '../../test_helper' require_relative '../../support/admin_helper' require_relative '../../support/custom_assertions' class AdminCommentsTest < LokkaTestCase include AdminLoginContext include CustomAssertions::NotFoundPage def setup super @post = create(:po...
github
lokka/lokka
https://github.com/lokka/lokka
test/integration/admin/posts_test.rb
Ruby
mit
300
main
2,065
# frozen_string_literal: true require_relative '../../test_helper' require_relative '../../support/admin_helper' require_relative '../../support/custom_assertions' class AdminPostsTest < LokkaTestCase include AdminLoginContext include CustomAssertions::NotFoundPage def setup super @post = create(:post)...
github
lokka/lokka
https://github.com/lokka/lokka
test/integration/admin/permalink_test.rb
Ruby
mit
300
main
1,359
# frozen_string_literal: true require_relative '../../test_helper' require_relative '../../support/admin_helper' class AdminPermalinkTest < LokkaTestCase include AdminLoginContext def setup super Option.permalink_enabled = false Option.permalink_format = '/%year%/%id%' end def teardown Optio...
github
lokka/lokka
https://github.com/lokka/lokka
test/integration/admin/preview_test.rb
Ruby
mit
300
main
656
# frozen_string_literal: true require_relative '../../test_helper' require_relative '../../support/admin_helper' class AdminPreviewTest < LokkaTestCase include AdminLoginContext def test_post_admin_previews_with_valid_params_succeeds params = { raw_body: "## Dinner\n\n1. Ramen\n2. Udon\n3. Tempura\n", ...