Module: Volt
- Includes:
 - Configurations
 
- Defined in:
 - lib/volt/server/rack/opal_files.rb,
lib/volt.rb,
lib/volt/cli.rb,
lib/volt/boot.rb,
lib/volt/config.rb,
lib/volt/config.rb,
lib/volt/server.rb,
lib/volt/page/page.rb,
lib/volt/cli/runner.rb,
lib/volt/models/url.rb,
lib/volt/page/tasks.rb,
lib/volt/spec/setup.rb,
lib/volt/volt/users.rb,
app/volt/models/user.rb,
lib/volt/cli/console.rb,
lib/volt/utils/ejson.rb,
lib/volt/models/model.rb,
lib/volt/page/channel.rb,
lib/volt/models/buffer.rb,
lib/volt/models/cursor.rb,
lib/volt/page/document.rb,
lib/volt/router/routes.rb,
lib/volt/spec/capybara.rb,
lib/volt/spec/sauce_labs.rb,
lib/volt/page/sub_context.rb,
lib/volt/page/url_tracker.rb,
lib/volt/tasks/dispatcher.rb,
lib/volt/volt/environment.rb,
lib/volt/cli/asset_compile.rb,
lib/volt/page/channel_stub.rb,
lib/volt/models/array_model.rb,
lib/volt/models/model_state.rb,
lib/volt/models/validations.rb,
lib/volt/reactive/eventable.rb,
lib/volt/tasks/task_handler.rb,
lib/volt/utils/generic_pool.rb,
lib/volt/reactive/dependency.rb,
lib/volt/utils/local_storage.rb,
lib/volt/utils/local_storage.rb,
lib/volt/models/model_helpers.rb,
lib/volt/models/model_wrapper.rb,
lib/volt/page/document_events.rb,
lib/volt/reactive/computation.rb,
lib/volt/data_stores/data_store.rb,
lib/volt/models/persistors/base.rb,
lib/volt/page/template_renderer.rb,
lib/volt/reactive/reactive_hash.rb,
lib/volt/models/persistors/flash.rb,
lib/volt/models/persistors/store.rb,
lib/volt/page/targets/dom_target.rb,
lib/volt/reactive/reactive_array.rb,
lib/volt/server/rack/asset_files.rb,
lib/volt/server/rack/index_files.rb,
lib/volt/data_stores/mongo_driver.rb,
lib/volt/models/persistors/params.rb,
lib/volt/page/bindings/if_binding.rb,
lib/volt/page/targets/dom_section.rb,
lib/volt/reactive/hash_dependency.rb,
lib/volt/server/component_handler.rb,
lib/volt/models/persistors/cookies.rb,
lib/volt/page/targets/base_section.rb,
lib/volt/page/targets/dom_template.rb,
lib/volt/page/bindings/base_binding.rb,
lib/volt/page/bindings/each_binding.rb,
lib/volt/server/component_templates.rb,
lib/volt/server/rack/component_code.rb,
lib/volt/models/model_hash_behaviour.rb,
lib/volt/page/bindings/event_binding.rb,
lib/volt/reactive/reactive_accessors.rb,
lib/volt/server/rack/component_paths.rb,
lib/volt/utils/generic_counting_pool.rb,
lib/volt/controllers/model_controller.rb,
lib/volt/extra_core/inflector/methods.rb,
lib/volt/models/persistors/array_store.rb,
lib/volt/models/persistors/local_store.rb,
lib/volt/models/persistors/model_store.rb,
lib/volt/models/persistors/store_state.rb,
lib/volt/page/bindings/content_binding.rb,
lib/volt/page/string_template_renderer.rb,
lib/volt/page/targets/attribute_target.rb,
lib/volt/server/html_parser/each_scope.rb,
lib/volt/server/html_parser/view_scope.rb,
lib/volt/server/rack/source_map_server.rb,
app/volt/controllers/notices_controller.rb,
lib/volt/page/bindings/template_binding.rb,
lib/volt/page/targets/attribute_section.rb,
lib/volt/server/html_parser/view_parser.rb,
lib/volt/models/persistors/store_factory.rb,
lib/volt/page/bindings/attribute_binding.rb,
lib/volt/page/bindings/component_binding.rb,
lib/volt/server/html_parser/view_handler.rb,
lib/volt/extra_core/inflector/inflections.rb,
lib/volt/server/html_parser/if_view_scope.rb,
lib/volt/server/socket_connection_handler.rb,
lib/volt/server/html_parser/textarea_scope.rb,
lib/volt/models/validators/length_validator.rb,
lib/volt/models/validators/unique_validator.rb,
lib/volt/server/html_parser/attribute_scope.rb,
lib/volt/server/rack/component_html_renderer.rb,
lib/volt/models/persistors/model_identity_map.rb,
lib/volt/models/validators/presence_validator.rb,
lib/volt/server/html_parser/sandlebars_parser.rb,
lib/volt/server/socket_connection_handler_stub.rb,
lib/volt/models/persistors/query/query_listener.rb,
lib/volt/page/targets/helpers/comment_searchers.rb,
lib/volt/page/targets/binding_document/base_node.rb,
lib/volt/page/targets/binding_document/html_node.rb,
lib/volt/models/validators/numericality_validator.rb,
lib/volt/models/persistors/query/query_listener_pool.rb,
lib/volt/page/targets/binding_document/component_node.rb,
lib/volt/page/bindings/template_binding/grouped_controllers.rb 
Overview
Some template bindings share the controller with other template bindings based on a name. This class keeps track of the number of templates using this controller and clears it once no one else is using it. Use #get or #inc to add to the count. #clear removes 1 from the count. When the count is 0, delete the controller.
Defined Under Namespace
Modules: AttributeScope, Buffer, CommentSearchers, Eventable, Inflector, LocalStorage, ModelHashBehaviour, ModelHelpers, ModelState, ModelWrapper, Persistors, ReactiveAccessors, Validations Classes: ArrayModel, AssetFiles, AttributeBinding, AttributeSection, AttributeTarget, BaseBinding, BaseNode, BaseSection, CLI, Channel, ChannelStub, ComponentBinding, ComponentCode, ComponentHandler, ComponentHtmlRenderer, ComponentNode, ComponentPaths, ComponentTemplates, Computation, Console, ContentBinding, Cursor, DataStore, Dependency, Dispatcher, Document, DocumentEvents, DomSection, DomTarget, DomTemplate, EJson, EachBinding, EachScope, Environment, EventBinding, GenericCountingPool, GenericPool, GroupedControllers, HTMLParseError, HashDependency, HtmlNode, IfBinding, IfViewScope, IndexFiles, JSEvent, LengthValidator, Listener, Model, ModelController, ModelIdentityMap, NilMethodCall, NoticesController, NumericalityValidator, OpalFiles, Page, PresenceValidator, QueryListener, QueryListenerPool, ReactiveArray, ReactiveHash, Routes, SandlebarsParser, Server, SocketConnectionHandler, SocketConnectionHandlerStub, SourceMapServer, StringTemplateRender, SubContext, TaskHandler, Tasks, TemplateBinding, TemplateRenderer, TextareaScope, URL, UniqueValidator, UrlTracker, User, ViewHandler, ViewParser, ViewScope
Class Attribute Summary collapse
Class Method Summary collapse
- .boot(app_path) ⇒ Object
 - .client? ⇒ Boolean
 - .defaults ⇒ Object
 - .env ⇒ Object
 - .in_browser? ⇒ Boolean
 - 
  
    
      .login(username, password)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Login the user, return a promise for success.
 - .logout ⇒ Object
 - 
  
    
      .reset_config!  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Resets the configuration to the default (empty hash).
 - 
  
    
      .run_files_in_config_folder  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Load in all .rb files in the config folder.
 - .server? ⇒ Boolean
 - .setup_capybara(app_path) ⇒ Object
 - .setup_capybara_app(app_path) ⇒ Object
 - 
  
    
      .setup_client_config(config_hash)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Called on page load to pass the backend config to the client.
 - .setup_sauce_labs ⇒ Object
 - .source_maps? ⇒ Boolean
 - .spec_setup(app_path = '.') ⇒ Object
 - 
  
    
      .user  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Return the current user.
 - 
  
    
      .user?  ⇒ Boolean 
    
    
  
  
  
  
  
  
  
  
  
    
True if the user is logged in and the user is loaded.
 - 
  
    
      .user_id  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Get the user_id from the cookie.
 - 
  
    
      .user_id_signature  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Fetches the user_id+signature from the correct spot depending on client or server, does not verify it.
 - 
  
    
      .wrap_config(hash)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Wraps the config hash in an OpenStruct so it can be accessed in the same way as the server side config.
 
Class Attribute Details
Class Method Details
.boot(app_path) ⇒ Object
      10 11 12 13 14 15 16 17 18 19 20 21 22  | 
    
      # File 'lib/volt/boot.rb', line 10 def self.boot(app_path) # Run the app config to load all users config files Volt.run_files_in_config_folder if Volt.server? $page = Page.new end component_paths = ComponentPaths.new(app_path) component_paths.require_in_components component_paths end  | 
  
.defaults ⇒ Object
      49 50 51 52 53 54 55 56 57 58  | 
    
      # File 'lib/volt/config.rb', line 49 def defaults app_name = File.basename(Dir.pwd) { app_name: app_name, db_name: ENV['DB_NAME'] || (app_name + '_' + Volt.env.to_s), db_host: ENV['DB_HOST'] || 'localhost', db_port: (ENV['DB_PORT'] || 27_017).to_i, db_driver: ENV['DB_DRIVER'] || 'mongo', } end  | 
  
.env ⇒ Object
      38 39 40  | 
    
      # File 'lib/volt.rb', line 38 def env @env ||= Volt::Environment.new end  | 
  
.login(username, password) ⇒ Object
Login the user, return a promise for success
      44 45 46 47 48 49 50 51 52 53  | 
    
      # File 'lib/volt/volt/users.rb', line 44 def login(username, password) UserTasks.login(username, password).then do |result| # Assign the user_id cookie for the user $page.._user_id = result # Pass nil back nil end end  | 
  
.logout ⇒ Object
      55 56 57  | 
    
      # File 'lib/volt/volt/users.rb', line 55 def logout $page..delete(:user_id) end  | 
  
.reset_config! ⇒ Object
Resets the configuration to the default (empty hash)
      61 62 63 64 65  | 
    
      # File 'lib/volt/config.rb', line 61 def reset_config! self.configure do |c| c.from_h(defaults) end end  | 
  
.run_files_in_config_folder ⇒ Object
Load in all .rb files in the config folder
      68 69 70 71 72  | 
    
      # File 'lib/volt/config.rb', line 68 def run_files_in_config_folder Dir[Volt.root + '/config/*.rb'].each do |config_file| require(config_file) end end  | 
  
.setup_capybara(app_path) ⇒ Object
      5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28  | 
    
      # File 'lib/volt/spec/capybara.rb', line 5 def (app_path) browser = ENV['BROWSER'] if browser (app_path) case browser when 'phantom' Capybara.default_driver = :poltergeist when 'chrome', 'safari' # Use the browser name, note that safari requires an extension to run browser = browser.to_sym Capybara.register_driver(browser) do |app| Capybara::Selenium::Driver.new(app, browser: browser) end Capybara.default_driver = browser when 'firefox' Capybara.default_driver = :selenium when 'sauce' setup_sauce_labs end end end  | 
  
.setup_capybara_app(app_path) ⇒ Object
      30 31 32 33 34 35 36 37 38 39 40 41 42 43  | 
    
      # File 'lib/volt/spec/capybara.rb', line 30 def (app_path) require 'capybara' require 'capybara/dsl' require 'capybara/rspec' require 'capybara/poltergeist' require 'volt/server' Capybara.server do |app, port| require 'rack/handler/thin' Rack::Handler::Thin.run(app, Port: port) end Capybara.app = Server.new(app_path).app end  | 
  
.setup_client_config(config_hash) ⇒ Object
Called on page load to pass the backend config to the client
      21 22 23 24  | 
    
      # File 'lib/volt/config.rb', line 21 def setup_client_config(config_hash) # Only Volt.config.public is passed from the server (for security reasons) @config = wrap_config({public: config_hash}) end  | 
  
.setup_sauce_labs ⇒ Object
      3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31  | 
    
      # File 'lib/volt/spec/sauce_labs.rb', line 3 def setup_sauce_labs require "sauce" require "sauce/capybara" Sauce.config do |c| if ENV['OS'] # Use a specifc OS, BROWSER, VERSION combo (for travis) c[:browsers] = [ [ENV['OS'], ENV['USE_BROWSER'], ENV['VERSION']] ] else # Run all c[:browsers] = [ # ["Windows 7", "Chrome", "30"], # ["Windows 8", "Firefox", "28"], ["Windows 8.1", "Internet Explorer", "11"], ["Windows 8.0", "Internet Explorer", "10"], ["Windows 7.0", "Internet Explorer", "9"], # ["OSX 10.9", "iPhone", "8.1"], # ["OSX 10.8", "Safari", "6"], # ["Linux", "Chrome", "26"] ] end c[:start_local_application] = false end Capybara.default_driver = :sauce Capybara.javascript_driver = :sauce end  | 
  
.spec_setup(app_path = '.') ⇒ Object
      3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18  | 
    
      # File 'lib/volt/spec/setup.rb', line 3 def spec_setup(app_path = '.') require 'volt' unless RUBY_PLATFORM == 'opal' require 'volt/spec/capybara' ENV['SERVER'] = 'true' ENV['VOLT_ENV'] = 'test' require 'volt/boot' # Require in app Volt.boot(app_path) (app_path) end end  | 
  
.user ⇒ Object
Return the current user.
      34 35 36 37 38 39 40 41  | 
    
      # File 'lib/volt/volt/users.rb', line 34 def user user_id = self.user_id if user_id return $page.store._users.find_one(_id: user_id) else return nil end end  | 
  
.user? ⇒ Boolean
True if the user is logged in and the user is loaded
      29 30 31  | 
    
      # File 'lib/volt/volt/users.rb', line 29 def user? !!user end  | 
  
.user_id ⇒ Object
Get the user_id from the cookie
      4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26  | 
    
      # File 'lib/volt/volt/users.rb', line 4 def user_id user_id_signature = self.user_id_signature if user_id_signature.nil? return nil else index = user_id_signature.index(':') user_id = user_id_signature[0...index] if RUBY_PLATFORM != 'opal' hash = user_id_signature[(index+1)..-1] # Make sure the user hash matches if BCrypt::Password.new(hash) != "#{Volt.config.app_secret}::#{user_id}" # user id has been tampered with, reject raise "user id or hash has been tampered with" end end return user_id end end  | 
  
.user_id_signature ⇒ Object
Fetches the user_id+signature from the correct spot depending on client or server, does not verify it.
      62 63 64 65 66 67 68 69 70 71 72 73 74 75 76  | 
    
      # File 'lib/volt/volt/users.rb', line 62 def user_id_signature if Volt.client? user_id_signature = $page.._user_id else # Check meta for the user id and validate it = Thread.current['meta'] if user_id_signature = ['user_id'] else user_id_signature = nil end end user_id_signature end  | 
  
.wrap_config(hash) ⇒ Object
Wraps the config hash in an OpenStruct so it can be accessed in the same way as the server side config.
      28 29 30 31 32 33 34 35 36 37 38 39 40  | 
    
      # File 'lib/volt/config.rb', line 28 def wrap_config(hash) new_hash = {} hash.each_pair do |key, value| if value.is_a?(Hash) new_hash[key] = wrap_config(value) else new_hash[key] = value end end OpenStruct.new(new_hash) end  |