text
stringlengths
2
1.04M
meta
dict
<?php namespace FishDiary\Test\TestCase\Controller; use Cake\TestSuite\IntegrationTestCase; use FishDiary\Controller\CaughtFishesController; /** * FishDiary\Controller\CaughtFishesController Test Case */ class CaughtFishesControllerTest extends IntegrationTestCase { /** * Fixtures * * @var array */ public $fixtures = [ 'app.caught_fishes', 'app.fish_types', 'app.fishing_places', 'app.lures', 'app.lure_types', 'app.weather_types', 'app.caught_fish_notes', 'app.caught_fish' ]; /** * Test index method * * @return void */ public function testIndex() { $this->markTestIncomplete('Not implemented yet.'); } /** * Test view method * * @return void */ public function testView() { $this->markTestIncomplete('Not implemented yet.'); } /** * Test add method * * @return void */ public function testAdd() { $this->markTestIncomplete('Not implemented yet.'); } /** * Test edit method * * @return void */ public function testEdit() { $this->markTestIncomplete('Not implemented yet.'); } /** * Test delete method * * @return void */ public function testDelete() { $this->markTestIncomplete('Not implemented yet.'); } }
{ "content_hash": "ee1849e88c5d44b049d72088aa285faf", "timestamp": "", "source": "github", "line_count": 78, "max_line_length": 60, "avg_line_length": 18.423076923076923, "alnum_prop": 0.5539318023660403, "repo_name": "makallio85/fish-diary", "id": "1e6894eeea100b99873d45c6a11ef4b09545c22f", "size": "1437", "binary": false, "copies": "1", "ref": "refs/heads/master", "path": "tests/TestCase/Controller/CaughtFishesControllerTest.php", "mode": "33188", "license": "mit", "language": [ { "name": "Batchfile", "bytes": "834" }, { "name": "CSS", "bytes": "12827" }, { "name": "JavaScript", "bytes": "215256" }, { "name": "PHP", "bytes": "291927" }, { "name": "Shell", "bytes": "1457" } ], "symlink_target": "" }
package com.thinkgem.jeesite.modules.cms.web; import java.util.List; import java.util.Map; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import com.thinkgem.jeesite.common.web.BaseController; import com.thinkgem.jeesite.modules.cms.service.StatsService; /** * 统计Controller * @author ThinkGem * @version 2013-5-21 */ @Controller @RequestMapping(value = "${adminPath}/cms/stats") public class StatsController extends BaseController { @Autowired private StatsService statsService; /** * 文章信息量 * @param map * @param model * @return */ @RequiresPermissions("cms:stats:article") @RequestMapping(value = "article") public String article(@RequestParam Map<String, Object> paramMap, Model model) { List<Map<String, Object>> list = statsService.article(paramMap); model.addAttribute("list", list); model.addAttribute("paramMap", paramMap); return "modules/cms/statsArticle"; } }
{ "content_hash": "2a70ebecc7cf4aff2f83a4bf79dbf0f9", "timestamp": "", "source": "github", "line_count": 44, "max_line_length": 81, "avg_line_length": 27.204545454545453, "alnum_prop": 0.7744360902255639, "repo_name": "chu888chu888/Chuguangming.Java.Fork.CMS.jeesite", "id": "914168a6d1fa48147ff4c15308caea27ee526209", "size": "1397", "binary": false, "copies": "2", "ref": "refs/heads/master", "path": "src/main/java/com/thinkgem/jeesite/modules/cms/web/StatsController.java", "mode": "33188", "license": "apache-2.0", "language": [ { "name": "ASP", "bytes": "3753" }, { "name": "Java", "bytes": "492553" }, { "name": "JavaScript", "bytes": "4994852" }, { "name": "PHP", "bytes": "6972" }, { "name": "Shell", "bytes": "3139" } ], "symlink_target": "" }
 /** * @fileOverview Defines the {@link CKFinder.lang} object for the Croatian * language. */ /** * Contains the dictionary of language entries. * @namespace */ CKFinder.lang['hr'] = { appTitle : 'CKFinder', // Common messages and labels. common : { // Put the voice-only part of the label in the span. unavailable : '%1<span class="cke_accessibility">, nedostupno</span>', confirmCancel : 'Neke od opcija su promjenjene. Sigurno želite zatvoriti prozor??', ok : 'U redu', cancel : 'Poništi', confirmationTitle : 'Potvrda', messageTitle : 'Informacija', inputTitle : 'Pitanje', undo : 'Poništi', redo : 'Preuredi', skip : 'Preskoči', skipAll : 'Preskoči sve', makeDecision : 'Što bi trebali napraviti?', rememberDecision: 'Zapamti moj izbor' }, // Language direction, 'ltr' or 'rtl'. dir : 'ltr', HelpLang : 'en', LangCode : 'hr', // Date Format // d : Day // dd : Day (padding zero) // m : Month // mm : Month (padding zero) // yy : Year (two digits) // yyyy : Year (four digits) // h : Hour (12 hour clock) // hh : Hour (12 hour clock, padding zero) // H : Hour (24 hour clock) // HH : Hour (24 hour clock, padding zero) // M : Minute // MM : Minute (padding zero) // a : Firt char of AM/PM // aa : AM/PM DateTime : 'm/d/yyyy h:MM aa', DateAmPm : ['AM', 'PM'], // Folders FoldersTitle : 'Direktoriji', FolderLoading : 'Učitavam...', FolderNew : 'Unesite novo ime direktorija: ', FolderRename : 'Unesite novo ime direktorija: ', FolderDelete : 'Sigurno želite obrisati direktorij "%1"?', FolderRenaming : ' (Mijenjam ime...)', FolderDeleting : ' (Brišem...)', // Files FileRename : 'Unesite novo ime datoteke: ', FileRenameExt : 'Sigurno želite promijeniti vrstu datoteke? Datoteka može postati neiskoristiva.', FileRenaming : 'Mijenjam ime...', FileDelete : 'Sigurno želite obrisati datoteku "%1"?', FilesLoading : 'Učitavam...', FilesEmpty : 'Direktorij je prazan.', FilesMoved : 'Datoteka %1 premještena u %2:%3.', FilesCopied : 'Datoteka %1 kopirana u %2:%3.', // Basket BasketFolder : 'Košara', BasketClear : 'Isprazni košaru', BasketRemove : 'Ukloni iz košare', BasketOpenFolder : 'Otvori nadređeni direktorij', BasketTruncateConfirm : 'Sigurno želite obrisati sve datoteke iz košare?', BasketRemoveConfirm : 'Sigurno želite obrisati datoteku "%1" iz košare?', BasketEmpty : 'Nema niti jedne datoteke, ubacite koju.', BasketCopyFilesHere : 'Kopiraj datoteke iz košare', BasketMoveFilesHere : 'Premjesti datoteke iz košare', BasketPasteErrorOther : 'Datoteke %s greška: %e', BasketPasteMoveSuccess : 'Sljedeće datoteke su premještene: %s', BasketPasteCopySuccess : 'Sljedeće datoteke su kopirane: %s', // Toolbar Buttons (some used elsewhere) Upload : 'Pošalji', UploadTip : 'Pošalji nove datoteke na server', Refresh : 'Osvježi', Settings : 'Postavke', Help : 'Pomoć', HelpTip : 'Pomoć', // Context Menus Select : 'Odaberi', SelectThumbnail : 'Odaberi manju sliku', View : 'Pogledaj', Download : 'Skini', NewSubFolder : 'Novi poddirektorij', Rename : 'Promijeni naziv', Delete : 'Obriši', CopyDragDrop : 'Kopiraj datoteku ovdje', MoveDragDrop : 'Premjesti datoteku ovdje', // Dialogs RenameDlgTitle : 'Promijeni naziv', NewNameDlgTitle : 'Novi naziv', FileExistsDlgTitle : 'Datoteka već postoji', SysErrorDlgTitle : 'Greška sustava', FileOverwrite : 'Prepiši', FileAutorename : 'Automatska promjena naziva', // Generic OkBtn : 'U redu', CancelBtn : 'Poništi', CloseBtn : 'Zatvori', // Upload Panel UploadTitle : 'Pošalji novu datoteku', UploadSelectLbl : 'Odaberi datoteku za slanje', UploadProgressLbl : '(Slanje u tijeku, molimo pričekajte...)', UploadBtn : 'Pošalji odabranu datoteku', UploadBtnCancel : 'Poništi', UploadNoFileMsg : 'Odaberite datoteku na Vašem računalu.', UploadNoFolder : 'Odaberite direktorije prije slanja.', UploadNoPerms : 'Slanje datoteka nije dozvoljeno.', UploadUnknError : 'Greška kod slanja datoteke.', UploadExtIncorrect : 'Vrsta datoteka nije dozvoljena.', // Flash Uploads UploadLabel : 'Datoteka za slanje:', UploadTotalFiles : 'Ukupno datoteka:', UploadTotalSize : 'Ukupna veličina:', UploadSend : 'Pošalji', UploadAddFiles : 'Dodaj datoteke', UploadClearFiles : 'Izbaci datoteke', UploadCancel : 'Poništi slanje', UploadRemove : 'Ukloni', UploadRemoveTip : 'Ukloni !f', UploadUploaded : 'Poslano !n%', UploadProcessing : 'Obrađujem...', // Settings Panel SetTitle : 'Postavke', SetView : 'Pregled:', SetViewThumb : 'Mala slika', SetViewList : 'Lista', SetDisplay : 'Prikaz:', SetDisplayName : 'Naziv datoteke', SetDisplayDate : 'Datum', SetDisplaySize : 'Veličina datoteke', SetSort : 'Sortiranje:', SetSortName : 'po nazivu', SetSortDate : 'po datumu', SetSortSize : 'po veličini', SetSortExtension : 'po vrsti datoteke', // Status Bar FilesCountEmpty : '<Prazan direktorij>', FilesCountOne : '1 datoteka', FilesCountMany : '%1 datoteka', // Size and Speed Kb : '%1 kB', KbPerSecond : '%1 kB/s', // Connector Error Messages. ErrorUnknown : 'Nije moguće završiti zahtjev. (Greška %1)', Errors : { 10 : 'Nepoznata naredba.', 11 : 'Nije navedena vrsta u zahtjevu.', 12 : 'Zatražena vrsta nije važeća.', 102 : 'Neispravno naziv datoteke ili direktoija.', 103 : 'Nije moguće izvršiti zahtjev zbog ograničenja pristupa.', 104 : 'Nije moguće izvršiti zahtjev zbog ograničenja postavka sustava.', 105 : 'Nedozvoljena vrsta datoteke.', 109 : 'Nedozvoljen zahtjev.', 110 : 'Nepoznata greška.', 115 : 'Datoteka ili direktorij s istim nazivom već postoji.', 116 : 'Direktorij nije pronađen. Osvježite stranicu i pokušajte ponovo.', 117 : 'Datoteka nije pronađena. Osvježite listu datoteka i pokušajte ponovo.', 118 : 'Putanje izvora i odredišta su jednake.', 201 : 'Datoteka s istim nazivom već postoji. Poslana datoteka je promjenjena u "%1".', 202 : 'Neispravna datoteka.', 203 : 'Neispravna datoteka. Veličina datoteke je prevelika.', 204 : 'Poslana datoteka je neispravna.', 205 : 'Ne postoji privremeni direktorij za slanje na server.', 206 : 'Slanje je poništeno zbog sigurnosnih postavki. Naziv datoteke sadrži HTML podatke.', 207 : 'Poslana datoteka je promjenjena u "%1".', 300 : 'Premještanje datoteke(a) nije uspjelo.', 301 : 'Kopiranje datoteke(a) nije uspjelo.', 500 : 'Pretraživanje datoteka nije dozvoljeno iz sigurnosnih razloga. Molimo kontaktirajte administratora sustava kako bi provjerili postavke CKFinder konfiguracijske datoteke.', 501 : 'The thumbnails support is disabled.' }, // Other Error Messages. ErrorMsg : { FileEmpty : 'Naziv datoteke ne može biti prazan.', FileExists : 'Datoteka %s već postoji.', FolderEmpty : 'Naziv direktorija ne može biti prazan.', FileInvChar : 'Naziv datoteke ne smije sadržavati niti jedan od sljedećih znakova: \n\\ / : * ? " < > |', FolderInvChar : 'Naziv direktorija ne smije sadržavati niti jedan od sljedećih znakova: \n\\ / : * ? " < > |', PopupBlockView : 'Nije moguće otvoriti datoteku u novom prozoru. Promijenite postavke svog Internet preglednika i isključite sve popup blokere za ove web stranice.', XmlError : 'Nije moguće učitati XML odgovor od web servera.', XmlEmpty : 'Nije moguće učitati XML odgovor od web servera. Server je vratio prazan odgovor.', XmlRawResponse : 'Odgovor servera: %s' }, // Imageresize plugin Imageresize : { dialogTitle : 'Promijeni veličinu %s', sizeTooBig : 'Nije moguće postaviti veličinu veću od originala (%size).', resizeSuccess : 'Slika je uspješno promijenjena.', thumbnailNew : 'Napravi malu sliku', thumbnailSmall : 'Mala (%s)', thumbnailMedium : 'Srednja (%s)', thumbnailLarge : 'Velika (%s)', newSize : 'Postavi novu veličinu', width : 'Širina', height : 'Visina', invalidHeight : 'Neispravna visina.', invalidWidth : 'Neispravna širina.', invalidName : 'Neispravan naziv datoteke.', newImage : 'Napravi novu sliku', noExtensionChange : 'Vrsta datoteke se ne smije mijenjati.', imageSmall : 'Izvorna slika je premala.', contextMenuName : 'Promijeni veličinu', lockRatio : 'Zaključaj odnose', resetSize : 'Vrati veličinu' }, // Fileeditor plugin Fileeditor : { save : 'Snimi', fileOpenError : 'Nije moguće otvoriti datoteku.', fileSaveSuccess : 'Datoteka je uspješno snimljena.', contextMenuName : 'Promjeni', loadingFile : 'Učitavam, molimo pričekajte...' }, Maximize : { maximize : 'Povećaj', minimize : 'Smanji' } };
{ "content_hash": "5e0c1598118a54a15726a7d03179833f", "timestamp": "", "source": "github", "line_count": 263, "max_line_length": 179, "avg_line_length": 32.77946768060836, "alnum_prop": 0.690871128639369, "repo_name": "thanhdv193/cuteshop", "id": "8ba7bb26ed919578f5fb49702fe1eea0b5402c48", "size": "9155", "binary": false, "copies": "16", "ref": "refs/heads/master", "path": "web/ckfinder/lang/hr.js", "mode": "33188", "license": "bsd-3-clause", "language": [ { "name": "ApacheConf", "bytes": "841" }, { "name": "Batchfile", "bytes": "1030" }, { "name": "CSS", "bytes": "1686027" }, { "name": "HTML", "bytes": "759450" }, { "name": "JavaScript", "bytes": "1268538" }, { "name": "PHP", "bytes": "1744646" } ], "symlink_target": "" }
////////////////////////////////////////////////////////////////////////////// // Copyright (C) 2008-2012, Shane Liesegang // All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above copyright // notice, this list of conditions and the following disclaimer in the // documentation and/or other materials provided with the distribution. // * Neither the name of the copyright holder nor the names of any // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE // POSSIBILITY OF SUCH DAMAGE. ////////////////////////////////////////////////////////////////////////////// #pragma once #include "../Infrastructure/VecStructs.h" #include "../Infrastructure/Vector2.h" #include "../Infrastructure/Log.h" #if defined(WIN32) #include <XInput.h> #pragma comment(lib, "XInput.lib") #elif defined(__APPLE__) #include <Carbon/Carbon.h> #include <IOKit/HID/IOHIDKeys.h> #include "HID_Utilities_External.h" #elif defined(__linux__) #include <fcntl.h> #include <linux/joystick.h> #include <string.h> #include <sstream> #include <unistd.h> #define LINUX_CONTROLLER_1_PATH "/dev/input/js0" #define LINUX_CONTROLLER_2_PATH "/dev/input/js1" #define LINUX_EVENT_INTERFACE "/dev/input/event" #define MAX_LINUX_EVENT_INTERFACES 32 #endif ///A struct that wraps all controller input values into one unit struct ControllerInput { int LeftThumbstickX; int LeftThumbstickY; int RightThumbstickX; int RightThumbstickY; int LeftTriggerValue; int RightTriggerValue; unsigned int Buttons; }; //forward declaration for the manager class class Controller; //Limited to two because our wrapping is a little naive at the moment #define MAX_CONTROLLERS 2 /// (Internal) Manages multiple controllers (currently up to 2) /** * This internal class represents the coordinator for gamepad controllers. You * should only have to deal with it if you're using it with multiple * controllers, and even then, it's best to access them with the * "controllerOne" and "controllerTwo" shortcuts. * * Like the World, it uses the singleton pattern; you can't actually declare * a new instance of a ControllerManager. To access controllers in your * world, use "theControllerManager" to retrieve the singleton object. * "theControllerManager" is defined in both C++ and Lua. * * If you're not familiar with the singleton pattern, this paper is a good * starting point. (Don't be afraid that it's written by Microsoft.) * * http://msdn.microsoft.com/en-us/library/ms954629.aspx */ class ControllerManager { public: /** * Used to access the singleton instance of this class. As a shortcut, * you can just use "theControllerManager". * * @return The singleton */ static ControllerManager& GetInstance(); /** * Get a reference to one of the controllers. * * @param controllerIndex The index of the controller you want to * retrieve. Since we only support 2 controllers, this needs to be * either 0 or 1. * @return A Controller object */ Controller& GetController(int controllerIndex=0) { if ( (controllerIndex >= MAX_CONTROLLERS) || (controllerIndex < 0) ) { sysLog.Log("ERROR: Bad controller index."); } return *_controllers[controllerIndex]; } /** * Attempt to initialize both controllers. */ void Setup(); /** * Called once per frame, reads all input data from the controller for * polling by the rest of the game. */ void UpdateState(); /** * The destructor releases all the controller input handles. */ ~ControllerManager(); protected: static ControllerManager *s_ControllerManager; private: ControllerManager(); Controller* _controllers[MAX_CONTROLLERS]; }; //Accessor and Singleton shortcuts #define theControllerManager ControllerManager::GetInstance() #define theController ControllerManager::GetInstance().GetController() #define controllerOne theController #define controllerTwo ControllerManager::GetInstance().GetController(1) ///A class representing a gamepad controller /** * This class is your means of getting data from a controller. At the moment * we only test and support the Xbox 360 controller over USB, but this * interface could be abstracted to support other controllers. * * On Windows you'll need DirectX installed to play a game made with Angel, * and the DirectX SDK to develop one. A pretty big download/install just * to get access to a controller, but we figure most gamers/developers have * already done so anyway. * * On the Mac both players and developers need to install a kernel extension * (sorry!) included in the Tools directory. We'd be more than happy to * remove this requirement, but unless someone who knows more about how to * use IOKit and raw USB values wants to help, this is what we've got. */ class Controller { public: friend class ControllerManager; /** * Sets the controller up to read data every frame. If it's successful, * the Controller::IsConnected function will return true. */ void Setup(); /** * Called once per frame to read the data in from the controller. Called * automatically by the ControllerManager. */ void UpdateState(); /** * Directly access all current input on the controller. * * @return The current input data from the buttons and thumbsticks of this * controller. */ const ControllerInput GetState(); /** * Get the X and Y positions of the left thumbstick as a Vector2. * * @return The current direction of the left thumbstick, as a Vector2 with * both dimensions ranging from -1.0 to 1.0. */ const Vector2 GetLeftThumbVec2(); /** * Get the X and Y positions of the right thumbstick as a Vector2. * * @return The current direction of the right thumbstick, as a Vector2 * with both dimensions ranging from -1.0 to 1.0. */ const Vector2 GetRightThumbVec2(); /** * Get the raw values of the left thumbstick as an integer vector. * * @return The current raw values of the left thumbstick, with both X and * Y ranging from -32768 to 32768. */ const Vec2i GetLeftThumbstick(); /** * Get the raw values of the right thumbstick as an integer vector. * * @return The current raw values of the right thumbstick, with both X and * Y ranging from -32768 to 32768. */ const Vec2i GetRightThumbstick(); /** * Get the current value of the right trigger. * * @return How much the right analog trigger is pressed, ranging from 0 * (untouched) to 255 (all the way down). */ const int GetRightTrigger(); /** * Get the current value of the left trigger. * * @return How much the left analog trigger is pressed, ranging from 0 * (untouched) to 255 (all the way down). */ const int GetLeftTrigger(); /** * Pass a button mask to find out if a combination of buttons is depressed * at the same time. Here are the mask values: * * \code * #define XINPUT_GAMEPAD_DPAD_UP 0x00000001 * #define XINPUT_GAMEPAD_DPAD_DOWN 0x00000002 * #define XINPUT_GAMEPAD_DPAD_LEFT 0x00000004 * #define XINPUT_GAMEPAD_DPAD_RIGHT 0x00000008 * #define XINPUT_GAMEPAD_START 0x00000010 * #define XINPUT_GAMEPAD_BACK 0x00000020 * #define XINPUT_GAMEPAD_LEFT_THUMB 0x00000040 * #define XINPUT_GAMEPAD_RIGHT_THUMB 0x00000080 * #define XINPUT_GAMEPAD_LEFT_SHOULDER 0x0100 * #define XINPUT_GAMEPAD_RIGHT_SHOULDER 0x0200 * #define XINPUT_GAMEPAD_A 0x1000 * #define XINPUT_GAMEPAD_B 0x2000 * #define XINPUT_GAMEPAD_X 0x4000 * #define XINPUT_GAMEPAD_Y 0x8000 * \endcode * * @param buttonMask The values you care about, combined as a bitmask * @return True if all the masked buttons are pressed, false if they're * not */ const bool IsButtonDown(int buttonMask); //Do these really need documentation comments? Sigh. I guess so. /** * Find out if the A button is currently pressed. * * @return True if it is, false if it's not. */ const bool IsAButtonDown(); /** * Find out if the B button is currently pressed. * * @return True if it is, false if it's not. */ const bool IsBButtonDown(); /** * Find out if the X button is currently pressed. * * @return True if it is, false if it's not. */ const bool IsXButtonDown(); /** * Find out if the Y button is currently pressed. * * @return True if it is, false if it's not. */ const bool IsYButtonDown(); /** * Find out if the left thumbstick is currently pressed down. * * @return True if it is, false if it's not. */ const bool IsLeftThumbstickButtonDown(); /** * Find out if the right thumbstick is currently pressed down. * * @return True if it is, false if it's not. */ const bool IsRightThumbstickButtonDown(); /** * Find out if the start button is currently pressed. * * @return True if it is, false if it's not. */ const bool IsStartButtonDown(); /** * Find out if the back button is currently pressed. * * @return True if it is, false if it's not. */ const bool IsBackButtonDown(); /** * Find out if the left shoulder button is currently pressed. * * @return True if it is, false if it's not. */ const bool IsLeftBumperDown(); /** * Find out if the right shoulder button is currently pressed. * * @return True if it is, false if it's not. */ const bool IsRightBumperDown(); /** * Find out if the left trigger is pressed down. Since it's an analog * trigger, there's a driver-defined threshold that this function will * use to determine when it can be considered "activated." * * @return True if it is, false if it's not. */ const bool IsLeftTriggerPressed(); /** * Find out if the left trigger is pressed down. Since it's an analog * trigger, there's a driver-defined threshold that this function will * use to determine when it can be considered "activated." * * @return True if it is, false if it's not. */ const bool IsRightTriggerPressed(); /** * Set the rumble of the controller's lower frequencies. This sets the * raw driver value. * * Not available on Mac OS X. :-( * * @param frequencies The desired intensity, ranging from 0 to 65535. */ void SetLeftVibrationRaw(unsigned int vibration); /** * Set the rumble of the controller's higher frequencies. This sets the * raw driver value. * * Not available on Mac OS X. :-( * * @param frequencies The desired intensity, ranging from 0 to 65535. */ void SetRightVibrationRaw(unsigned int vibration); /** * Set the rumble of the controller's lower frequencies. This uses more * manageable numbers if you don't feel like dealing with INT_MAX. * * Not available on Mac OS X. :-( * * @param frequencies The desired intensity, ranging from 0 to 255. */ void SetLeftVibration(unsigned int vibration); /** * Set the rumble of the controller's higher frequencies. This uses more * manageable numbers if you don't feel like dealing with INT_MAX. * * Not available on Mac OS X. :-( * * @param frequencies The desired intensity, ranging from 0 to 255. */ void SetRightVibration(unsigned int vibration); /** * Get the current vibration setting for the lower frequencies. * * @return Current intensity, ranging from 0 to 65535. */ const unsigned int GetLeftVibration(); /** * Get the current vibration setting for the higher frequencies. * * @return Current intensity, ranging from 0 to 65535. */ const unsigned int GetRightVibration(); /** * Find out if this controller object is currently mapped to a real-world * controller and receiving input. * * @return True if this controller gets input */ const bool IsConnected() { return _connected; } /** * Get the index this controller corresponds to in the ControllerManager. * * @return The index that can be used in ControllerManager::GetController */ const int GetControllerID() { return _controllerID; } protected: Controller(); static Controller *s_Controller; private: int _controllerID; bool _connected; ControllerInput _currentControllerInput; unsigned int _currentLeftVibration; unsigned int _currentRightVibration; #if defined(WIN32) DWORD _dwResult; XINPUT_STATE _currentControllerRawState; #elif defined(__APPLE__) pRecDevice _device; hashmap_ns::hash_map<unsigned int, pRecElement> _elements; const long _getValueForCookie(unsigned int cookie) { return HIDGetElementValue(_device, _elements[cookie]); } #elif defined(__linux__) int _deviceFD; int _ffFD; struct ff_effect _ffEffect; struct input_event _ffPlay; #endif };
{ "content_hash": "d9bbe667de3be3c47c5777296ed0da34", "timestamp": "", "source": "github", "line_count": 452, "max_line_length": 79, "avg_line_length": 30.88938053097345, "alnum_prop": 0.6920212004010887, "repo_name": "d909b/GADEL-Snake", "id": "ed77c4c6d3ba10c662222b5607725f17fdd72fe5", "size": "13962", "binary": false, "copies": "1", "ref": "refs/heads/master", "path": "Angel/Input/Controller.h", "mode": "33188", "license": "bsd-3-clause", "language": [ { "name": "Ada", "bytes": "89080" }, { "name": "Assembly", "bytes": "143356" }, { "name": "C", "bytes": "15770728" }, { "name": "C#", "bytes": "55726" }, { "name": "C++", "bytes": "7152957" }, { "name": "D", "bytes": "416653" }, { "name": "Delphi", "bytes": "68422" }, { "name": "JavaScript", "bytes": "40695" }, { "name": "Lua", "bytes": "542771" }, { "name": "OCaml", "bytes": "6380" }, { "name": "Objective-C", "bytes": "1650241" }, { "name": "Perl", "bytes": "269377" }, { "name": "Python", "bytes": "202527" }, { "name": "Racket", "bytes": "19627" }, { "name": "Ruby", "bytes": "234" }, { "name": "Scheme", "bytes": "9578" }, { "name": "Shell", "bytes": "5749964" } ], "symlink_target": "" }
<?php namespace FOS\RestBundle\Util\Inflector; use Doctrine\Common\Inflector\Inflector; use FOS\RestBundle\Inflector\DoctrineInflector as NewDoctrineInflector; /** * Inflector object using the Doctrine/Inflector. * * @author Mark Kazemier <Markkaz> * * @deprecated since 1.8, to be removed in 2.0. Use {@link \FOS\RestBundle\Inflector\DoctrineInflector} instead. */ class DoctrineInflector implements InflectorInterface { public function __construct() { if (!$this instanceof NewDoctrineInflector) { @trigger_error(sprintf('%s is deprecated since version 1.8 and will be removed in 2.0. Use FOS\RestBundle\Inflector\DoctrineInflector instead.', __CLASS__), E_USER_DEPRECATED); } } /** * {@inheritdoc} */ public function pluralize($word) { return Inflector::pluralize($word); } }
{ "content_hash": "ee6d743ce1eef523ca1f053cbc230d6b", "timestamp": "", "source": "github", "line_count": 33, "max_line_length": 188, "avg_line_length": 26.21212121212121, "alnum_prop": 0.6890173410404624, "repo_name": "smeagonline-developers/OnlineEducationPlatform---SMEAGonline", "id": "e72dcbc4e6ef6caf09241642393064443d60c79d", "size": "1117", "binary": false, "copies": "2", "ref": "refs/heads/master", "path": "vendor/friendsofsymfony/rest-bundle/FOS/RestBundle/Util/Inflector/DoctrineInflector.php", "mode": "33188", "license": "mit", "language": [ { "name": "ApacheConf", "bytes": "2691" }, { "name": "CSS", "bytes": "9937162" }, { "name": "CoffeeScript", "bytes": "167262" }, { "name": "HTML", "bytes": "4919069" }, { "name": "JavaScript", "bytes": "42925514" }, { "name": "PHP", "bytes": "22450097" }, { "name": "PLSQL", "bytes": "7483" }, { "name": "Shell", "bytes": "9237" }, { "name": "Smarty", "bytes": "6" } ], "symlink_target": "" }
/* * Copyright (C) 2002, * * Hewlett-Packard Arjuna Labs, * Newcastle upon Tyne, * Tyne and Wear, * UK. * * $Id: BaseTransaction.java 2342 2006-03-30 13:06:17Z $ */ package com.arjuna.ats.internal.jta.transaction.arjunacore; import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.Callable; import java.util.concurrent.Future; import java.util.concurrent.FutureTask; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; import javax.transaction.InvalidTransactionException; import javax.transaction.NotSupportedException; import com.arjuna.ats.arjuna.AtomicAction; import com.arjuna.ats.arjuna.coordinator.TxControl; import com.arjuna.ats.jta.common.jtaPropertyManager; import com.arjuna.ats.jta.logging.jtaLogger; public class BaseTransaction { public void begin() throws javax.transaction.NotSupportedException, javax.transaction.SystemException { if (jtaLogger.logger.isTraceEnabled()) { jtaLogger.logger.trace("BaseTransaction.begin"); } /* * We can supported subtransactions, so should have the option to let * programmer use them. Strict conformance will always say no. */ if (!_supportSubtransactions) { try { checkTransactionState(); } catch (IllegalStateException e1) { NotSupportedException notSupportedException = new NotSupportedException( e1.getMessage()); notSupportedException.initCause(e1); throw notSupportedException; } catch (Exception e2) { javax.transaction.SystemException systemException = new javax.transaction.SystemException( e2.toString()); systemException.initCause(e2); throw systemException; } } Integer value = _timeouts.get(); int v = 0; // if not set then assume 0. What else can we do? if (value != null) { v = value.intValue(); } else v = TxControl.getDefaultTimeout(); // TODO set default timeout TransactionImple.putTransaction(new TransactionImple(v)); } /** * We will never throw a HeuristicRollbackException because if we get a * HeuristicRollback from a resource, and can successfully rollback the * other resources, this is then the same as having simply been forced to * rollback the transaction during phase 1. The OTS interfaces do not allow * a differentiation. */ public void commit() throws javax.transaction.RollbackException, javax.transaction.HeuristicMixedException, javax.transaction.HeuristicRollbackException, java.lang.SecurityException, java.lang.IllegalStateException, javax.transaction.SystemException { if (jtaLogger.logger.isTraceEnabled()) { jtaLogger.logger.trace("BaseTransaction.commit"); } TransactionImple theTransaction = TransactionImple.getTransaction(); if (theTransaction == null) throw new IllegalStateException( "BaseTransaction.commit - " + jtaLogger.i18NLogger.get_transaction_arjunacore_notx()); theTransaction.commitAndDisassociate(); } public void rollback() throws java.lang.IllegalStateException, java.lang.SecurityException, javax.transaction.SystemException { if (jtaLogger.logger.isTraceEnabled()) { jtaLogger.logger.trace("BaseTransaction.rollback"); } TransactionImple theTransaction = TransactionImple.getTransaction(); if (theTransaction == null) throw new IllegalStateException( "BaseTransaction.rollback - " + jtaLogger.i18NLogger.get_transaction_arjunacore_notx()); theTransaction.rollbackAndDisassociate(); } public void setRollbackOnly() throws java.lang.IllegalStateException, javax.transaction.SystemException { if (jtaLogger.logger.isTraceEnabled()) { jtaLogger.logger.trace("BaseTransaction.setRollbackOnly"); } TransactionImple theTransaction = TransactionImple.getTransaction(); if (theTransaction == null) throw new IllegalStateException( jtaLogger.i18NLogger.get_transaction_arjunacore_nosuchtx()); theTransaction.setRollbackOnly(); } public int getStatus() throws javax.transaction.SystemException { TransactionImple theTransaction = TransactionImple.getTransaction(); if (theTransaction == null) return javax.transaction.Status.STATUS_NO_TRANSACTION; else return theTransaction.getStatus(); } public void setTransactionTimeout(int seconds) throws javax.transaction.SystemException { if (seconds >= 0) { _timeouts.set(new Integer(seconds)); } } public int getTimeout() throws javax.transaction.SystemException { Integer value = _timeouts.get(); if (value != null) { return value.intValue(); } else return 0; } public String toString() { TransactionImple theTransaction = TransactionImple.getTransaction(); if (theTransaction == null) return "Transaction: unknown"; else return "Transaction: " + theTransaction; } public TransactionImple createSubordinate () throws javax.transaction.NotSupportedException, javax.transaction.SystemException { if (jtaLogger.logger.isTraceEnabled()) { jtaLogger.logger.trace("BaseTransaction.createSubordinate"); } try { checkTransactionState(); } catch (IllegalStateException e1) { NotSupportedException notSupportedException = new NotSupportedException(); notSupportedException.initCause(e1); throw notSupportedException; } catch (Exception e2) { javax.transaction.SystemException systemException = new javax.transaction.SystemException(e2.toString()); systemException.initCause(e2); throw systemException; } Integer value = _timeouts.get(); int v = 0; // if not set then assume 0. What else can we do? if (value != null) { v = value.intValue(); } // TODO set default timeout return new com.arjuna.ats.internal.jta.transaction.arjunacore.subordinate.TransactionImple(v); } protected BaseTransaction() { } /** * Called when we want to make sure this thread does not already have a * transaction associated with it. */ final void checkTransactionState() throws IllegalStateException, javax.transaction.SystemException { // ok, no transaction currently associated with thread. TransactionImple theTransaction = TransactionImple.getTransaction(); if (theTransaction == null) return; else { if ((theTransaction.getStatus() != javax.transaction.Status.STATUS_NO_TRANSACTION) && !_supportSubtransactions) { throw new IllegalStateException( "BaseTransaction.checkTransactionState - " + jtaLogger.i18NLogger.get_transaction_arjunacore_alreadyassociated()); } } } public Future<Void> commitAsync() { final TransactionImple theTransaction = TransactionImple .getTransaction(); if (theTransaction == null) throw new IllegalStateException("BaseTransaction.commit - " + jtaLogger.i18NLogger.get_transaction_arjunacore_notx()); AtomicAction.suspend(); return wrap(new Callable<Void>() { public Void call() throws InvalidTransactionException, javax.transaction.RollbackException, javax.transaction.HeuristicMixedException, javax.transaction.HeuristicRollbackException, java.lang.SecurityException, javax.transaction.SystemException, java.lang.IllegalStateException { if (AtomicAction.suspend() != null) { System.err .println("WARNING - A PREVIOUS TRANSACTION WAS ON THE THREAD UNSUSPENDED"); } if (!AtomicAction.resume(theTransaction.getAtomicAction())) throw new InvalidTransactionException(); theTransaction.commitAndDisassociate(); return null; } }); } public static <T> Future<T> wrap(Callable<T> callable) { final FutureTask<T> task = new FutureTask<T>(callable); tpe.execute(task); return task; } private static final boolean _supportSubtransactions = jtaPropertyManager.getJTAEnvironmentBean().isSupportSubtransactions(); private static final ThreadLocal<Integer> _timeouts = new ThreadLocal<Integer>(); private static final int _asyncCommitPoolSize = jtaPropertyManager.getJTAEnvironmentBean().getAsyncCommitPoolSize(); private static final ThreadPoolExecutor tpe = new ThreadPoolExecutor(1, _asyncCommitPoolSize, 10, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(3)); }
{ "content_hash": "51e485b69635b7623609e60341890002", "timestamp": "", "source": "github", "line_count": 294, "max_line_length": 154, "avg_line_length": 28.602040816326532, "alnum_prop": 0.7227970032108455, "repo_name": "nmcl/wfswarm-example-arjuna-old", "id": "4650ef4e0abd27c559d4d7d6d70282dfc428412d", "size": "9387", "binary": false, "copies": "3", "ref": "refs/heads/master", "path": "graalvm/transactions/fork/narayana/ArjunaJTA/jta/classes/com/arjuna/ats/internal/jta/transaction/arjunacore/BaseTransaction.java", "mode": "33261", "license": "apache-2.0", "language": [ { "name": "Java", "bytes": "6903" } ], "symlink_target": "" }
<?php /** * customers defined options * * @author Magento Core Team <[email protected]> */ namespace Magento\Catalog\Block\Adminhtml\Product\Edit\Tab\Options\Type; class Select extends \Magento\Catalog\Block\Adminhtml\Product\Edit\Tab\Options\Type\AbstractType { /** * @var string */ protected $_template = 'catalog/product/edit/options/type/select.phtml'; /** * Class constructor * * @return void */ protected function _construct() { parent::_construct(); $this->setCanEditPrice(true); $this->setCanReadPrice(true); } /** * @return $this */ protected function _prepareLayout() { $this->addChild( 'add_select_row_button', 'Magento\Backend\Block\Widget\Button', [ 'label' => __('Add New Row'), 'class' => 'add add-select-row', 'id' => 'product_option_<%- data.option_id %>_add_select_row' ] ); $this->addChild( 'delete_select_row_button', 'Magento\Backend\Block\Widget\Button', [ 'label' => __('Delete Row'), 'class' => 'delete delete-select-row icon-btn', 'id' => 'product_option_<%- data.id %>_select_<%- data.select_id %>_delete' ] ); return parent::_prepareLayout(); } /** * @return string */ public function getAddButtonHtml() { return $this->getChildHtml('add_select_row_button'); } /** * @return string */ public function getDeleteButtonHtml() { return $this->getChildHtml('delete_select_row_button'); } /** * Return select input for price type * * @param string $extraParams * @return string */ public function getPriceTypeSelectHtml($extraParams = '') { $this->getChildBlock( 'option_price_type' )->setData( 'id', 'product_option_<%- data.id %>_select_<%- data.select_id %>_price_type' )->setName( 'product[options][<%- data.id %>][values][<%- data.select_id %>][price_type]' ); return parent::getPriceTypeSelectHtml($extraParams); } }
{ "content_hash": "6de54c313457fae0936a2cc00a52f73f", "timestamp": "", "source": "github", "line_count": 94, "max_line_length": 96, "avg_line_length": 24.51063829787234, "alnum_prop": 0.5269097222222222, "repo_name": "enettolima/magento-training", "id": "92a1da98a0c555dda4ae4777cba54f2531c84931", "size": "2402", "binary": false, "copies": "2", "ref": "refs/heads/master", "path": "magento2ce/app/code/Magento/Catalog/Block/Adminhtml/Product/Edit/Tab/Options/Type/Select.php", "mode": "33188", "license": "mit", "language": [ { "name": "ApacheConf", "bytes": "22648" }, { "name": "CSS", "bytes": "3382928" }, { "name": "HTML", "bytes": "8749335" }, { "name": "JavaScript", "bytes": "7355635" }, { "name": "PHP", "bytes": "58607662" }, { "name": "Perl", "bytes": "10258" }, { "name": "Shell", "bytes": "41887" }, { "name": "XSLT", "bytes": "19889" } ], "symlink_target": "" }
"use strict"; describe("Unit Test for The Profile Service: ", function () { var profileService; beforeEach(function () { module("yoda.home.services.socialMedia"); inject(["yoda.home.service.getProfile", function (_profileService_) { profileService = _profileService_; }]); }); it("Should define user profiles for Denis Karanja", function () { var profile = profileService.profile(); expect(profile).toBeDefined(); expect(typeof(profile)).toBe("object"); }); it("Should have 4 profiles defined", function () { var profile = profileService.profile(); expect(profile.length).toBe(5); }); it("Should link the profiles to the correct URLs", function () { var twitter = "https://twitter.com/dee_beat"; var email = "mailto:[email protected]"; var github = "https://github.com/yoda-yoda"; var linkedin = "https://linkedin.com/in/karanja"; var repo = "https://github.com/yoda-yoda/yoda-face.git"; var profile = profileService.profile(); expect(profile[0]).toEqual(twitter); expect(profile[1]).toEqual(email); expect(profile[2]).toEqual(github); expect(profile[3]).toEqual(linkedin); expect(profile[4]).toEqual(repo); }); });
{ "content_hash": "f94d58855aec265dccd0e8e659b09b61", "timestamp": "", "source": "github", "line_count": 42, "max_line_length": 77, "avg_line_length": 31.666666666666668, "alnum_prop": 0.6090225563909775, "repo_name": "yoda-yoda/yoda-face", "id": "5547eac105664728a21906bb70b96f549ad17d67", "size": "1330", "binary": false, "copies": "1", "ref": "refs/heads/master", "path": "src/app/home/services/tests/socialMedia.spec.js", "mode": "33188", "license": "mit", "language": [ { "name": "CSS", "bytes": "568" }, { "name": "HTML", "bytes": "2205" }, { "name": "JavaScript", "bytes": "34867" }, { "name": "Smarty", "bytes": "797" } ], "symlink_target": "" }
package solr import "testing" func TestSolrQueryAddParam(t *testing.T) { q := NewQuery() q.AddParam("qf", "some qf") if q.String() != "qf=some+qf" { t.Errorf("Expected to be: 'some qf'") } } func TestSolrQuerySetParam(t *testing.T) { q := NewQuery() q.SetParam("qf", "some qf") if q.String() != "qf=some+qf" { t.Errorf("Expected to be: 'some qf'") } } func TestSolrQueryGetParam(t *testing.T) { q := NewQuery() q.SetParam("qf", "some qf") if q.GetParam("qf") != "some qf" { t.Errorf("Expected to be: 'some qf'") } } func TestSolrQueryStart(t *testing.T) { q := NewQuery() q.Start(100) if q.String() != "start=100" { t.Errorf("Expected 'start=100'") } } func TestSolrSearchMultipleValueQuery(t *testing.T) { q := NewQuery() q.AddParam("testing", "test") q.AddParam("testing", "testing 2") res := q.String() expected := "testing=test&testing=testing+2" if res != expected { t.Errorf("Expected to be: '%s' but got '%s'", expected, res) } } func TestSolrQueryRemoveParam(t *testing.T) { q := NewQuery() q.AddParam("testing", "test") q.AddParam("testing2", "testing 2") // random order in for loop of range on map res := q.String() if res != "testing=test&testing2=testing+2" { t.Errorf("Expected to be: 'testing=test&testing2=testing+2' but got %s", res) } q.RemoveParam("testing2") if q.String() != "testing=test" { t.Errorf("Expected to be: 'testing=test'") } } func TestQueryQ(t *testing.T) { q := NewQuery() q.Q("id:100") expected := "q=id%3A100" result := q.String() if result != expected { t.Errorf("expected '%s' but got '%s'", expected, result) } } func TestQuerySort(t *testing.T) { q := NewQuery() q.Sort("geodist() desc") expected := "sort=geodist%28%29+desc" result := q.String() if result != expected { t.Errorf("expected '%s' but got '%s'", expected, result) } } func TestQueryFilterQuery(t *testing.T) { q := NewQuery() q.FilterQuery("popularity:[10 TO *]") expected := "fq=popularity%3A%5B10+TO+%2A%5D" result := q.String() if result != expected { t.Errorf("expected '%s' but got '%s'", expected, result) } } func TestQueryFieldList(t *testing.T) { q := NewQuery() q.FieldList("id,name,decsription") expected := "fl=id%2Cname%2Cdecsription" result := q.String() if result != expected { t.Errorf("expected '%s' but got '%s'", expected, result) } } func TestQueryGeofilt(t *testing.T) { q := NewQuery() q.Geofilt(45.15, -93.85, "store", 5) expected := "fq=%7B%21geofilt+pt%3D45.15%2C-93.85+sfield%3Dstore+d%3D5%7D" result := q.String() if result != expected { t.Errorf("expected '%s' but got '%s'", expected, result) } } func TestQueryDefType(t *testing.T) { q := NewQuery() q.DefType("func") expected := "defType=func" result := q.String() if result != expected { t.Errorf("expected '%s' but got '%s'", expected, result) } } func TestQueryBoostFunctions(t *testing.T) { q := NewQuery() q.BoostFunctions("recip(rord(myfield),1,2,3)") expected := "bf=recip%28rord%28myfield%29%2C1%2C2%2C3%29" result := q.String() if result != expected { t.Errorf("expected '%s' but got '%s'", expected, result) } } func TestQueryBoostQuery(t *testing.T) { q := NewQuery() q.BoostQuery("cat:electronics^5.0") expected := "bq=cat%3Aelectronics%5E5.0" result := q.String() if result != expected { t.Errorf("expected '%s' but got '%s'", expected, result) } } func TestQueryQueryField(t *testing.T) { q := NewQuery() q.QueryFields("features^20.0+text^0.3") expected := "qf=features%5E20.0%2Btext%5E0.3" result := q.String() if result != expected { t.Errorf("expected '%s' but got '%s'", expected, result) } } func TestSolrQueryAddFacet(t *testing.T) { q := NewQuery() q.AddFacet("color") q.AddFacet("size") expected := "facet=true&facet.field=color&facet.field=size" result := q.String() if result != expected { t.Errorf("expected '%s' but got '%s'", expected, result) } } func TestSolrQueryAddFacetQuery(t *testing.T) { q := NewQuery() q.AddFacetQuery("price:[* TO 500]") q.AddFacetQuery("price:[501 TO *]") expected := "facet=true&facet.query=price%3A%5B%2A+TO+500%5D&facet.query=price%3A%5B501+TO+%2A%5D" result := q.String() if result != expected { t.Errorf("expected '%s' but got '%s'", expected, result) } } func TestSolrQuerySetFacetMinCount(t *testing.T) { q := NewQuery() q.SetFacetMinCount(10) expected := "facet.mincount=10" result := q.String() if result != expected { t.Errorf("expected '%s' but got '%s'", expected, result) } } func TestSolrQueryAddFacetPivot(t *testing.T) { q := NewQuery() q.AddFacetPivot("color") q.AddFacetPivot("size") expected := "facet.pivot=color&facet.pivot=size" result := q.String() if result != expected { t.Errorf("expected '%s' but got '%s'", expected, result) } } func TestSolrQuerySetFacetPivotMinCount(t *testing.T) { q := NewQuery() q.SetFacetPivotMinCount(10) expected := "facet.pivot.mincount=10" result := q.String() if result != expected { t.Errorf("expected '%s' but got '%s'", expected, result) } } func TestSolrQueryAddJsonFacet(t *testing.T) { q := NewQuery() q.AddJsonFacet("{categories:{type:terms,field:cat,sort:'x desc',facet:{x:'avg(price)',y:'sum(price)'}}") expected := "json.facet=%7Bcategories%3A%7Btype%3Aterms%2Cfield%3Acat%2Csort%3A%27x+desc%27%2Cfacet%3A%7Bx%3A%27avg%28price%29%27%2Cy%3A%27sum%28price%29%27%7D%7D" result := q.String() if result != expected { t.Errorf("expected '%s' but got '%s'", expected, result) } }
{ "content_hash": "33fc2e5eafe9c900fbc6fd71eea02e29", "timestamp": "", "source": "github", "line_count": 222, "max_line_length": 164, "avg_line_length": 24.684684684684683, "alnum_prop": 0.6545620437956204, "repo_name": "vanng822/go-solr", "id": "fda7195c47fb15f696d1ca9939da238365b8394d", "size": "5480", "binary": false, "copies": "1", "ref": "refs/heads/master", "path": "solr/query_test.go", "mode": "33188", "license": "mit", "language": [ { "name": "Go", "bytes": "159833" } ], "symlink_target": "" }
use events::VirtualKeyCode; use winapi; pub fn vkeycode_to_element(code: winapi::WPARAM) -> Option<VirtualKeyCode> { match code as i32 { //winapi::VK_LBUTTON => Some(VirtualKeyCode::Lbutton), //winapi::VK_RBUTTON => Some(VirtualKeyCode::Rbutton), //winapi::VK_CANCEL => Some(VirtualKeyCode::Cancel), //winapi::VK_MBUTTON => Some(VirtualKeyCode::Mbutton), //winapi::VK_XBUTTON1 => Some(VirtualKeyCode::Xbutton1), //winapi::VK_XBUTTON2 => Some(VirtualKeyCode::Xbutton2), winapi::VK_BACK => Some(VirtualKeyCode::Back), winapi::VK_TAB => Some(VirtualKeyCode::Tab), //winapi::VK_CLEAR => Some(VirtualKeyCode::Clear), winapi::VK_RETURN => Some(VirtualKeyCode::Return), //winapi::VK_SHIFT => Some(VirtualKeyCode::Shift), //winapi::VK_CONTROL => Some(VirtualKeyCode::Control), //winapi::VK_MENU => Some(VirtualKeyCode::Menu), winapi::VK_PAUSE => Some(VirtualKeyCode::Pause), winapi::VK_CAPITAL => Some(VirtualKeyCode::Capital), winapi::VK_KANA => Some(VirtualKeyCode::Kana), //winapi::VK_HANGUEL => Some(VirtualKeyCode::Hanguel), //winapi::VK_HANGUL => Some(VirtualKeyCode::Hangul), //winapi::VK_JUNJA => Some(VirtualKeyCode::Junja), //winapi::VK_FINAL => Some(VirtualKeyCode::Final), //winapi::VK_HANJA => Some(VirtualKeyCode::Hanja), winapi::VK_KANJI => Some(VirtualKeyCode::Kanji), winapi::VK_ESCAPE => Some(VirtualKeyCode::Escape), winapi::VK_CONVERT => Some(VirtualKeyCode::Convert), //winapi::VK_NONCONVERT => Some(VirtualKeyCode::Nonconvert), //winapi::VK_ACCEPT => Some(VirtualKeyCode::Accept), //winapi::VK_MODECHANGE => Some(VirtualKeyCode::Modechange), winapi::VK_SPACE => Some(VirtualKeyCode::Space), winapi::VK_PRIOR => Some(VirtualKeyCode::PageUp), winapi::VK_NEXT => Some(VirtualKeyCode::PageDown), winapi::VK_END => Some(VirtualKeyCode::End), winapi::VK_HOME => Some(VirtualKeyCode::Home), winapi::VK_LEFT => Some(VirtualKeyCode::Left), winapi::VK_UP => Some(VirtualKeyCode::Up), winapi::VK_RIGHT => Some(VirtualKeyCode::Right), winapi::VK_DOWN => Some(VirtualKeyCode::Down), //winapi::VK_SELECT => Some(VirtualKeyCode::Select), //winapi::VK_PRINT => Some(VirtualKeyCode::Print), //winapi::VK_EXECUTE => Some(VirtualKeyCode::Execute), winapi::VK_SNAPSHOT => Some(VirtualKeyCode::Snapshot), winapi::VK_INSERT => Some(VirtualKeyCode::Insert), winapi::VK_DELETE => Some(VirtualKeyCode::Delete), //winapi::VK_HELP => Some(VirtualKeyCode::Help), 0x30 => Some(VirtualKeyCode::Key0), 0x31 => Some(VirtualKeyCode::Key1), 0x32 => Some(VirtualKeyCode::Key2), 0x33 => Some(VirtualKeyCode::Key3), 0x34 => Some(VirtualKeyCode::Key4), 0x35 => Some(VirtualKeyCode::Key5), 0x36 => Some(VirtualKeyCode::Key6), 0x37 => Some(VirtualKeyCode::Key7), 0x38 => Some(VirtualKeyCode::Key8), 0x39 => Some(VirtualKeyCode::Key9), 0x41 => Some(VirtualKeyCode::A), 0x42 => Some(VirtualKeyCode::B), 0x43 => Some(VirtualKeyCode::C), 0x44 => Some(VirtualKeyCode::D), 0x45 => Some(VirtualKeyCode::E), 0x46 => Some(VirtualKeyCode::F), 0x47 => Some(VirtualKeyCode::G), 0x48 => Some(VirtualKeyCode::H), 0x49 => Some(VirtualKeyCode::I), 0x4A => Some(VirtualKeyCode::J), 0x4B => Some(VirtualKeyCode::K), 0x4C => Some(VirtualKeyCode::L), 0x4D => Some(VirtualKeyCode::M), 0x4E => Some(VirtualKeyCode::N), 0x4F => Some(VirtualKeyCode::O), 0x50 => Some(VirtualKeyCode::P), 0x51 => Some(VirtualKeyCode::Q), 0x52 => Some(VirtualKeyCode::R), 0x53 => Some(VirtualKeyCode::S), 0x54 => Some(VirtualKeyCode::T), 0x55 => Some(VirtualKeyCode::U), 0x56 => Some(VirtualKeyCode::V), 0x57 => Some(VirtualKeyCode::W), 0x58 => Some(VirtualKeyCode::X), 0x59 => Some(VirtualKeyCode::Y), 0x5A => Some(VirtualKeyCode::Z), //winapi::VK_LWIN => Some(VirtualKeyCode::Lwin), //winapi::VK_RWIN => Some(VirtualKeyCode::Rwin), winapi::VK_APPS => Some(VirtualKeyCode::Apps), winapi::VK_SLEEP => Some(VirtualKeyCode::Sleep), winapi::VK_NUMPAD0 => Some(VirtualKeyCode::Numpad0), winapi::VK_NUMPAD1 => Some(VirtualKeyCode::Numpad1), winapi::VK_NUMPAD2 => Some(VirtualKeyCode::Numpad2), winapi::VK_NUMPAD3 => Some(VirtualKeyCode::Numpad3), winapi::VK_NUMPAD4 => Some(VirtualKeyCode::Numpad4), winapi::VK_NUMPAD5 => Some(VirtualKeyCode::Numpad5), winapi::VK_NUMPAD6 => Some(VirtualKeyCode::Numpad6), winapi::VK_NUMPAD7 => Some(VirtualKeyCode::Numpad7), winapi::VK_NUMPAD8 => Some(VirtualKeyCode::Numpad8), winapi::VK_NUMPAD9 => Some(VirtualKeyCode::Numpad9), winapi::VK_MULTIPLY => Some(VirtualKeyCode::Multiply), winapi::VK_ADD => Some(VirtualKeyCode::Add), //winapi::VK_SEPARATOR => Some(VirtualKeyCode::Separator), winapi::VK_SUBTRACT => Some(VirtualKeyCode::Subtract), winapi::VK_DECIMAL => Some(VirtualKeyCode::Decimal), winapi::VK_DIVIDE => Some(VirtualKeyCode::Divide), winapi::VK_F1 => Some(VirtualKeyCode::F1), winapi::VK_F2 => Some(VirtualKeyCode::F2), winapi::VK_F3 => Some(VirtualKeyCode::F3), winapi::VK_F4 => Some(VirtualKeyCode::F4), winapi::VK_F5 => Some(VirtualKeyCode::F5), winapi::VK_F6 => Some(VirtualKeyCode::F6), winapi::VK_F7 => Some(VirtualKeyCode::F7), winapi::VK_F8 => Some(VirtualKeyCode::F8), winapi::VK_F9 => Some(VirtualKeyCode::F9), winapi::VK_F10 => Some(VirtualKeyCode::F10), winapi::VK_F11 => Some(VirtualKeyCode::F11), winapi::VK_F12 => Some(VirtualKeyCode::F12), winapi::VK_F13 => Some(VirtualKeyCode::F13), winapi::VK_F14 => Some(VirtualKeyCode::F14), winapi::VK_F15 => Some(VirtualKeyCode::F15), /*winapi::VK_F16 => Some(VirtualKeyCode::F16), winapi::VK_F17 => Some(VirtualKeyCode::F17), winapi::VK_F18 => Some(VirtualKeyCode::F18), winapi::VK_F19 => Some(VirtualKeyCode::F19), winapi::VK_F20 => Some(VirtualKeyCode::F20), winapi::VK_F21 => Some(VirtualKeyCode::F21), winapi::VK_F22 => Some(VirtualKeyCode::F22), winapi::VK_F23 => Some(VirtualKeyCode::F23), winapi::VK_F24 => Some(VirtualKeyCode::F24),*/ winapi::VK_NUMLOCK => Some(VirtualKeyCode::Numlock), winapi::VK_SCROLL => Some(VirtualKeyCode::Scroll), /*winapi::VK_LSHIFT => Some(VirtualKeyCode::Lshift), winapi::VK_RSHIFT => Some(VirtualKeyCode::Rshift), winapi::VK_LCONTROL => Some(VirtualKeyCode::Lcontrol), winapi::VK_RCONTROL => Some(VirtualKeyCode::Rcontrol), winapi::VK_LMENU => Some(VirtualKeyCode::Lmenu), winapi::VK_RMENU => Some(VirtualKeyCode::Rmenu), winapi::VK_BROWSER_BACK => Some(VirtualKeyCode::Browser_back), winapi::VK_BROWSER_FORWARD => Some(VirtualKeyCode::Browser_forward), winapi::VK_BROWSER_REFRESH => Some(VirtualKeyCode::Browser_refresh), winapi::VK_BROWSER_STOP => Some(VirtualKeyCode::Browser_stop), winapi::VK_BROWSER_SEARCH => Some(VirtualKeyCode::Browser_search), winapi::VK_BROWSER_FAVORITES => Some(VirtualKeyCode::Browser_favorites), winapi::VK_BROWSER_HOME => Some(VirtualKeyCode::Browser_home), winapi::VK_VOLUME_MUTE => Some(VirtualKeyCode::Volume_mute), winapi::VK_VOLUME_DOWN => Some(VirtualKeyCode::Volume_down), winapi::VK_VOLUME_UP => Some(VirtualKeyCode::Volume_up), winapi::VK_MEDIA_NEXT_TRACK => Some(VirtualKeyCode::Media_next_track), winapi::VK_MEDIA_PREV_TRACK => Some(VirtualKeyCode::Media_prev_track), winapi::VK_MEDIA_STOP => Some(VirtualKeyCode::Media_stop), winapi::VK_MEDIA_PLAY_PAUSE => Some(VirtualKeyCode::Media_play_pause), winapi::VK_LAUNCH_MAIL => Some(VirtualKeyCode::Launch_mail), winapi::VK_LAUNCH_MEDIA_SELECT => Some(VirtualKeyCode::Launch_media_select), winapi::VK_LAUNCH_APP1 => Some(VirtualKeyCode::Launch_app1), winapi::VK_LAUNCH_APP2 => Some(VirtualKeyCode::Launch_app2), winapi::VK_OEM_1 => Some(VirtualKeyCode::Oem_1), winapi::VK_OEM_PLUS => Some(VirtualKeyCode::Oem_plus), winapi::VK_OEM_COMMA => Some(VirtualKeyCode::Oem_comma), winapi::VK_OEM_MINUS => Some(VirtualKeyCode::Oem_minus), winapi::VK_OEM_PERIOD => Some(VirtualKeyCode::Oem_period), winapi::VK_OEM_2 => Some(VirtualKeyCode::Oem_2), winapi::VK_OEM_3 => Some(VirtualKeyCode::Oem_3), winapi::VK_OEM_4 => Some(VirtualKeyCode::Oem_4), winapi::VK_OEM_5 => Some(VirtualKeyCode::Oem_5), winapi::VK_OEM_6 => Some(VirtualKeyCode::Oem_6), winapi::VK_OEM_7 => Some(VirtualKeyCode::Oem_7), winapi::VK_OEM_8 => Some(VirtualKeyCode::Oem_8), winapi::VK_OEM_102 => Some(VirtualKeyCode::Oem_102), winapi::VK_PROCESSKEY => Some(VirtualKeyCode::Processkey), winapi::VK_PACKET => Some(VirtualKeyCode::Packet), winapi::VK_ATTN => Some(VirtualKeyCode::Attn), winapi::VK_CRSEL => Some(VirtualKeyCode::Crsel), winapi::VK_EXSEL => Some(VirtualKeyCode::Exsel), winapi::VK_EREOF => Some(VirtualKeyCode::Ereof), winapi::VK_PLAY => Some(VirtualKeyCode::Play), winapi::VK_ZOOM => Some(VirtualKeyCode::Zoom), winapi::VK_NONAME => Some(VirtualKeyCode::Noname), winapi::VK_PA1 => Some(VirtualKeyCode::Pa1), winapi::VK_OEM_CLEAR => Some(VirtualKeyCode::Oem_clear),*/ _ => None } }
{ "content_hash": "17ec6af993f27d2cc3322d81406d1110", "timestamp": "", "source": "github", "line_count": 181, "max_line_length": 84, "avg_line_length": 54.751381215469614, "alnum_prop": 0.6251261352169526, "repo_name": "retep998/glutin", "id": "6fbde816538c0e24e551c0136e941fb69118bc4f", "size": "9910", "binary": false, "copies": "2", "ref": "refs/heads/master", "path": "src/api/win32/event.rs", "mode": "33188", "license": "apache-2.0", "language": [ { "name": "Rust", "bytes": "434510" } ], "symlink_target": "" }
using System; class ParseURL { static void Main() { string url = Console.ReadLine(); int indexOfDoubleDots = url.IndexOf(':'); int indexFrom = indexOfDoubleDots + 3; int indexTo = url.IndexOf('/', indexFrom); string protocol = url.Substring(0, indexOfDoubleDots); string server = url.Substring(indexFrom, indexTo - indexFrom); string resource = url.Substring(indexTo); Console.WriteLine("[protocol] = {0}",protocol); Console.WriteLine("[server] = {0}", server); Console.WriteLine("[resource] = {0}", resource); } }
{ "content_hash": "fed7830d65c4af00bf4e11c2db406568", "timestamp": "", "source": "github", "line_count": 19, "max_line_length": 70, "avg_line_length": 32.10526315789474, "alnum_prop": 0.6098360655737705, "repo_name": "VVoev/Telerik-Academy", "id": "8d0f49a09e9a11fef7a9d698dcdbfbfc145b7d62", "size": "612", "binary": false, "copies": "1", "ref": "refs/heads/master", "path": "03.C#Advanced/06.StringsAndTextProcessing/12.ParseURL/ParseURL.cs", "mode": "33188", "license": "mit", "language": [ { "name": "ASP", "bytes": "100" }, { "name": "C#", "bytes": "5055520" }, { "name": "C++", "bytes": "6554" }, { "name": "CSS", "bytes": "220628" }, { "name": "CoffeeScript", "bytes": "1570" }, { "name": "HTML", "bytes": "2116929" }, { "name": "Java", "bytes": "186556" }, { "name": "JavaScript", "bytes": "3798933" }, { "name": "PLSQL", "bytes": "139427" }, { "name": "PLpgSQL", "bytes": "1336296" }, { "name": "PowerShell", "bytes": "468" }, { "name": "SQLPL", "bytes": "7996" }, { "name": "Smalltalk", "bytes": "5031" }, { "name": "TypeScript", "bytes": "19610" }, { "name": "Visual Basic", "bytes": "7346" }, { "name": "XSLT", "bytes": "1343" } ], "symlink_target": "" }
var __extends = (this && this.__extends) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; function __() { this.constructor = d; } __.prototype = b.prototype; d.prototype = new __(); }; define(["require", "exports"], function (require, exports) { var DataModel; (function (DataModel) { (function (Gender) { Gender[Gender["Female"] = 0] = "Female"; Gender[Gender["Male"] = 1] = "Male"; Gender[Gender["Transgender"] = 2] = "Transgender"; Gender[Gender["Androgyne"] = 3] = "Androgyne"; Gender[Gender["Unknown"] = 4] = "Unknown"; Gender[Gender["Other"] = 5] = "Other"; })(DataModel.Gender || (DataModel.Gender = {})); var Gender = DataModel.Gender; (function (Personality) { Personality[Personality["INTJ"] = 0] = "INTJ"; Personality[Personality["INTP"] = 1] = "INTP"; Personality[Personality["ENTJ"] = 2] = "ENTJ"; Personality[Personality["INFJ"] = 3] = "INFJ"; Personality[Personality["INFP"] = 4] = "INFP"; Personality[Personality["ENFJ"] = 5] = "ENFJ"; Personality[Personality["ENFP"] = 6] = "ENFP"; Personality[Personality["ISTJ"] = 7] = "ISTJ"; Personality[Personality["ISFJ"] = 8] = "ISFJ"; Personality[Personality["ESTJ"] = 9] = "ESTJ"; Personality[Personality["ESFJ"] = 10] = "ESFJ"; Personality[Personality["ISTP"] = 11] = "ISTP"; Personality[Personality["ISFP"] = 12] = "ISFP"; Personality[Personality["ESTP"] = 13] = "ESTP"; Personality[Personality["ESFP"] = 14] = "ESFP"; })(DataModel.Personality || (DataModel.Personality = {})); var Personality = DataModel.Personality; (function (Role) { Role[Role["Major"] = 0] = "Major"; Role[Role["Minor"] = 1] = "Minor"; Role[Role["Protagonist"] = 2] = "Protagonist"; Role[Role["Antagonist"] = 3] = "Antagonist"; Role[Role["Foil"] = 4] = "Foil"; Role[Role["Symbolic"] = 5] = "Symbolic"; })(DataModel.Role || (DataModel.Role = {})); var Role = DataModel.Role; var Entity = (function () { function Entity() { } return Entity; })(); DataModel.Entity = Entity; var EntityBuilder = (function () { function EntityBuilder() { } EntityBuilder.prototype.id = function (value) { this._id = value; return this; }; EntityBuilder.prototype.construct = function () { return null; }; EntityBuilder.prototype.build = function () { var entity = this.construct(); if (this._id) { entity.id = this._id; } else { entity.id = guid(); } return entity; }; return EntityBuilder; })(); DataModel.EntityBuilder = EntityBuilder; var Chapter = (function (_super) { __extends(Chapter, _super); function Chapter() { _super.apply(this, arguments); } return Chapter; })(Entity); DataModel.Chapter = Chapter; var ChapterBuilder = (function (_super) { __extends(ChapterBuilder, _super); function ChapterBuilder() { _super.apply(this, arguments); } ChapterBuilder.prototype.title = function (value) { this._title = value; return this; }; ChapterBuilder.prototype.description = function (value) { this._description = value; return this; }; ChapterBuilder.prototype.construct = function () { return new Chapter(); }; ChapterBuilder.prototype.build = function () { var value = _super.prototype.build.call(this); value.title = this._title; value.description = this._description; return value; }; return ChapterBuilder; })(EntityBuilder); DataModel.ChapterBuilder = ChapterBuilder; var Character = (function (_super) { __extends(Character, _super); function Character() { _super.apply(this, arguments); } return Character; })(Entity); DataModel.Character = Character; var CharacterBuilder = (function (_super) { __extends(CharacterBuilder, _super); function CharacterBuilder() { _super.apply(this, arguments); } CharacterBuilder.prototype.alias = function (value) { this._alias = value; return this; }; CharacterBuilder.prototype.biography = function (value) { this._biography = value; return this; }; CharacterBuilder.prototype.description = function (value) { this._description = value; return this; }; CharacterBuilder.prototype.fullName = function (value) { this._fullName = value; return this; }; CharacterBuilder.prototype.shortName = function (value) { this._shortName = value; return this; }; CharacterBuilder.prototype.goals = function (value) { this._goals = value; return this; }; CharacterBuilder.prototype.gender = function (value) { this._gender = value; return this; }; CharacterBuilder.prototype.personality = function (value) { this._personality = value; return this; }; CharacterBuilder.prototype.role = function (value) { this._role = value; return this; }; CharacterBuilder.prototype.construct = function () { return new Character(); }; CharacterBuilder.prototype.build = function () { var value = _super.prototype.build.call(this); value.alias = this._alias; value.biography = this._biography; value.description = this._description; value.fullName = this._fullName; value.gender = this._gender; value.goals = this._goals; value.personality = this._personality; value.role = this._role; value.shortName = this._shortName; return value; }; return CharacterBuilder; })(EntityBuilder); DataModel.CharacterBuilder = CharacterBuilder; var Note = (function (_super) { __extends(Note, _super); function Note() { _super.apply(this, arguments); } return Note; })(Entity); DataModel.Note = Note; var NoteBuilder = (function (_super) { __extends(NoteBuilder, _super); function NoteBuilder() { _super.apply(this, arguments); } NoteBuilder.prototype.prose = function (value) { this._prose = value; return this; }; NoteBuilder.prototype.construct = function () { return new Note(); }; NoteBuilder.prototype.build = function () { var value = _super.prototype.build.call(this); value.prose = this._prose; return value; }; return NoteBuilder; })(EntityBuilder); DataModel.NoteBuilder = NoteBuilder; var Prop = (function (_super) { __extends(Prop, _super); function Prop() { _super.apply(this, arguments); } return Prop; })(Entity); DataModel.Prop = Prop; var PropBuilder = (function (_super) { __extends(PropBuilder, _super); function PropBuilder() { _super.apply(this, arguments); } PropBuilder.prototype.alias = function (value) { this._alias = value; return this; }; PropBuilder.prototype.description = function (value) { this._description = value; return this; }; PropBuilder.prototype.name = function (value) { this._name = value; return this; }; PropBuilder.prototype.construct = function () { return new Prop(); }; PropBuilder.prototype.build = function () { var value = _super.prototype.build.call(this); value.alias = this._alias; value.description = this._description; value.name = this._name; return value; }; return PropBuilder; })(EntityBuilder); DataModel.PropBuilder = PropBuilder; var Scene = (function (_super) { __extends(Scene, _super); function Scene() { _super.apply(this, arguments); } return Scene; })(Entity); DataModel.Scene = Scene; var SceneBuilder = (function (_super) { __extends(SceneBuilder, _super); function SceneBuilder() { _super.apply(this, arguments); } SceneBuilder.prototype.prose = function (value) { this._prose = value; return this; }; SceneBuilder.prototype.title = function (value) { this._title = value; return this; }; SceneBuilder.prototype.construct = function () { return new Scene(); }; SceneBuilder.prototype.build = function () { var value = _super.prototype.build.call(this); value.prose = this._prose; value.title = this._title; return value; }; return SceneBuilder; })(EntityBuilder); DataModel.SceneBuilder = SceneBuilder; function guid() { function s4() { return Math.floor((1 + Math.random()) * 0x10000).toString(16).substring(1); } return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4(); } })(DataModel = exports.DataModel || (exports.DataModel = {})); }); //# sourceMappingURL=DataModel.js.map
{ "content_hash": "1d7ed65eee12c048ed1accc9169f7f6d", "timestamp": "", "source": "github", "line_count": 284, "max_line_length": 97, "avg_line_length": 39.00704225352113, "alnum_prop": 0.4839321177107781, "repo_name": "anthonyhiga/novelidea", "id": "ab91e9a580a488bf9d1bb2f8e0a0eb7e78de8076", "size": "11137", "binary": false, "copies": "1", "ref": "refs/heads/master", "path": "Noveldea/www/scripts/DataModel.js", "mode": "33188", "license": "mit", "language": [ { "name": "CSS", "bytes": "518046" }, { "name": "HTML", "bytes": "139474" }, { "name": "Java", "bytes": "6311" }, { "name": "JavaScript", "bytes": "2694648" }, { "name": "Objective-C", "bytes": "4012" }, { "name": "TypeScript", "bytes": "20719" } ], "symlink_target": "" }
<?php namespace Snail\App; use Snail\App\Config\SNAIL; use Snail\App\Utils\Debug; class View { /** * @var string * Path to the controllers folder */ private $path_to_controllers = './controllers/'; /** * @var string * Path to the views folder */ private $path_to_views = './views/'; /** * @var bool * Will be true on the first * show/extend/show_hf execution */ private $rendered = false; public function __construct($route = null, $param = null) { if ($route !== null) { /* Build the controller name with provided route */ $controller_name = ucfirst($route) . 'Controller'; /* Check if the controller exists */ $complete_path = $this->path_to_controllers . $controller_name . '.php'; if (!file_exists($complete_path)) { Debug::fatal("Controller: '$controller_name' does not exist"); } /* Require the controller */ require_once $complete_path; /* Render the view */ $object = new $controller_name(); if ($param !== null) { /* Execute show method with provided $param var */ $object->show($param); } else { /* Execute show method without parameters */ $object->show(); } } } /** * @param $view_name string * * Method to render a view from the * views folder. * * Usage: $this->view->show([VIEW]) */ public function show($view_name) { /* Add PHP extension to view name */ $view = strtolower($view_name) . '.php'; $complete_path = $this->path_to_views . $view; if (!file_exists($complete_path)) { Debug::fatal("View: '$view_name' not found"); } /* Require the view */ require_once $complete_path; /* Set rendered to true */ if (!$this->rendered) { $this->rendered = true; } } /** * @param $view_name * * Method for rendering a view with header * and footer file attached * * Usage: $this->view->show_hf([VIEW]) */ public function show_hf($view_name) { /* Add PHP extension to view name */ $view = strtolower($view_name) . '.php'; $complete_path = $this->path_to_views . $view; if (!file_exists($complete_path)) { Debug::fatal("View: '$view_name' not found"); } if (!file_exists(SNAIL::HEADER)) { $header = SNAIL::HEADER; Debug::fatal("View: '$header' not found"); } if (!file_exists(SNAIL::FOOTER)) { $footer = SNAIL::FOOTER; Debug::fatal("View: '$footer' not found"); } /* Require the header */ require_once SNAIL::HEADER; /* Require the view */ require_once $complete_path; /* Require the footer */ require_once SNAIL::FOOTER; /* Set rendered to true */ if (!$this->rendered) { $this->rendered = true; } } }
{ "content_hash": "c3a747acf812a0859de217a544db56b8", "timestamp": "", "source": "github", "line_count": 124, "max_line_length": 84, "avg_line_length": 25.629032258064516, "alnum_prop": 0.5034612964128382, "repo_name": "dennisslimmers01/Snail-MVC", "id": "f7d46711c005b0519a666d750d56bf26940e912c", "size": "3540", "binary": false, "copies": "1", "ref": "refs/heads/master", "path": "app/View.php", "mode": "33188", "license": "mit", "language": [ { "name": "ApacheConf", "bytes": "357" }, { "name": "CSS", "bytes": "37" }, { "name": "JavaScript", "bytes": "1348" }, { "name": "PHP", "bytes": "265936" } ], "symlink_target": "" }
package com.intellij.execution.configurations; import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.util.text.StringUtil; import com.intellij.util.EnvironmentUtil; import com.intellij.util.SmartList; import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.io.File; import java.io.FileFilter; import java.util.Collections; import java.util.List; /** * A collection of utility methods for working with PATH environment variable. */ public class PathEnvironmentVariableUtil { private static final String PATH = "PATH"; private PathEnvironmentVariableUtil() { } /** * Finds an executable file with the specified base name, that is located in a directory * listed in PATH environment variable. * * @param fileBaseName file base name * @return {@link File} instance or null if not found */ @Nullable public static File findInPath(@NotNull String fileBaseName) { return findInPath(fileBaseName, null); } /** * Finds an executable file with the specified base name, that is located in a directory * listed in PATH environment variable and is accepted by filter. * * @param fileBaseName file base name * @param filter exe file filter * @return {@link File} instance or null if not found */ @Nullable public static File findInPath(@NotNull String fileBaseName, @Nullable FileFilter filter) { return findInPath(fileBaseName, EnvironmentUtil.getValue(PATH), filter); } /** * Finds an executable file with the specified base name, that is located in a directory * listed in the passed PATH environment variable value and is accepted by filter. * * @param fileBaseName file base name * @param pathVariableValue value of PATH environment variable * @param filter exe file filter * @return {@link File} instance or null if not found */ @Nullable public static File findInPath(@NotNull String fileBaseName, @Nullable String pathVariableValue, @Nullable FileFilter filter) { List<File> exeFiles = findExeFilesInPath(fileBaseName, true, filter, pathVariableValue); return ContainerUtil.getFirstItem(exeFiles); } /** * Finds an executable file with the specified base name, that is located in a directory * listed in PATH environment variable. * * @param fileBaseName file base name * @param logDetails true if extra logging is needed * @return {@link File} instance or null if not found * * @deprecated use {@link #findInPath(String)} instead */ @Nullable public static File findInPath(@NotNull String fileBaseName, boolean logDetails) { return findInPath(fileBaseName, null); } /** * Finds an executable file with the specified base name, that is located in a directory * listed in an original PATH environment variable. * Original PATH environment variable value is a value returned by <code>System.getenv("PATH")</code>. * * @param fileBaseName file base name * @return {@link File} instance or null if not found */ private static File findInOriginalPath(@NotNull String fileBaseName) { List<File> exeFiles = findExeFilesInPath(fileBaseName, true, null, System.getenv(PATH)); return ContainerUtil.getFirstItem(exeFiles); } /** * Finds all executable files with the specified base name, that are located in directories * from PATH environment variable. * * @param fileBaseName file base name * @return file list */ @NotNull public static List<File> findAllExeFilesInPath(@NotNull String fileBaseName) { return findAllExeFilesInPath(fileBaseName, null); } @NotNull public static List<File> findAllExeFilesInPath(@NotNull String fileBaseName, @Nullable FileFilter filter) { return findExeFilesInPath(fileBaseName, false, filter, EnvironmentUtil.getValue(PATH)); } @NotNull private static List<File> findExeFilesInPath(@NotNull String fileBaseName, boolean stopAfterFirstMatch, @Nullable FileFilter filter, @Nullable String pathEnvVarValue) { if (pathEnvVarValue == null) { return Collections.emptyList(); } List<File> result = new SmartList<>(); List<String> dirPaths = getPathDirs(pathEnvVarValue); for (String dirPath : dirPaths) { File dir = new File(dirPath); if (dir.isAbsolute() && dir.isDirectory()) { File exeFile = new File(dir, fileBaseName); if (exeFile.isFile() && exeFile.canExecute()) { if (filter == null || filter.accept(exeFile)) { result.add(exeFile); if (stopAfterFirstMatch) { return result; } } } } } return result; } @NotNull public static List<String> getPathDirs(@NotNull String pathEnvVarValue) { return StringUtil.split(pathEnvVarValue, File.pathSeparator, true, true); } /** * Alters the passed in exe path to increase probability of exe file success finding when * spawning an external process. Modifications are performed iff the passed in exe path is * a basename (i.e. it doesn't contain slashes). E.g. "java", "git" or "node". * <p> * The motivation behind this modification is as follows. When exe path is a basename, * {@link ProcessBuilder#start} searches for the executable file in the original PATH * environment variable (i.e. {@code System.getenv("PATH")}). * The problem is that on MacOSX original PATH value can be different than the PATH * value in Terminal (see {@link EnvironmentUtil#getEnvironmentMap()}. * * @param exePath String path to exe file (basename, relative path or absolute path) * @return if an exe file can be found in {@code EnvironmentUtil.getValue("PATH")} and * nothing found in original PATH (i.e. {@code System.getenv("PATH")}), * return the found exe file absolute path. * Otherwise, return the passed in exe path. */ @NotNull public static String toLocatableExePath(@NotNull String exePath) { //noinspection deprecation return findAbsolutePathOnMac(exePath); } /** * @deprecated use {@link #toLocatableExePath(String)} instead */ public static String findAbsolutePathOnMac(@NotNull String exePath) { if (SystemInfo.isMac) { if (!StringUtil.containsChar(exePath, '/') && !StringUtil.containsChar(exePath, '\\')) { File originalResolvedExeFile = findInOriginalPath(exePath); // don't modify exePath if the absolute path can be found in the original PATH if (originalResolvedExeFile == null) { File resolvedExeFile = findInPath(exePath); if (resolvedExeFile != null) { exePath = resolvedExeFile.getAbsolutePath(); } } } } return exePath; } }
{ "content_hash": "4177b3938bcd2af88f6d2a37a8849741", "timestamp": "", "source": "github", "line_count": 183, "max_line_length": 128, "avg_line_length": 37.9344262295082, "alnum_prop": 0.6914433880726015, "repo_name": "semonte/intellij-community", "id": "ea4bcab1f2e5b6f6eabe98c053a8bd69702290cf", "size": "7542", "binary": false, "copies": "2", "ref": "refs/heads/master", "path": "platform/platform-api/src/com/intellij/execution/configurations/PathEnvironmentVariableUtil.java", "mode": "33188", "license": "apache-2.0", "language": [ { "name": "AMPL", "bytes": "20665" }, { "name": "AspectJ", "bytes": "182" }, { "name": "Batchfile", "bytes": "60580" }, { "name": "C", "bytes": "211556" }, { "name": "C#", "bytes": "1264" }, { "name": "C++", "bytes": "197528" }, { "name": "CMake", "bytes": "1675" }, { "name": "CSS", "bytes": "201445" }, { "name": "CoffeeScript", "bytes": "1759" }, { "name": "Erlang", "bytes": "10" }, { "name": "Groovy", "bytes": "3222009" }, { "name": "HLSL", "bytes": "57" }, { "name": "HTML", "bytes": "1895767" }, { "name": "J", "bytes": "5050" }, { "name": "Java", "bytes": "164918191" }, { "name": "JavaScript", "bytes": "570364" }, { "name": "Jupyter Notebook", "bytes": "93222" }, { "name": "Kotlin", "bytes": "4472431" }, { "name": "Lex", "bytes": "147154" }, { "name": "Makefile", "bytes": "2352" }, { "name": "NSIS", "bytes": "51270" }, { "name": "Objective-C", "bytes": "27941" }, { "name": "Perl", "bytes": "903" }, { "name": "Perl6", "bytes": "26" }, { "name": "Protocol Buffer", "bytes": "6680" }, { "name": "Python", "bytes": "25421481" }, { "name": "Roff", "bytes": "37534" }, { "name": "Ruby", "bytes": "1217" }, { "name": "Scala", "bytes": "11698" }, { "name": "Shell", "bytes": "65719" }, { "name": "Smalltalk", "bytes": "338" }, { "name": "TeX", "bytes": "25473" }, { "name": "Thrift", "bytes": "1846" }, { "name": "TypeScript", "bytes": "9469" }, { "name": "Visual Basic", "bytes": "77" }, { "name": "XSLT", "bytes": "113040" } ], "symlink_target": "" }
(function () { 'use strict'; angular.module('auth.admin') .directive('svManagerProfileSummary', function () { return { replace: true, templateUrl: 'scripts/auth/manager/directives/sv-manager-profile-summary.html', scope: {}, link: function ($scope, el, attrs) { } }; }); })();
{ "content_hash": "481984b9683de53553ae9a50009679f9", "timestamp": "", "source": "github", "line_count": 13, "max_line_length": 95, "avg_line_length": 32.15384615384615, "alnum_prop": 0.4569377990430622, "repo_name": "SvitlanaShepitsena/svet-media-node", "id": "739ff6d6bbb69d72578e2e32ad2fefdb9d84b3dc", "size": "418", "binary": false, "copies": "1", "ref": "refs/heads/master", "path": "app/scripts/auth/manager/directives/sv-manager-profile-summary.js", "mode": "33188", "license": "mit", "language": [ { "name": "CSS", "bytes": "122771" }, { "name": "HTML", "bytes": "593835" }, { "name": "JavaScript", "bytes": "510677" }, { "name": "Objective-J", "bytes": "148" }, { "name": "Smarty", "bytes": "989" } ], "symlink_target": "" }
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Nucleo.DataMapper.Incrementing { /// <summary> /// Represents the collection of mappings. /// </summary> public class IncrementMappings { private IncrementMappingCollection _values = null; #region " Properties " /// <summary> /// Gets the number of registered mappings. /// </summary> public int MappingCount { get { return this._values.Count; } } private IncrementMappingCollection Values { get { if (_values == null) _values = new IncrementMappingCollection(); return _values; } } #endregion #region " Methods " /// <summary> /// Gets the mapping at the specified index. /// </summary> /// <param name="index">The index to look at.</param> /// <returns>The mapping found or null.</returns> /// <remarks>If the value is out of range, a null is returned.</remarks> public IncrementMapping GetMapping(int index) { if (this.Values.Count >= index || index < 0) return null; return this.Values[index]; } /// <summary> /// Gets the complete collection of mappings. /// </summary> /// <returns>The collection of mappings.</returns> public IncrementMappingCollection GetMappings() { return this.Values; } /// <summary> /// Returns whether all of the mappings, when being iterated through, are at the zero index position. /// </summary> /// <returns>Whether at all zeros.</returns> public bool IsAtAllZeros() { foreach (IncrementMapping mapping in this.Values) { if (mapping.CurrentValueIndex != 0) return false; } return true; } public void Register(string field, object[] values) { this.Values.Add(new IncrementMapping { Field = field, Values = values, CurrentValueIndex = 0 }); } #endregion } }
{ "content_hash": "cb7029564a8bf936bfe8cdefb5ce79d5", "timestamp": "", "source": "github", "line_count": 88, "max_line_length": 103, "avg_line_length": 21.045454545454547, "alnum_prop": 0.661987041036717, "repo_name": "brianmains/Nucleo.NET", "id": "b036b716d9535a3d1e5df190b4c581fafd178bb9", "size": "1854", "binary": false, "copies": "3", "ref": "refs/heads/master", "path": "src_wip/Orm/4.0/Nucleo.Orm.Core/DataMapper/Incrementing/IncrementMappings.cs", "mode": "33188", "license": "mit", "language": [ { "name": "ASP", "bytes": "546493" }, { "name": "Batchfile", "bytes": "546" }, { "name": "C#", "bytes": "6202251" }, { "name": "CSS", "bytes": "278033" }, { "name": "HTML", "bytes": "1371610" }, { "name": "JavaScript", "bytes": "767255" }, { "name": "PowerShell", "bytes": "44718" }, { "name": "Smalltalk", "bytes": "172636" }, { "name": "XSLT", "bytes": "21697" } ], "symlink_target": "" }
namespace blink { namespace scheduler { WebTaskRunnerImpl::WebTaskRunnerImpl(scoped_refptr<TaskQueue> task_queue) : task_queue_(task_queue) {} WebTaskRunnerImpl::~WebTaskRunnerImpl() {} void WebTaskRunnerImpl::postTask(const blink::WebTraceLocation& location, blink::WebTaskRunner::Task* task) { task_queue_->PostTask(location, base::Bind(&WebTaskRunnerImpl::runTask, base::Passed(base::WrapUnique(task)))); } void WebTaskRunnerImpl::postDelayedTask(const blink::WebTraceLocation& location, blink::WebTaskRunner::Task* task, double delayMs) { DCHECK_GE(delayMs, 0.0); task_queue_->PostDelayedTask(location, base::Bind(&WebTaskRunnerImpl::runTask, base::Passed(base::WrapUnique(task))), base::TimeDelta::FromMillisecondsD(delayMs)); } bool WebTaskRunnerImpl::runsTasksOnCurrentThread() { return task_queue_->RunsTasksOnCurrentThread(); } double WebTaskRunnerImpl::virtualTimeSeconds() const { return (Now() - base::TimeTicks::UnixEpoch()).InSecondsF(); } double WebTaskRunnerImpl::monotonicallyIncreasingVirtualTimeSeconds() const { return Now().ToInternalValue() / static_cast<double>(base::Time::kMicrosecondsPerSecond); } base::TimeTicks WebTaskRunnerImpl::Now() const { TimeDomain* time_domain = task_queue_->GetTimeDomain(); // It's possible task_queue_ has been Unregistered which can lead to a null // TimeDomain. If that happens just return the current real time. if (!time_domain) return base::TimeTicks::Now(); return time_domain->Now(); } std::unique_ptr<blink::WebTaskRunner> WebTaskRunnerImpl::clone() { return base::WrapUnique(new WebTaskRunnerImpl(task_queue_)); } base::SingleThreadTaskRunner* WebTaskRunnerImpl::taskRunner() { return task_queue_.get(); } void WebTaskRunnerImpl::runTask( std::unique_ptr<blink::WebTaskRunner::Task> task) { task->run(); } } // namespace scheduler } // namespace blink
{ "content_hash": "2e3d5443364630b377384c90dbbdac79", "timestamp": "", "source": "github", "line_count": 62, "max_line_length": 80, "avg_line_length": 34.79032258064516, "alnum_prop": 0.6518312471024571, "repo_name": "danakj/chromium", "id": "3144fcaab010338f256d487ca876de7862375d58", "size": "2618", "binary": false, "copies": "1", "ref": "refs/heads/master", "path": "third_party/WebKit/Source/platform/scheduler/child/web_task_runner_impl.cc", "mode": "33188", "license": "bsd-3-clause", "language": [], "symlink_target": "" }
@interface VideoPlayerViewController : UIViewController<YouTubeDirectTagDelegate, UIWebViewDelegate> @property(nonatomic, strong) UIWebView *webView; @property(nonatomic, strong) VideoData *videoData; @property(nonatomic, retain) GTLServiceYouTube *youtubeService; @property(nonatomic, strong) YouTubeDirectTag *directTag; @end
{ "content_hash": "dc47f4134ac049fb2a8a26f1a3ece082", "timestamp": "", "source": "github", "line_count": 6, "max_line_length": 100, "avg_line_length": 54.5, "alnum_prop": 0.8440366972477065, "repo_name": "hash3r/ios-app-youtube-token-test", "id": "656221362c247ba27b09dcc97098b4730ae91224", "size": "572", "binary": false, "copies": "5", "ref": "refs/heads/master", "path": "iosapp-token-test/iosapp-token-test/VideoPlayerViewController.h", "mode": "33188", "license": "mit", "language": [ { "name": "C", "bytes": "113530" }, { "name": "C++", "bytes": "2926" }, { "name": "Objective-C", "bytes": "4103876" }, { "name": "Ruby", "bytes": "55" }, { "name": "Shell", "bytes": "3618" } ], "symlink_target": "" }
package ru.contextguide.adgroup.dynamicTextAdGroup; //TODO public class DynamicTextAdGroupFieldEnum { }
{ "content_hash": "0340b1205292a39c75b83e1ee09c7600", "timestamp": "", "source": "github", "line_count": 5, "max_line_length": 51, "avg_line_length": 21, "alnum_prop": 0.8380952380952381, "repo_name": "kubikrubikvkube/yandexDirectJavaApi", "id": "91665bfee232ce2b61d4f6ef50d07b21a45928b6", "size": "105", "binary": false, "copies": "1", "ref": "refs/heads/master", "path": "src/main/java/ru/contextguide/adgroup/dynamicTextAdGroup/DynamicTextAdGroupFieldEnum.java", "mode": "33188", "license": "apache-2.0", "language": [ { "name": "Java", "bytes": "373161" } ], "symlink_target": "" }
 using Markdig.Renderers.Agg.Inlines; using MatterHackers.MatterControl; namespace Markdig.Renderers.Agg { public class AggMatchingTextRenderer : AggObjectRenderer<MatchingTextInline> { private ThemeConfig theme; public AggMatchingTextRenderer(ThemeConfig theme) { this.theme = theme; } protected override void Write(AggRenderer renderer, MatchingTextInline obj) { renderer.Push(new CodeInlineX(theme) { BackgroundColor = theme.AccentMimimalOverlay }); renderer.WriteText(obj.MatchingText); renderer.Pop(); } } }
{ "content_hash": "d92983e69c1424b7cd08a2a1363b21e2", "timestamp": "", "source": "github", "line_count": 27, "max_line_length": 77, "avg_line_length": 20.62962962962963, "alnum_prop": 0.755834829443447, "repo_name": "jlewin/MatterControl", "id": "1615c443f4fd60fc0a03d546dfc80b16594fa0a3", "size": "2084", "binary": false, "copies": "2", "ref": "refs/heads/master", "path": "MatterControlLib/Utilities/MarkdigAgg/AggMatchingTextRenderer.cs", "mode": "33188", "license": "bsd-2-clause", "language": [ { "name": "C", "bytes": "1007" }, { "name": "C#", "bytes": "9250078" }, { "name": "C++", "bytes": "8783" }, { "name": "G-code", "bytes": "1473799" }, { "name": "Shell", "bytes": "322" } ], "symlink_target": "" }
package bingo.lang; public abstract class Lazy1<T,R> implements Func1<T,R>{ private transient R r; public final R apply(T in) { if(null == r){ r = get(in); } return r; } protected abstract R get(T in); }
{ "content_hash": "3bab2d3acd20bf684d1a2d8c51bf2f43", "timestamp": "", "source": "github", "line_count": 16, "max_line_length": 55, "avg_line_length": 15, "alnum_prop": 0.5875, "repo_name": "bingo-open-source/bingo-core", "id": "96269caf31e9a1b1d4ef4ac2100266f18fa51374", "size": "869", "binary": false, "copies": "1", "ref": "refs/heads/master", "path": "core-lang/src/main/java/bingo/lang/Lazy1.java", "mode": "33188", "license": "apache-2.0", "language": [ { "name": "Java", "bytes": "3273591" } ], "symlink_target": "" }
require 'spec_helper' describe MergeWorker do describe "remove source branch" do let!(:merge_request) { create(:merge_request, source_branch: "markdown") } let!(:source_project) { merge_request.source_project } let!(:project) { merge_request.project } let!(:author) { merge_request.author } before do source_project.add_maintainer(author) source_project.repository.expire_branches_cache end it 'clears cache of source repo after removing source branch' do expect(source_project.repository.branch_names).to include('markdown') described_class.new.perform( merge_request.id, merge_request.author_id, commit_message: 'wow such merge', should_remove_source_branch: true) merge_request.reload expect(merge_request).to be_merged source_project.repository.expire_branches_cache expect(source_project.repository.branch_names).not_to include('markdown') end end end
{ "content_hash": "fe627d74748993066ed23378b2b6a566", "timestamp": "", "source": "github", "line_count": 30, "max_line_length": 79, "avg_line_length": 32.36666666666667, "alnum_prop": 0.698249227600412, "repo_name": "stoplightio/gitlabhq", "id": "138a99abde67bda60a048b7fc6252f9041bd487b", "size": "1002", "binary": false, "copies": "2", "ref": "refs/heads/stoplight/develop", "path": "spec/workers/merge_worker_spec.rb", "mode": "33188", "license": "mit", "language": [ { "name": "CSS", "bytes": "632980" }, { "name": "Clojure", "bytes": "79" }, { "name": "Dockerfile", "bytes": "1676" }, { "name": "HTML", "bytes": "1264236" }, { "name": "JavaScript", "bytes": "3425347" }, { "name": "Ruby", "bytes": "16497064" }, { "name": "Shell", "bytes": "34509" }, { "name": "Vue", "bytes": "752795" } ], "symlink_target": "" }
// Copyright (c) 2013-2021 niXman (github dotty nixman doggy pm dotty me) // All rights reserved. // // This file is part of EASYNET(https://github.com/niXman/easynet) project. // // Redistribution and use in source and binary forms, with or without modification, // are permitted provided that the following conditions are met: // // Redistributions of source code must retain the above copyright notice, this // list of conditions and the following disclaimer. // // Redistributions in binary form must reproduce the above copyright notice, this // list of conditions and the following disclaimer in the documentation and/or // other materials provided with the distribution. // // Neither the name of the {organization} nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef __easynet__handler_allocator_hpp #define __easynet__handler_allocator_hpp #include <type_traits> #include <memory> namespace easynet { /***************************************************************************/ template<std::size_t alloc_size> struct handler_allocator { handler_allocator(const handler_allocator &) = delete; handler_allocator& operator=(const handler_allocator &) = delete; handler_allocator(handler_allocator &&) = default; handler_allocator& operator=(handler_allocator &&) = default; handler_allocator() :in_use(false) {} void *allocate(std::size_t size) { if (!in_use && size <= alloc_size) { in_use = true; return std::addressof(storage); } return ::operator new(size); } void deallocate(void *pointer) { if (std::addressof(storage) == pointer) { in_use = false; } else { ::operator delete(pointer); } } private: typename std::aligned_storage<alloc_size>::type storage; bool in_use; }; /***************************************************************************/ } // namespace easynet #endif // __easynet__handler_allocator_hpp
{ "content_hash": "9dd101dab50deae264d713e1b6675288", "timestamp": "", "source": "github", "line_count": 80, "max_line_length": 83, "avg_line_length": 36.3875, "alnum_prop": 0.6702164204740639, "repo_name": "niXman/easynet", "id": "9c306d2746bb0054f2cdc9c7c5c4311b449aca5d", "size": "2911", "binary": false, "copies": "1", "ref": "refs/heads/master", "path": "include/easynet/handler_allocator.hpp", "mode": "33188", "license": "mit", "language": [ { "name": "C++", "bytes": "72792" } ], "symlink_target": "" }
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN" "http://struts.apache.org/dtds/struts-2.3.dtd"> <struts> <package name="default-wechat" namespace="/wechat" extends="default" > <interceptors> <interceptor name="WechatInterceptor" class="interceptor.WechatInterceptor"> </interceptor> <!-- 拦截器栈 --> <interceptor-stack name="wechatDefault"> <interceptor-ref name="noLoginStack" /> <interceptor-ref name="WechatInterceptor" /> </interceptor-stack> </interceptors> <default-interceptor-ref name="wechatDefault"></default-interceptor-ref> <global-results> <result name="message">/pages/wechat/wechatMessage.jsp</result> <result name="redirectBinding">/pages/wechat/userBindingRedirect.jsp</result> </global-results> </package> <package name="wechat" namespace="/wechat" extends="default-wechat"> <action name="redirect" class="actions.wechat.WechatRedirect" method="redirect"> <result name="success">/pages/wechat/redirect.jsp</result> </action> <action name="userBinding" class="actions.wechat.WechatUserAction" method="binding"> <result name="success">/pages/wechat/userBinding.jsp</result> <result name="releaseBinding">/pages/wechat/userBindingRelease.jsp</result> </action> <action name="userBindingRelease" class="actions.wechat.WechatUserAction" method="releaseBinding"> <result name="success">/pages/wechat/userBinding.jsp</result> </action> <action name="userBindingSubmit" class="actions.wechat.WechatUserAction" method="bindingSubmit"> <result name="success">/pages/wechat/userBindingSuccess.jsp</result> <result name="error">/pages/wechat/userBinding.jsp</result> </action> <action name="checkIn" class="actions.wechat.WechatServiceAction" method="checkIn"> <result name="success">/pages/wechat/checkIn.jsp</result> <result name="checkout">/pages/wechat/checkOut.jsp</result> <result name="login">/pages/wechat/userBindingRedirect.jsp</result> <result name="error">/pages/wechat/wechatError.jsp</result> </action> <action name="checkInSubmit" class="actions.wechat.WechatServiceAction" method="checkInSubmit"> <result name="success">/pages/wechat/wechatMessage.jsp</result> </action> <action name="checkOut" class="actions.wechat.WechatServiceAction" method="checkOut"> <result name="success">/pages/wechat/checkOut.jsp</result> <result name="error">/pages/wechat/wechatMessage.jsp</result> </action> <action name="checkOutSubmit" class="actions.wechat.WechatServiceAction" method="checkOutSubmit"> <result name="success">/pages/wechat/wechatMessage.jsp</result> </action> <action name="peopleHere" class="actions.wechat.WechatUserAction" method="searchActiveUser"> <result name="success">/pages/wechat/searchActiveUser.jsp</result> </action> <action name="volunteerRecruit" class="actions.wechat.WechatRecruitAction" method="volunteerRecruitView"> <result name="success">/pages/wechat/volunteerrecruit.jsp</result> </action> <action name="volunteerRecruitSave" class="actions.wechat.WechatRecruitAction" method="volunteerRecruitSave"> <result name="success">/pages/wechat/volunteerrecruitsuccess.jsp</result> <result name="error">/pages/wechat/volunteerrecruit.jsp</result> </action> <action name="myAdvise" class="actions.wechat.WechatBaseAuthAction" method="execute"> <result name="success">/pages/wechat/developing.jsp</result> </action> <action name="currentActivity" class="actions.wechat.WechatBaseAuthAction" method="execute"> <result name="success">/pages/wechat/developing.jsp</result> </action> <action name="serviceDescription" class="actions.wechat.WechatServiceDescriptionAction" method="outDescription"> <result name="success">/pages/wechat/servicedescription.jsp</result> </action> <action name="productList" class="actions.wechat.WechatProductAction" method="search"> <result name="success">/pages/wechat/productList.jsp</result> </action> <action name="loadRecords" class="actions.wechat.WechatProductAction" method="loadRecords"> <result name="success" type="freemarker">/ftl/wechat/lazyLoadImages.ftl</result> </action> <action name="queryOrders" class="actions.wechat.WechatOrderAction" method="query"> <result name="success">/pages/wechat/orderList.jsp</result> </action> <action name="getOrderDetails" class="actions.wechat.WechatOrderAction" method="getOrder"> <result name="success">/pages/wechat/orderDetail.jsp</result> </action> <action name="mainPage" class="actions.wechat.WechatProductAction" method="main"> <result name="success">/pages/wechat/mainPage.jsp</result> </action> </package> <package name="user" namespace="/wechat/user" extends="default-wechat"> <action name="myInfo" class="actions.wechat.WechatUserAction" method="myInfo"> <result name="success">/pages/wechat/userMyInfo.jsp</result> </action> <action name="save" class="actions.wechat.WechatUserAction" method="save"> <result name="success">/pages/wechat/wechatMessage.jsp</result> </action> <action name="myHonor" class="actions.wechat.WechatUserAction" method="myHonor"> <result name="success">/pages/wechat/developing.jsp</result> </action> <action name="register" class="actions.wechat.WechatUserAction" method="register"> <result name="failure">/pages/wechat/register.jsp</result> <result name="success">/pages/wechat/registerSuccess.jsp</result> </action> </package> <package name="trainCourse" namespace="/wechat/trainCourse" extends="default-wechat"> <action name="myTrainCourse" class="actions.wechat.WechatTrainCourseAction" method="myTrainCourse"> <result name="success">/pages/wechat/myTrainCourse.jsp</result> </action> </package> </struts>
{ "content_hash": "046c07e6b3260e2e518575307d4638af", "timestamp": "", "source": "github", "line_count": 121, "max_line_length": 120, "avg_line_length": 54.09090909090909, "alnum_prop": 0.6603514132925897, "repo_name": "nature2014/nature", "id": "f72b723019732721b166c2689e9438f4f4b7f41a", "size": "6553", "binary": false, "copies": "1", "ref": "refs/heads/master", "path": "srcresources/struts-wechat.xml", "mode": "33188", "license": "apache-2.0", "language": [ { "name": "ActionScript", "bytes": "41334" }, { "name": "ApacheConf", "bytes": "1199" }, { "name": "CSS", "bytes": "1404909" }, { "name": "CoffeeScript", "bytes": "80553" }, { "name": "Go", "bytes": "13788" }, { "name": "HTML", "bytes": "4021853" }, { "name": "Java", "bytes": "985029" }, { "name": "JavaScript", "bytes": "6717720" }, { "name": "Makefile", "bytes": "636" }, { "name": "PHP", "bytes": "246996" }, { "name": "Python", "bytes": "11017" }, { "name": "Shell", "bytes": "7411" } ], "symlink_target": "" }
/** * AtomicHashArray is the building block for AtomicHashMap. It provides the * core lock-free functionality, but is limited by the fact that it cannot * grow past its initialization size and is a little more awkward (no public * constructor, for example). If you're confident that you won't run out of * space, don't mind the awkardness, and really need bare-metal performance, * feel free to use AHA directly. * * Check out AtomicHashMap.h for more thorough documentation on perf and * general pros and cons relative to other hash maps. * * @author Spencer Ahrens <[email protected]> * @author Jordan DeLong <[email protected]> */ #pragma once #define FOLLY_ATOMICHASHARRAY_H_ #include <atomic> #include <boost/iterator/iterator_facade.hpp> #include <boost/noncopyable.hpp> #include <folly/Hash.h> #include <folly/ThreadCachedInt.h> namespace folly { struct AtomicHashArrayLinearProbeFcn { inline size_t operator()(size_t idx, size_t /* numProbes */, size_t capacity) const { idx += 1; // linear probing // Avoid modulus because it's slow return LIKELY(idx < capacity) ? idx : (idx - capacity); } }; struct AtomicHashArrayQuadraticProbeFcn { inline size_t operator()(size_t idx, size_t numProbes, size_t capacity) const{ idx += numProbes; // quadratic probing // Avoid modulus because it's slow return LIKELY(idx < capacity) ? idx : (idx - capacity); } }; // Enables specializing checkLegalKey without specializing its class. namespace detail { // Local copy of folly::gen::Identity, to avoid heavy dependencies. class AHAIdentity { public: template<class Value> auto operator()(Value&& value) const -> decltype(std::forward<Value>(value)) { return std::forward<Value>(value); } }; template <typename NotKeyT, typename KeyT> inline void checkLegalKeyIfKeyTImpl(NotKeyT /* ignored */, KeyT /* emptyKey */, KeyT /* lockedKey */, KeyT /* erasedKey */) {} template <typename KeyT> inline void checkLegalKeyIfKeyTImpl(KeyT key_in, KeyT emptyKey, KeyT lockedKey, KeyT erasedKey) { DCHECK_NE(key_in, emptyKey); DCHECK_NE(key_in, lockedKey); DCHECK_NE(key_in, erasedKey); } } // namespace detail template <class KeyT, class ValueT, class HashFcn = std::hash<KeyT>, class EqualFcn = std::equal_to<KeyT>, class Allocator = std::allocator<char>, class ProbeFcn = AtomicHashArrayLinearProbeFcn, class KeyConvertFcn = detail::AHAIdentity> class AtomicHashMap; template <class KeyT, class ValueT, class HashFcn = std::hash<KeyT>, class EqualFcn = std::equal_to<KeyT>, class Allocator = std::allocator<char>, class ProbeFcn = AtomicHashArrayLinearProbeFcn, class KeyConvertFcn = detail::AHAIdentity> class AtomicHashArray : boost::noncopyable { static_assert((std::is_convertible<KeyT,int32_t>::value || std::is_convertible<KeyT,int64_t>::value || std::is_convertible<KeyT,const void*>::value), "You are trying to use AtomicHashArray with disallowed key " "types. You must use atomically compare-and-swappable integer " "keys, or a different container class."); public: typedef KeyT key_type; typedef ValueT mapped_type; typedef HashFcn hasher; typedef EqualFcn key_equal; typedef KeyConvertFcn key_convert; typedef std::pair<const KeyT, ValueT> value_type; typedef std::size_t size_type; typedef std::ptrdiff_t difference_type; typedef value_type& reference; typedef const value_type& const_reference; typedef value_type* pointer; typedef const value_type* const_pointer; const size_t capacity_; const size_t maxEntries_; const KeyT kEmptyKey_; const KeyT kLockedKey_; const KeyT kErasedKey_; template<class ContT, class IterVal> struct aha_iterator; typedef aha_iterator<const AtomicHashArray,const value_type> const_iterator; typedef aha_iterator<AtomicHashArray,value_type> iterator; // You really shouldn't need this if you use the SmartPtr provided by create, // but if you really want to do something crazy like stick the released // pointer into a DescriminatedPtr or something, you'll need this to clean up // after yourself. static void destroy(AtomicHashArray*); private: const size_t kAnchorMask_; struct Deleter { void operator()(AtomicHashArray* ptr) { AtomicHashArray::destroy(ptr); } }; public: typedef std::unique_ptr<AtomicHashArray, Deleter> SmartPtr; /* * create -- * * Creates AtomicHashArray objects. Use instead of constructor/destructor. * * We do things this way in order to avoid the perf penalty of a second * pointer indirection when composing these into AtomicHashMap, which needs * to store an array of pointers so that it can perform atomic operations on * them when growing. * * Instead of a mess of arguments, we take a max size and a Config struct to * simulate named ctor parameters. The Config struct has sensible defaults * for everything, but is overloaded - if you specify a positive capacity, * that will be used directly instead of computing it based on * maxLoadFactor. * * Create returns an AHA::SmartPtr which is a unique_ptr with a custom * deleter to make sure everything is cleaned up properly. */ struct Config { KeyT emptyKey; KeyT lockedKey; KeyT erasedKey; double maxLoadFactor; double growthFactor; uint32_t entryCountThreadCacheSize; size_t capacity; // if positive, overrides maxLoadFactor public: // Cannot have constexpr ctor because some compilers rightly complain. Config() : emptyKey((KeyT)-1), lockedKey((KeyT)-2), erasedKey((KeyT)-3), maxLoadFactor(0.8), growthFactor(-1), entryCountThreadCacheSize(1000), capacity(0) {} }; // Cannot have pre-instantiated const Config instance because of SIOF. static SmartPtr create(size_t maxSize, const Config& c = Config()); /* * find -- * * * Returns the iterator to the element if found, otherwise end(). * * As an optional feature, the type of the key to look up (LookupKeyT) is * allowed to be different from the type of keys actually stored (KeyT). * * This enables use cases where materializing the key is costly and usually * redudant, e.g., canonicalizing/interning a set of strings and being able * to look up by StringPiece. To use this feature, LookupHashFcn must take * a LookupKeyT, and LookupEqualFcn must take KeyT and LookupKeyT as first * and second parameter, respectively. * * See folly/test/ArrayHashArrayTest.cpp for sample usage. */ template <typename LookupKeyT = key_type, typename LookupHashFcn = hasher, typename LookupEqualFcn = key_equal> iterator find(LookupKeyT k) { return iterator(this, findInternal<LookupKeyT, LookupHashFcn, LookupEqualFcn>(k).idx); } template <typename LookupKeyT = key_type, typename LookupHashFcn = hasher, typename LookupEqualFcn = key_equal> const_iterator find(LookupKeyT k) const { return const_cast<AtomicHashArray*>(this)-> find<LookupKeyT, LookupHashFcn, LookupEqualFcn>(k); } /* * insert -- * * Returns a pair with iterator to the element at r.first and bool success. * Retrieve the index with ret.first.getIndex(). * * Fails on key collision (does not overwrite) or if map becomes * full, at which point no element is inserted, iterator is set to end(), * and success is set false. On collisions, success is set false, but the * iterator is set to the existing entry. */ std::pair<iterator,bool> insert(const value_type& r) { return emplace(r.first, r.second); } std::pair<iterator,bool> insert(value_type&& r) { return emplace(r.first, std::move(r.second)); } /* * emplace -- * * Same contract as insert(), but performs in-place construction * of the value type using the specified arguments. * * Also, like find(), this method optionally allows 'key_in' to have a type * different from that stored in the table; see find(). If and only if no * equal key is already present, this method converts 'key_in' to a key of * type KeyT using the provided LookupKeyToKeyFcn. */ template <typename LookupKeyT = key_type, typename LookupHashFcn = hasher, typename LookupEqualFcn = key_equal, typename LookupKeyToKeyFcn = key_convert, typename... ArgTs> std::pair<iterator,bool> emplace(LookupKeyT key_in, ArgTs&&... vCtorArgs) { SimpleRetT ret = insertInternal<LookupKeyT, LookupHashFcn, LookupEqualFcn, LookupKeyToKeyFcn>( key_in, std::forward<ArgTs>(vCtorArgs)...); return std::make_pair(iterator(this, ret.idx), ret.success); } // returns the number of elements erased - should never exceed 1 size_t erase(KeyT k); // clears all keys and values in the map and resets all counters. Not thread // safe. void clear(); // Exact number of elements in the map - note that readFull() acquires a // mutex. See folly/ThreadCachedInt.h for more details. size_t size() const { return numEntries_.readFull() - numErases_.load(std::memory_order_relaxed); } bool empty() const { return size() == 0; } iterator begin() { iterator it(this, 0); it.advancePastEmpty(); return it; } const_iterator begin() const { const_iterator it(this, 0); it.advancePastEmpty(); return it; } iterator end() { return iterator(this, capacity_); } const_iterator end() const { return const_iterator(this, capacity_); } // See AtomicHashMap::findAt - access elements directly // WARNING: The following 2 functions will fail silently for hashtable // with capacity > 2^32 iterator findAt(uint32_t idx) { DCHECK_LT(idx, capacity_); return iterator(this, idx); } const_iterator findAt(uint32_t idx) const { return const_cast<AtomicHashArray*>(this)->findAt(idx); } iterator makeIter(size_t idx) { return iterator(this, idx); } const_iterator makeIter(size_t idx) const { return const_iterator(this, idx); } // The max load factor allowed for this map double maxLoadFactor() const { return ((double) maxEntries_) / capacity_; } void setEntryCountThreadCacheSize(uint32_t newSize) { numEntries_.setCacheSize(newSize); numPendingEntries_.setCacheSize(newSize); } uint32_t getEntryCountThreadCacheSize() const { return numEntries_.getCacheSize(); } /* Private data and helper functions... */ private: friend class AtomicHashMap<KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn>; struct SimpleRetT { size_t idx; bool success; SimpleRetT(size_t i, bool s) : idx(i), success(s) {} SimpleRetT() = default; }; template <typename LookupKeyT = key_type, typename LookupHashFcn = hasher, typename LookupEqualFcn = key_equal, typename LookupKeyToKeyFcn = detail::AHAIdentity, typename... ArgTs> SimpleRetT insertInternal(LookupKeyT key, ArgTs&&... vCtorArgs); template <typename LookupKeyT = key_type, typename LookupHashFcn = hasher, typename LookupEqualFcn = key_equal> SimpleRetT findInternal(const LookupKeyT key); template <typename MaybeKeyT> void checkLegalKeyIfKey(MaybeKeyT key) { detail::checkLegalKeyIfKeyTImpl(key, kEmptyKey_, kLockedKey_, kErasedKey_); } static std::atomic<KeyT>* cellKeyPtr(const value_type& r) { // We need some illegal casting here in order to actually store // our value_type as a std::pair<const,>. But a little bit of // undefined behavior never hurt anyone ... static_assert(sizeof(std::atomic<KeyT>) == sizeof(KeyT), "std::atomic is implemented in an unexpected way for AHM"); return const_cast<std::atomic<KeyT>*>( reinterpret_cast<std::atomic<KeyT> const*>(&r.first)); } static KeyT relaxedLoadKey(const value_type& r) { return cellKeyPtr(r)->load(std::memory_order_relaxed); } static KeyT acquireLoadKey(const value_type& r) { return cellKeyPtr(r)->load(std::memory_order_acquire); } // Fun with thread local storage - atomic increment is expensive // (relatively), so we accumulate in the thread cache and periodically // flush to the actual variable, and walk through the unflushed counts when // reading the value, so be careful of calling size() too frequently. This // increases insertion throughput several times over while keeping the count // accurate. ThreadCachedInt<uint64_t> numEntries_; // Successful key inserts ThreadCachedInt<uint64_t> numPendingEntries_; // Used by insertInternal std::atomic<int64_t> isFull_; // Used by insertInternal std::atomic<int64_t> numErases_; // Successful key erases value_type cells_[0]; // This must be the last field of this class // Force constructor/destructor private since create/destroy should be // used externally instead AtomicHashArray( size_t capacity, KeyT emptyKey, KeyT lockedKey, KeyT erasedKey, double maxLoadFactor, uint32_t cacheSize); ~AtomicHashArray() = default; inline void unlockCell(value_type* const cell, KeyT newKey) { cellKeyPtr(*cell)->store(newKey, std::memory_order_release); } inline bool tryLockCell(value_type* const cell) { KeyT expect = kEmptyKey_; return cellKeyPtr(*cell)->compare_exchange_strong(expect, kLockedKey_, std::memory_order_acq_rel); } template <class LookupKeyT = key_type, class LookupHashFcn = hasher> inline size_t keyToAnchorIdx(const LookupKeyT k) const { const size_t hashVal = LookupHashFcn()(k); const size_t probe = hashVal & kAnchorMask_; return LIKELY(probe < capacity_) ? probe : hashVal % capacity_; } }; // AtomicHashArray } // namespace folly #include <folly/AtomicHashArray-inl.h>
{ "content_hash": "cb744265bd4f1c23c3a08c1068c510e4", "timestamp": "", "source": "github", "line_count": 422, "max_line_length": 80, "avg_line_length": 34.867298578199055, "alnum_prop": 0.6578088894929999, "repo_name": "floxard/folly", "id": "96a647d1a3da6bcf0e0f907273a20da1c09f7a24", "size": "15309", "binary": false, "copies": "3", "ref": "refs/heads/packaging-57-0", "path": "folly/AtomicHashArray.h", "mode": "33188", "license": "apache-2.0", "language": [ { "name": "Assembly", "bytes": "4324" }, { "name": "C", "bytes": "69341" }, { "name": "C++", "bytes": "10321995" }, { "name": "CMake", "bytes": "29766" }, { "name": "CSS", "bytes": "165" }, { "name": "M4", "bytes": "109274" }, { "name": "Makefile", "bytes": "45592" }, { "name": "Objective-C", "bytes": "3143" }, { "name": "Python", "bytes": "470318" }, { "name": "Ruby", "bytes": "1531" }, { "name": "Shell", "bytes": "34043" } ], "symlink_target": "" }
All Notable changes to `gravitymedia/ghostscript` will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). ## NEXT - YYYY-MM-DD ### Added - Nothing ### Changed - Nothing ### Deprecated - Nothing ### Removed - Nothing ### Fixed - Nothing ### Security - Nothing
{ "content_hash": "569fed60126c269aa82bd67b293fda40", "timestamp": "", "source": "github", "line_count": 22, "max_line_length": 82, "avg_line_length": 14.136363636363637, "alnum_prop": 0.6913183279742765, "repo_name": "GravityMedia/Ghostscript", "id": "637b564a44b496a1b7ca68d12bffce62689587d3", "size": "324", "binary": false, "copies": "1", "ref": "refs/heads/master", "path": "CHANGELOG.md", "mode": "33188", "license": "mit", "language": [ { "name": "PHP", "bytes": "272495" } ], "symlink_target": "" }
require "rails_helper" feature "Admin authorization" do scenario "admin accesses dashboard" do stub_admin_usernames(["admin_user", "other_admin_user"]) admin = create(:user, username: "admin_user") sign_in_as(admin, token) visit admin_blacklisted_pull_requests_path click_link "Owners" expect(page).to have_admin_owners_header end scenario "non-admin cannot access dashboard" do non_admin = create(:user, username: "not_admin_user") sign_in_as(non_admin, token) visit admin_owners_path expect(page).not_to have_admin_owners_header end def stub_admin_usernames(usernames) stub_const("Hound::ADMIN_GITHUB_USERNAMES", usernames) end def have_admin_owners_header have_css("h1", text: "Owners") end def token "usergithubtoken" end end
{ "content_hash": "1d6c5367645de8d3e93206c08fb9468d", "timestamp": "", "source": "github", "line_count": 35, "max_line_length": 60, "avg_line_length": 23.17142857142857, "alnum_prop": 0.6954377311960542, "repo_name": "thoughtbot/hound", "id": "6b5d335366b7edda67cc0a028d5a251149dadf45", "size": "811", "binary": false, "copies": "2", "ref": "refs/heads/master", "path": "spec/features/admin_authorization_spec.rb", "mode": "33188", "license": "mit", "language": [ { "name": "CSS", "bytes": "39035" }, { "name": "CoffeeScript", "bytes": "2833" }, { "name": "HTML", "bytes": "37560" }, { "name": "JavaScript", "bytes": "297" }, { "name": "Ruby", "bytes": "407836" }, { "name": "Shell", "bytes": "1136" } ], "symlink_target": "" }
// Licensed to the Apache Software Foundation (ASF) under one // or more contributor license agreements. See the NOTICE file // distributed with this work for additional information // regarding copyright ownership. The ASF licenses this file // to you under the Apache License, Version 2.0 (the // "License"); you may not use this file except in compliance // with the License. You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, // software distributed under the License is distributed on an // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations // under the License. using System; using Org.Apache.REEF.Tang.Annotations; namespace Org.Apache.REEF.Client.YARN { internal class IdentityResourceFileRemoteUrlToClusterUrlConverter : IResourceFileRemoteUrlToClusterUrlConverter { [Inject] private IdentityResourceFileRemoteUrlToClusterUrlConverter() { } public string ConvertToLocalUrl(Uri url) { return url.AbsoluteUri; } } }
{ "content_hash": "51fec204a75f99d97c8b52ab5f156145", "timestamp": "", "source": "github", "line_count": 35, "max_line_length": 115, "avg_line_length": 35.457142857142856, "alnum_prop": 0.7308622078968574, "repo_name": "tcNickolas/incubator-reef", "id": "a1fe2a9058c0898ff407883f75085dbff643d459", "size": "1243", "binary": false, "copies": "25", "ref": "refs/heads/master", "path": "lang/cs/Org.Apache.REEF.Client/YARN/IdentityResourceFileRemoteUrlToClusterUrlConverter.cs", "mode": "33188", "license": "apache-2.0", "language": [ { "name": "Batchfile", "bytes": "2297" }, { "name": "C", "bytes": "1022" }, { "name": "C#", "bytes": "3760659" }, { "name": "C++", "bytes": "183351" }, { "name": "CSS", "bytes": "905" }, { "name": "Java", "bytes": "5588554" }, { "name": "JavaScript", "bytes": "3750" }, { "name": "Objective-C", "bytes": "2755" }, { "name": "PowerShell", "bytes": "8530" }, { "name": "Protocol Buffer", "bytes": "35089" }, { "name": "Python", "bytes": "20640" }, { "name": "Shell", "bytes": "22281" } ], "symlink_target": "" }
<?php /* | ------------------------------------- | @file : Edp.php | @date : 3/26/2015 | @author: | ------------------------------------- */ class Edp extends CI_Controller { public $numberOfStudents; public $yearL = array(0 => 0,1 => 0,2 => 0,3 => 0); function add_room() { $this->api->userMenu(); $this->load->library('form_validation'); $this->load->helper('form'); //rules $this->form_validation->set_rules('room', 'Classroom', 'trim|required|max_length[10]'); $this->form_validation->set_rules('mincapacity', 'Minimum Capacity', 'trim|required|integer'); $this->form_validation->set_rules('maxcapacity', 'Maximun Capacity', 'trim|required|integer'); if ($this->form_validation->run() === FALSE) { $data['error'] = ''; $this->load->view('edp/edit_classroom', $data); } else { $min = $this->input->post('mincapacity'); $max = $this->input->post('maxcapacity'); if ($min > $max OR $min == $max) { $data['error'] = 'error'; $this->load->view('edp/edit_classroom',$data); } else { $dat['legacycode'] = $this->input->post('room'); $dat['mincapacity'] = $this->input->post('mincapacity'); $dat['maxcapacity'] = $this->input->post('maxcapacity'); $dat['location'] = $this->input->post('location'); $dat['status'] = $this->input->post('status'); $this->db->insert('tbl_classroom',$dat); } } $this->load->view('templates/footer', array('orig_page' => '')); } function load_stat() { $systemVal = $this->api->systemValue(); //check if the phase term is FINALS if ($systemVal['phase'] == FIN) { $this->load->model(array( 'edp/edp_classallocation', 'registrar/academicterm' )); $this->load->view('edp/ajax_studentCount'); } else { echo 'Not final'; } } function studentc($isFirstYear = TRUE) { // check if the term is summer if ($term == 3) { // if term is summer . get the students enrolled in last 2nd sem. if($isFirstYear) $acam = $current_academicterm - 2; else $acam = $current_academicterm - 1; $e = $this->edp_classallocation->getStudEnrol($cid, $acam); } else { // if not get the students in enrolled in current academicterm $e = $this->edp_classallocation->getStudEnrol($cid, $current_academicterm); } foreach ($e as $stud) { $yearlevel = $this->api->yearLevel($stud['student'], $course); // API return curriculum not found if the course does not have a curriculum if ($yearlevel != CUR_NOT_FOUND) { if ($isFirstYear) { if ($yearlevel == 1) $this->yearL[0] += 1; } else { if($yearlevel > 1) $this->yearL[$yearlevel - 1] += 1; } } } } function load_stat1() { $this->load->model(array( 'edp/out_studentcount', 'registrar/course', 'registrar/curriculum', 'registrar/academicterm', 'registrar/curriculumdetail', 'edp/edp_classallocation' )); $this->load->view('edp/ajax_stu'); } // function for student statistics function studentcount() { // collect all the post variable $acam = $this->input->post('acam'); $coursemajor = $this->input->post('coursemajor'); $year_level = $this->input->post('year_level'); $count = $this->input->post('count'); $this->load->model('edp/out_studentcount'); //truncate table before inserting $this->db->query("TRUNCATE out_studentcount"); foreach ($coursemajor as $key => $value) { $data = array(); $data['course'] = $value; $data['yearlevel'] = $year_level[$key]; $data['studentcount'] = $count[$key]; $data['academicterm'] = $acam; $this->out_studentcount->insert($data); } $this->out_section(); // update the system value in tbl_systemvalues $this->db->update('tbl_systemvalues', array('classallocationstatus' => 1)); $this->session->set_flashdata('message', '<div class="alert alert-success"> Successfully Created </div>'); redirect(base_url()); } function out_section() { //truncate table before inserting $this->db->query("TRUNCATE out_section"); $systemVal = $this->api->systemValue(); $sy = $systemVal['phaseterm']; $this->numberOfStudents = $systemVal['numberofstudent']; $this->db->where('id', $sy); $tt = $this->db->get('tbl_academicterm')->row_array(); $term = $tt['term']; $acamd = $this->db->query("SELECT * FROM `tbl_academicterm` WHERE systart <= {$tt['systart']} ORDER BY systart DESC,term")->result_array(); $stuC = $this->db->query("SELECT * FROM out_studentcount GROUP BY course")->result_array(); foreach ($stuC as $studentC) : $coursemajor = $studentC['course']; $acam = $studentC['academicterm']; $cur1 = 0; if ($coursemajor != 8 AND $coursemajor != 9 AND $coursemajor != 10 AND $coursemajor != 11) : if ($coursemajor == 2) { $sql = "SELECT id FROM tbl_coursemajor WHERE course = $coursemajor AND major != 0"; } else { $sql = "SELECT id FROM tbl_coursemajor WHERE course = $coursemajor"; } $c = $this->db->query($sql)->result_array(); foreach ($c as $curs) : $course = 0; $cur1 = 0; foreach ($acamd as $acams) { $this->db->where('coursemajor', $curs['id']); $this->db->where('academicterm', $acams['id']); $c1 = $this->db->get('tbl_curriculum'); if ($c1->num_rows() > 0) { $course = $curs['id']; $cc = $c1->row_array(); $cur1 = $cc['id']; break; } } if ($course != 0 AND $cur1 != 0 AND $cur1 != 55) { //echo $course.' '.$cur1.' <br/>'; //get the curriculum within 4 years $cur_range1 = $acam - 12; $cur_range = $this->db->query("SELECT tbl_curriculum.id as id FROM tbl_curriculum,tbl_coursemajor WHERE academicterm BETWEEN $cur_range1 AND $acam AND tbl_curriculum.coursemajor = tbl_coursemajor.id AND course = $coursemajor")->num_rows(); // if there are more than 1 curriculums if ($cur_range > 1) : $c = $this->db->get_where('out_studentcount', array('course' => $coursemajor))->result_array(); foreach ($c as $cc) : $y = $cc['yearlevel']; $cou = $cc['studentcount']; $cur_range2 = $this->db->query("SELECT tbl_curriculum.id as id FROM tbl_curriculum,tbl_coursemajor WHERE academicterm between $cur_range1 and $acam and tbl_curriculum.coursemajor = tbl_coursemajor.id AND course = $coursemajor")->result_array(); foreach ($cur_range2 as $ra) : $e = $this->db->get_where('tbl_curriculumdetail', array('curriculum' => $ra['id'], 'yearlevel' => $y, 'term' => $term))->result_array(); foreach ($e as $ee): $this->insert_section($sy, $coursemajor, $ee['subject'], $y, $cou, $course); endforeach; endforeach; endforeach; elseif ($cur1 != 0) : $c = $this->db->get_where('out_studentcount', array('course' => $coursemajor))->result_array(); foreach ($c as $cc) : $y = $cc['yearlevel']; $cou = $cc['studentcount']; $e = $this->db->get_where('tbl_curriculumdetail', array('curriculum' => $cur1, 'yearlevel' => $y, 'term' => $term))->result_array(); foreach ($e as $ee) : $this->insert_section($sy, $coursemajor, $ee['subject'], $y, $cou, $course); endforeach; endforeach; endif; } endforeach; endif; endforeach; } // function for populate the out_section table private function insert_section($sy, $course, $subject, $yearlevel, $count, $cc) { //@TODO: max capacity for computersubjects is 15 average $d['academicterm'] = $sy; $d['coursemajor'] = $course; $d['subject'] = $subject; $d['yearlevel'] = $yearlevel; $d['studentcount'] = $count; // nstp subject must have 1 section only if ($subject == 298 OR $subject == 299) { $d['section'] = 1; } else { // if the count is less than the numberofstudent system value set it to 0 if ($count == 0 OR $count < $this->numberOfStudents) { // if the student count is less than 10 // default no. of section is 0 if($count <= 10) $d['section'] = 0; else $d['section'] = 1; } else { // force the result to be an integer $d['section'] = (int) ($count / $this->numberOfStudents); } } $this->db->where('coursemajor', $course); $this->db->where('yearlevel', $yearlevel); $this->db->where('subject', $subject); $c = $this->db->count_all_results('out_section'); if ($c < 1) { $this->db->where('coursemajor', $course); $this->db->where('subject', $subject); $coun = $this->db->count_all_results('out_section'); if ($subject == 299 OR $subject == 298) { $where = "(subject = 299 OR subject = 298)"; $this->db->where($where); $cc = $this->db->count_all_results('out_section'); if ($cc < 1) { $this->db->insert('out_section', $d); } } elseif ($coun > 0) { $section = $d['section']; $this->db->query("UPDATE out_section SET section = section + $section WHERE coursemajor = $course AND subject = $subject"); } elseif($coun < 1) { $this->db->insert('out_section', $d); } } } function view_sched($roomId = '') { if ( ! empty($roomId) AND is_numeric($roomId) ) { $this->load->model(array( 'edp/classroom', 'edp/edp_classallocation', 'dean/subject' )); $data['roomId'] = $roomId; $room = $this->classroom->find($roomId); $data['room_name'] = $room['legacycode']; $data['location'] = $room['location']; $this->api->userMenu(); $this->load->view('edp/view_room_sched', $data); $this->load->view('templates/footer'); } else { show_error('Did you type the url by yourself ?'); } } function add_sched($sid = '') { if ( ! empty($sid) ) { $this->api->userMenu(); $data['roomId'] = $sid; $this->load->model(array( 'edp/edp_classallocation' )); $this->load->view('edp/select_subj', $data); $this->load->view('templates/footer'); } else show_error('Did you type the url by yourself ?'); } function assign_room($cid = '') { if ( !empty($cid) ) { $this->api->userMenu(); $this->load->model(array( 'edp/classroom', 'edp/edp_classallocation', 'dean/subject' )); $this->load->helper('form'); $data['cid'] = $cid; $data['error'] = ''; $data['num'] = $this->input->post('days_count') ? $this->input->post('days_count') - 1 : 0; $this->load->view('edp/assign_subj_room', $data); $this->load->view('templates/footer'); } else show_error('Did you type the url by yourself ?'); } function add_room_class() { // puydi ku ini ikadto ha http://lcis.dev.com/assign_room/45009 // para ipa show la it available na room para iton na sched $this->load->model(array( 'edp/edp_classallocation' )); $dayPeriodId = $this->input->post('dayperiodId'); $day = $this->input->post('day'); $from_time = $this->input->post('from_time'); $to_time = $this->input->post('to_time'); $room = $this->input->post('room'); $conflict = FALSE; $cid = $this->input->post('cid'); foreach ($dayPeriodId as $key => $value) { $this->edp_classallocation->updateClassroom($room[$key], $value); /*$f = $this->db->get_where('tbl_period',array('id' => $from_time[$key]))->row_array(); $ff = $f['time']; $t = $this->db->get_where('tbl_period',array('id' => $to_time[$key]))->row_array(); $tt = $t['time']; $r = $this->db->get_where('tbl_dayperiod',array('classroom' => $room[$key]))->result_array(); foreach($r as $rr) { if($rr['day'] == $day[$key]) { $r_f = $this->db->get_where('tbl_period',array('id' => $rr['from_time']))->row_array(); $r_f1 = $r_f['time']; $r_t = $this->db->get_where('tbl_period',array('id' => $rr['to_time']))->row_array(); $r_t1 = $r_t['time']; $rs = $this->api->intersectCheck($ff,$r_f1,$tt,$r_t1); if($rs == TRUE) { $conflict = TRUE; } } }*/ } $d['status'] = 'O'; $this->db->where('id', $cid); $this->db->update('tbl_classallocation', $d); redirect(base_url('menu/edp-room_subj')); /* $this->db->where('id',$cid); $this->db->update('tbl_classallocation',$data);*/ /* $this->session->set_flashdata('message','<div class="alert alert-success">Successfully Assigned</div>'); */ } function sorting() { $this->load->model(array( 'edp/edp_classallocation', 'registrar/academicterm', 'dean/subject' )); $cid = $this->input->post('cid'); if ($cid == 1) { $this->load->view('edp/ajax_edp_all'); } elseif ($cid == 2) { $this->load->view('edp/ajax_edp_assigned'); } elseif ($cid == 3) { $this->load->view('edp/ajax_edp_notassigned'); } else { // this is a error message $this->load->view('edp/ajax_edp_bydean'); } } function preview($roomId) { $this->load->model(array( 'edp/classroom', 'edp/edp_classallocation', 'dean/subject' )); $data['roomId'] = $roomId; $room = $this->classroom->find($roomId); $data['room_name'] = $room['legacycode']; $data['location'] = $room['location']; $this->load->view('edp/preview',$data); } function cl_inc() { $stat['classallocationstatus'] = $this->input->post('name'); $this->db->update('tbl_systemvalues', $stat); $this->api->set_session_message('success', 'Successfully Attested'); redirect(base_url()); } function cre_reg($student, $coursemajor) { $d['student'] = $student; $d['coursemajor'] = $coursemajor; //$d['curriculum'] = $curriculum; $this->db->insert('tbl_registration', $d); $id = $this->db->insert_id(); $f['registration'] = $id; $this->db->where('student', $student); $this->db->where('coursemajor', $coursemajor); $this->db->update('tbl_enrolment', $f); return $id; } }
{ "content_hash": "0a2699a5e20e543455fa9069826035ef", "timestamp": "", "source": "github", "line_count": 483, "max_line_length": 277, "avg_line_length": 36.25258799171843, "alnum_prop": 0.454768703597944, "repo_name": "Jheysoon/lcis", "id": "6bb0cf57099944aada934d48ed954ef8e42a1752", "size": "17510", "binary": false, "copies": "1", "ref": "refs/heads/master", "path": "application/controllers/Edp.php", "mode": "33188", "license": "mit", "language": [ { "name": "ApacheConf", "bytes": "1006" }, { "name": "CSS", "bytes": "50887" }, { "name": "HTML", "bytes": "5633" }, { "name": "JavaScript", "bytes": "390936" }, { "name": "PHP", "bytes": "3146273" } ], "symlink_target": "" }
React Native Webpack Server is a development server that leverages the [Webpack Dev Server](https://github.com/webpack/webpack-dev-server) and the [React Packager](https://github.com/facebook/react-native/tree/master/packager) to enable building React Native JavaScript bundles with webpack. This allows you to use the existing webpack ecosystem when targeting React Native. [![react-native-webpack channel on slack](https://img.shields.io/badge/slack-react--native--webpack%40reactiflux-61DAFB.svg?style=flat-square)](http://www.reactiflux.com) ## Installing ```shell npm install --save-dev react-native-webpack-server ``` ## Using By default React Native will look for an index.ios.js at the root of the project. Delete this file and add an entry in your webpack config: ```js entry: { 'index.ios': ['./src/main.js'] } ``` Start the React Native Webpack Server using the included script. You might want to put this in your `package.json`. ```js "scripts": { "bundle": "react-native-webpack-server bundle", "start": "react-native-webpack-server start" } ``` This will start the server on port 8080. The last step is to change the URL of your application bundle in `AppDelegate.m`, changing 8081 to 8080: ```objc jsCodeLocation = [NSURL URLWithString:@"http://localhost:8080/index.ios.bundle"]; ``` To run the development server: ```shell npm start ``` ### Bundling for distribution Similar to the [standard React Native packager](https://facebook.github.io/react-native/docs/running-on-device-ios.html#using-offline-bundle), you can generate an offline JS bundle to use your app without a development server: ```shell react-native-webpack-server bundle # OR, using the above package.json script: npm run bundle ``` ## Source Maps Current solutions for building React Native bundles with Webpack lose source maps. This is because the Webpack bundle is first built and then passed off to the React Packager which [constructs the source map by hand](https://github.com/facebook/react-native/blob/master/packager/react-packager/src/Packager/Package.js#L149). This is done for speed, but it also means you can only use transforms that map lines 1 to 1. React Native Webpack Server enables source maps by generating the react-native and application bundles separately and then combining their source maps. ## Hot Reload Since this is built on Webpack you can now leverage the growing ecosystem of addons such as React hot module replacement via [react-transform-webpack-hmr](https://github.com/gaearon/react-transform-webpack-hmr). To enable hot reload, make sure you first install [babel-plugin-react-transform](https://github.com/gaearon/babel-plugin-react-transform) and [react-transform-webpack-hmr](https://github.com/gaearon/react-transform-webpack-hmr), then start the server with `--hot`. You'll also need to configure Webpack. See the [Babel+ES6 config](https://github.com/mjohnston/react-native-webpack-server/blob/master/Examples/BabelES6/webpack.config.js) for an example. **NOTE:** hot reload currently only works with the web socket executor (hit CMD+D in the simulator) or the WebView executor (CMD+CTRL+Z -> Enable Safari Debugging). If you regurlarly use this feature, you might want to default to the web socket exeuctor in development: RCTBridge.m: ```objc - (void)setUp { Class executorClass = _executorClass ?: _globalExecutorClass ?: [RCTContextExecutor class]; #if DEBUG executorClass = NSClassFromString(@"RCTWebSocketExecutor"); #endif ... } ``` Replace `RCTWebSocketExecutor` with `RCTWebViewExecutor` if you wish to use the Safari WebKit inspector instead of the Chrome dev tools. ## Packaging for release When you are ready to ship your app, you will want to generate a minified bundle and package it in the binary. You can build a minified bundle using the `dev` and `minify` URL parameters. Setting these to `false` or `0` will tell the React Native packager to minify and remove debug code. In your webpack config, you will likely want to enable the `UglifyJsPlugin`. The sample apps are configured to enable minification when `process.env.NODE_ENV` is set to `production`. See the [BabelES6 webpack config](https://github.com/mjohnston/react-native-webpack-server/blob/master/Examples/BabelES6/webpack.config.js#L41) for an example. To generate and copy the minified bundle into the iOS project: ```shell curl 'http://localhost:8080/index.ios.bundle?dev=false&minify=true' -o iOS/main.jsbundle ``` You will need to uncomment [this line](https://github.com/mjohnston/react-native-webpack-server/blob/master/Examples/BabelES6/iOS/AppDelegate.m#L37) in `AppDelegate.m` in order to load the local bundle. ## FAQ **I can't import 3rd party modules in my project.** Most react-native 3rd party modules are published to npm in ES6+ since the react-native packager handles transpiling. You may need to whitelist these modules in your webpack config, as the default configuration in the example excludes all of node_modules. See [issue #34](https://github.com/mjohnston/react-native-webpack-server/issues/34). **I get the red box of death when using hot reload even after fixing the exception.** Your code is still executing. Dismiss the red box using the `Esc` key. **Why is hot reload using a no-op setInterval() in my app?** It's a terrible hack to jump back onto the React Native runloop when a module is changed. If you have a better idea, please open a PR :) **Source map generation is really slow on io.js.** On a late-2012 Macbook Pro, it takes about 1.5 seconds to generate the source map for react-native on io.js. On stable node (0.12.x) it takes around 200ms. I originally thought this was an issue with [source-map](https://github.com/mozilla/source-map) but in an isolated test with the entirety of react-native I found io.js and node.js (stable) to be about the same. If you have any ideas, please let me know. In the meantime, it's best to use the latest stable version of node.js.
{ "content_hash": "09e5c663224c514d3f2d534662da8364", "timestamp": "", "source": "github", "line_count": 113, "max_line_length": 481, "avg_line_length": 52.84070796460177, "alnum_prop": 0.769887790989784, "repo_name": "pascience/react-native-webpack-server", "id": "e22f69afa60e39ecc03a994b13834e1bea6e3285", "size": "5999", "binary": false, "copies": "1", "ref": "refs/heads/master", "path": "README.md", "mode": "33188", "license": "mit", "language": [ { "name": "JavaScript", "bytes": "15095" } ], "symlink_target": "" }
<?php namespace Application\Controller; use Application\Service\LanguageService; use Zend\Mvc\Controller\AbstractActionController; use Zend\View\Model\ViewModel; class IndexController extends AbstractActionController { /** * @var LanguageService */ private $languageService; public function setLanguageService(LanguageService $languageService) { $this->languageService = $languageService; } public function indexAction() { if (!$this->zfcUserAuthentication()->hasIdentity()) { $this->redirect()->toRoute('zfcuser/login'); } $auth = $this->getServiceLocator()->get('zfcuser_auth_service'); $user = $auth->getIdentity(); $toDate = new \DateTime(); $fromDate = new \DateTime(); $fromDate = $fromDate->sub(date_interval_create_from_date_string('1 month')); $view = new ViewModel(); $view->toDate = $toDate; $view->fromDate = $fromDate; $view->user = $user; return $view; } public function languageAction() { $identificator = $this->params('language'); $language = $this->languageService->getLanguageByIdentificator($identificator); $this->languageService->setCurrentLanguage($language); // Redirect back to the referer url $url = $this->request->getHeader('Referer')->getUri(); return $this->redirect()->toUrl($url); } }
{ "content_hash": "6c3f6383fc61f0722eac7418feec35b9", "timestamp": "", "source": "github", "line_count": 51, "max_line_length": 87, "avg_line_length": 28.215686274509803, "alnum_prop": 0.6323835997220292, "repo_name": "kristjanAnd/SimpleIV", "id": "bdbd55ae653a110711c227eb39b431427fe63377", "size": "1761", "binary": false, "copies": "1", "ref": "refs/heads/master", "path": "module/Application/src/Application/Controller/IndexController.php", "mode": "33188", "license": "bsd-3-clause", "language": [ { "name": "CSS", "bytes": "1421" }, { "name": "JavaScript", "bytes": "58984" }, { "name": "PHP", "bytes": "421292" } ], "symlink_target": "" }
import warnings from collections.abc import Callable from django.conf import settings from django.utils.module_loading import import_string def su_login_callback(user): if hasattr(settings, "SU_LOGIN"): warnings.warn( "SU_LOGIN is deprecated, use SU_LOGIN_CALLBACK", DeprecationWarning, ) func = getattr(settings, "SU_LOGIN_CALLBACK", None) if func is not None: if not isinstance(func, Callable): func = import_string(func) return func(user) return user.has_perm("auth.change_user") def custom_login_action(request, user): func = getattr(settings, "SU_CUSTOM_LOGIN_ACTION", None) if func is None: return False if not isinstance(func, Callable): func = import_string(func) func(request, user) return True
{ "content_hash": "b61d3630f1c38f69dc0be21cacb85272", "timestamp": "", "source": "github", "line_count": 32, "max_line_length": 60, "avg_line_length": 26, "alnum_prop": 0.65625, "repo_name": "PetrDlouhy/django-su", "id": "160993be44b5a7c68b7e0de6539b73ec5bec65ff", "size": "857", "binary": false, "copies": "2", "ref": "refs/heads/develop", "path": "django_su/utils.py", "mode": "33188", "license": "mit", "language": [ { "name": "HTML", "bytes": "2997" }, { "name": "Python", "bytes": "29575" } ], "symlink_target": "" }
var Slave = mkClass({ initialize: function (thunk) { this.thunk = thunk }, die: function () {this.dead = true;}, nMoreTimes: function (times) { this.times = this.times || 0; this.times += times; var oldThunk = this.thunk; this.thunk = function (data) { oldThunk.call(this, data); if (--this.times == 0) this.die(); } return this; } }); var CallbackSlot = mkClass({ initialize: function () { this.slaves = []; }, subscribeWithSlave: function (thunkOrSlave) { var slave; if (thunkOrSlave instanceof Slave) slave = thunkOrSlave; else slave = new Slave(thunkOrSlave); this.slaves.push(slave); return slave; }, subscribeOnce: function (thunk) { return this.subscribeWithSlave(thunk).nMoreTimes(1); }, broadcast: function (data) { var oldSlaves = this.slaves; var newSlaves = this.slaves = []; _.each(oldSlaves, function (slave) { try { slave.thunk(data); } catch (e) { console.log("got exception in CallbackSlot#broadcast", e, "for slave thunk", slave.thunk); _.defer(function () {throw e;}); } if (!slave.dead) newSlaves.push(slave); }); }, unsubscribe: function (slave) { slave.die(); var index = $.inArray(slave, this.slaves); if (index >= 0) this.slaves.splice(index, 1); } });
{ "content_hash": "18cdff004ef9620871ee286e16f15d4a", "timestamp": "", "source": "github", "line_count": 55, "max_line_length": 98, "avg_line_length": 25.2, "alnum_prop": 0.588023088023088, "repo_name": "ingenthr/ns_server", "id": "08d9d7a746abc680a76b0af08058147c8148e422", "size": "1386", "binary": false, "copies": "1", "ref": "refs/heads/master", "path": "deps/menelaus/priv/js/callbacks.js", "mode": "33188", "license": "apache-2.0", "language": [ { "name": "Erlang", "bytes": "974742" }, { "name": "JavaScript", "bytes": "692656" }, { "name": "Python", "bytes": "177" }, { "name": "Ruby", "bytes": "25661" }, { "name": "Shell", "bytes": "2826" } ], "symlink_target": "" }
<?php namespace Matrix\ServiceBundle\Entity; use Doctrine\ORM\Mapping as ORM; /** * ProductPrices * * @ORM\Table(name="product_prices", indexes={@ORM\Index(name="Ref_12", columns={"product"}), @ORM\Index(name="Ref_13", columns={"currency"})}) * @ORM\Entity(repositoryClass="Matrix\ServiceBundle\Repository\ProductPricesRepository") */ class ProductPrices { /** * @var integer * * @ORM\Column(name="id", type="integer", nullable=false) * @ORM\Id * @ORM\GeneratedValue(strategy="IDENTITY") */ private $id; /** * @var float * * @ORM\Column(name="price", type="float", precision=9, scale=2, nullable=false) */ private $price; /** * @var integer * * @ORM\Column(name="version", type="integer", nullable=false) */ private $version = '1'; /** * @var Products * * @ORM\ManyToOne(targetEntity="Products") * @ORM\JoinColumns({ * @ORM\JoinColumn(name="product", referencedColumnName="id") * }) */ private $product; /** * @var Currency * * @ORM\ManyToOne(targetEntity="Currency") * @ORM\JoinColumns({ * @ORM\JoinColumn(name="currency", referencedColumnName="id") * }) */ private $currency; public function toArray(){ return array( "id" => $this->getId(), "product" => $this->getProduct()->getId(), "price" => $this->getPrice(), "currency" => $this->getCurrency()->getId(), "version" => $this->getVersion(), "status" => 1 ); } /** * Get id * * @return integer */ public function getId() { return $this->id; } /** * Set price * * @param float $price * @return ProductPrices */ public function setPrice($price) { $this->price = $price; return $this; } /** * Get price * * @return float */ public function getPrice() { return $this->price; } /** * Set version * * @param integer $version * @return ProductPrices */ public function setVersion($version) { $this->version = $version; return $this; } /** * Get version * * @return integer */ public function getVersion() { return $this->version; } /** * Set product * * @param Products $product * @return ProductPrices */ public function setProduct(Products $product = null) { $this->product = $product; return $this; } /** * Get product * * @return Products */ public function getProduct() { return $this->product; } /** * Set currency * * @param Currency $currency * @return ProductPrices */ public function setCurrency(Currency $currency = null) { $this->currency = $currency; return $this; } /** * Get currency * * @return Currency */ public function getCurrency() { return $this->currency; } }
{ "content_hash": "6693d0068372f3ef7661a50a7b208b34", "timestamp": "", "source": "github", "line_count": 171, "max_line_length": 143, "avg_line_length": 18.637426900584796, "alnum_prop": 0.5120803263256981, "repo_name": "Serge009/service", "id": "3043972d522a4841b24631ac6a7d6d53ec18ac62", "size": "3187", "binary": false, "copies": "1", "ref": "refs/heads/master", "path": "src/Matrix/ServiceBundle/Entity/ProductPrices.php", "mode": "33188", "license": "mit", "language": [ { "name": "CSS", "bytes": "713468" }, { "name": "JavaScript", "bytes": "196214" }, { "name": "PHP", "bytes": "506922" } ], "symlink_target": "" }
@implementation UpdateMessageDescription @synthesize title, body; + (id)description { return [[[[self class] alloc] init] autorelease]; } - (void)dealloc { self.title = nil; self.body = nil; [super dealloc]; } - (id)init { return (self = [super init]); } - (id)copyWithZone:(NSZone *)zone { UpdateMessageDescription * desc = [[[self class] allocWithZone:zone] init]; desc.title = self.title; desc.body = self.body; return desc; } - (NSString *)description { return [NSString stringWithFormat:@"title: '%@', body: '%@'", title, body]; } - (NSString *)xmlDescription { NSMutableString * xml = [NSMutableString string]; [xml appendString:@"<message>\n"]; if (self.title) [xml appendFormat:@"\t<title>%@</title>", self.title]; if (self.body) [xml appendFormat:@"\t<body>%@</body>\n", self.body]; [xml appendString:@"</message>"]; return xml; } @end
{ "content_hash": "8bd6978a67e1101ab369a7a8002545d8", "timestamp": "", "source": "github", "line_count": 52, "max_line_length": 79, "avg_line_length": 18.03846153846154, "alnum_prop": 0.6140724946695096, "repo_name": "highorderbit/bug-watch", "id": "1468b581cfcce9f2619e8c8daf0ee039aaf75324", "size": "1045", "binary": false, "copies": "1", "ref": "refs/heads/master", "path": "src/Classes/lighthouse/api/descriptions/UpdateMessageDescription.m", "mode": "33188", "license": "mit", "language": [ { "name": "Objective-C", "bytes": "516570" } ], "symlink_target": "" }
<Record> <Term>Nifurmerone</Term> <SemanticType>Pharmacologic Substance</SemanticType> <ParentTerm>Antifungal Agent</ParentTerm> <ClassificationPath>Chemicals_and_Drugs_Kind/Drug, Food, Chemical or Biomedical Material/Pharmacologic Substance/Anti-Infective Agent/Antifungal Agent/Nifurmerone</ClassificationPath> <BroaderTerm>Nifurmerone</BroaderTerm> <BroaderTerm>Chemicals_and_Drugs_Kind</BroaderTerm> <BroaderTerm>Antifungal Agent</BroaderTerm> <BroaderTerm>Pharmacologic Substance</BroaderTerm> <BroaderTerm>Anti-Infective Agent</BroaderTerm> <BroaderTerm>Drug, Food, Chemical or Biomedical Material</BroaderTerm> <Synonym>NIFURMERONE</Synonym> <Synonym>Nifurmerone</Synonym> <Source>NCI Thesaurus</Source> </Record>
{ "content_hash": "c913aba54fab7cb08bf83497bcac251e", "timestamp": "", "source": "github", "line_count": 15, "max_line_length": 183, "avg_line_length": 49.06666666666667, "alnum_prop": 0.8152173913043478, "repo_name": "detnavillus/modular-informatic-designs", "id": "09b60f0d53fc13069420cecbbadd55d1b09144b8", "size": "736", "binary": false, "copies": "1", "ref": "refs/heads/master", "path": "pipeline/src/test/resources/thesaurus/pharmacologicsubstance/nifurmerone.xml", "mode": "33261", "license": "apache-2.0", "language": [ { "name": "Java", "bytes": "2069134" } ], "symlink_target": "" }
\hypertarget{InventoryCommand_8java}{\section{Inventory\-Command.\-java} \label{InventoryCommand_8java}\index{pkg\-\_\-commands/\-Inventory\-Command.\-java@{pkg\-\_\-commands/\-Inventory\-Command.\-java}} } \begin{DoxyCode} 00001 \textcolor{keyword}{package }pkg\_commands; 00002 00003 \textcolor{keyword}{import} \hyperlink{classpkg__world_1_1Player}{pkg\_world.Player}; 00004 \hypertarget{InventoryCommand_8java_source_l00009}{}\hyperlink{classpkg__commands_1_1InventoryCommand}{00009} \textcolor{keyword}{public} \textcolor{keyword}{class }\hyperlink{classpkg__commands_1_1InventoryCommand}{InventoryCommand} \textcolor{keyword}{extends} \hyperlink{classpkg__commands_1_1Command}{Command} \{ 00010 \hypertarget{InventoryCommand_8java_source_l00014}{}\hyperlink{classpkg__commands_1_1InventoryCommand_a4ca959fe6979e5ca2a79a0596803533d}{00014} \textcolor{keyword}{public} \hyperlink{classpkg__commands_1_1InventoryCommand_a4ca959fe6979e5ca2a79a0596803533d}{InventoryCommand}()\{ 00015 00016 \} 00017 \hypertarget{InventoryCommand_8java_source_l00023}{}\hyperlink{classpkg__commands_1_1InventoryCommand_a16ce9e3db461ecb7c4a50d2bdef65022}{00023} \textcolor{keyword}{public} \textcolor{keywordtype}{boolean} \hyperlink{classpkg__commands_1_1InventoryCommand_a16ce9e3db461ecb7c4a50d2bdef65022}{execute}(\hyperlink{classpkg__world_1_1Player}{Player} player) \{ 00024 \hyperlink{classpkg__commands_1_1Command_ae210ff216fe908b111ba1c988a963d13}{setMessage}(player.\hyperlink{classpkg__world_1_1Player_a2a6e491f41e159bbac42022e55df2d52}{getInventory}()); 00025 \textcolor{keywordflow}{return} \textcolor{keyword}{false}; 00026 \} 00027 00028 \} \end{DoxyCode}
{ "content_hash": "eaac911e557f350fef0f5a5f15e2c3b7", "timestamp": "", "source": "github", "line_count": 22, "max_line_length": 359, "avg_line_length": 76.9090909090909, "alnum_prop": 0.793144208037825, "repo_name": "minijackson/Bad-Philophobia", "id": "0b5be21d09a44aceb8d47496ebf6b4cb7568e377", "size": "1692", "binary": false, "copies": "2", "ref": "refs/heads/master", "path": "progdoc/latex/InventoryCommand_8java_source.tex", "mode": "33188", "license": "mit", "language": [ { "name": "CSS", "bytes": "59118" }, { "name": "Java", "bytes": "69405" }, { "name": "JavaScript", "bytes": "142904" }, { "name": "TeX", "bytes": "1185922" } ], "symlink_target": "" }
<?xml version="1.0" encoding="utf-8"?> <inset xmlns:android="http://schemas.android.com/apk/res/android" android:drawable="@drawable/window_popup_background_inner" android:insetTop="@dimen/window_popup_corner_radius" android:insetRight="@dimen/window_popup_corner_radius" android:insetBottom="@dimen/window_popup_corner_radius" android:insetLeft="@dimen/window_popup_corner_radius"/>
{ "content_hash": "4a8b9163782620497cb4f16c0ebebf73", "timestamp": "", "source": "github", "line_count": 8, "max_line_length": 66, "avg_line_length": 54, "alnum_prop": 0.6990740740740741, "repo_name": "AnySoftKeyboard/AnySoftKeyboard", "id": "02d648e5319defde236a0d82e7085c1f72ac3f50", "size": "432", "binary": false, "copies": "1", "ref": "refs/heads/main", "path": "ime/app/src/main/res/drawable/window_popup_background.xml", "mode": "33188", "license": "apache-2.0", "language": [ { "name": "Batchfile", "bytes": "2631" }, { "name": "C", "bytes": "36897" }, { "name": "C++", "bytes": "196172" }, { "name": "Dockerfile", "bytes": "30" }, { "name": "Groovy", "bytes": "1692" }, { "name": "HTML", "bytes": "528564" }, { "name": "Java", "bytes": "3559273" }, { "name": "Kotlin", "bytes": "29619" }, { "name": "Makefile", "bytes": "723" }, { "name": "Python", "bytes": "2623" }, { "name": "Shell", "bytes": "30772" } ], "symlink_target": "" }
module Errors class UserNotAuthorizedError < AuthenticationError; end end
{ "content_hash": "b9cc83bfae901be75c3c2a95a492be5d", "timestamp": "", "source": "github", "line_count": 3, "max_line_length": 57, "avg_line_length": 25.333333333333332, "alnum_prop": 0.8421052631578947, "repo_name": "the-oneacct-export-project/oneacct-export", "id": "7bf29a78a8aa03bf4fc27bb837bf49fe8c6a3f7c", "size": "76", "binary": false, "copies": "2", "ref": "refs/heads/master", "path": "lib/errors/user_not_authorized_error.rb", "mode": "33188", "license": "mit", "language": [ { "name": "HTML", "bytes": "4636" }, { "name": "Ruby", "bytes": "161047" }, { "name": "Shell", "bytes": "817" } ], "symlink_target": "" }
package org.dcm4chex.archive.hl7; import org.dom4j.Document; import org.xml.sax.ContentHandler; /** * @author [email protected] * @version $Revision: 14795 $ $Date: 2011-01-31 23:15:13 +0800 (周一, 31 1月 2011) $ * @since 27.10.2004 * */ public interface HL7Service { boolean process(MSH msh, Document msg, ContentHandler hl7out, String[] xslSubDirs) throws HL7Exception; }
{ "content_hash": "38eb6e1c06fa3cbabb3726c1674b960f", "timestamp": "", "source": "github", "line_count": 19, "max_line_length": 107, "avg_line_length": 20.842105263157894, "alnum_prop": 0.7146464646464646, "repo_name": "medicayun/medicayundicom", "id": "5d971a46f98f5774898e1d0b73db2ba3ec340869", "size": "2278", "binary": false, "copies": "16", "ref": "refs/heads/master", "path": "dcm4jboss-all/branches/DCM4CHEE_2_17_1_PATCH/dcm4jboss-hl7/src/java/org/dcm4chex/archive/hl7/HL7Service.java", "mode": "33188", "license": "apache-2.0", "language": [], "symlink_target": "" }
package org.apache.harmony.test.stress.jni.strings; import org.apache.harmony.test.stress.jni.share.STTest; import org.apache.harmony.test.stress.jni.share.JNITestError; import org.apache.harmony.test.share.stress.ReliabilityRunner; /** * @author Vladimir Nenashev * @version $Revision: 1.7 $ */ public class StringsTest5 extends STTest { private static native void init(); private native int nativeMethod(int len, int maxCnt); public void doTest() { try { int length = Integer.getInteger( "org.apache.harmony.test.stress.jni." + "strings.StringsTest1.length", 10000).intValue(); int maxStrCount = Integer.getInteger( "org.apache.harmony.test.stress.jni." + "strings.StringsTest1.maxStrCount", 10000) .intValue(); int res = nativeMethod(length, maxStrCount); if (res == 0) { testLog("Working thread", "StringsTest5 FAILED: native method returned 0"); ReliabilityRunner.debug("Test failed"); ReliabilityRunner.mainTest.addError(this, new JNITestError()); } } catch (Throwable t) { testLog("Working thread", "StringsTest5: ERROR: Exception caught:"); testLog("Working thread", t); ReliabilityRunner.debug("Test error"); ReliabilityRunner.mainTest.addError(this, new JNITestError()); } testLog("Working thread", "StringsTest5 PASSED"); } static { init(); } }
{ "content_hash": "2c158f046007a0885ba456a62ace0732", "timestamp": "", "source": "github", "line_count": 50, "max_line_length": 80, "avg_line_length": 32.68, "alnum_prop": 0.5862913096695227, "repo_name": "freeVM/freeVM", "id": "59bf6c6231fc0667246477a41a73be25078e762b", "size": "2441", "binary": false, "copies": "1", "ref": "refs/heads/master", "path": "enhanced/buildtest/tests/stress/qa/src/test/stress/org/apache/harmony/test/stress/jni/strings/StringsTest5.java", "mode": "33188", "license": "apache-2.0", "language": [ { "name": "Assembly", "bytes": "116828" }, { "name": "C", "bytes": "17860389" }, { "name": "C++", "bytes": "19007206" }, { "name": "CSS", "bytes": "217777" }, { "name": "Java", "bytes": "152108632" }, { "name": "Objective-C", "bytes": "106412" }, { "name": "Objective-J", "bytes": "11029421" }, { "name": "Perl", "bytes": "305690" }, { "name": "Scilab", "bytes": "34" }, { "name": "Shell", "bytes": "153821" }, { "name": "XSLT", "bytes": "152859" } ], "symlink_target": "" }
package org.gwtproject.aria.client; ///////////////////////////////////////////////////////// // This is auto-generated code. Do not manually edit! // ///////////////////////////////////////////////////////// import org.gwtproject.dom.client.Element; /** * A type that represents the <a href="http://www.w3.org/TR/wai-aria/roles#group">group</a> role in * the ARIA specification. * * @see Role * @see Roles */ public interface GroupRole extends SectionRole { /** * Returns the value of the <a * href="http://www.w3.org/TR/wai-aria/states_and_properties#aria-activedescendant"> * aria-activedescendant</a> attribute for the {@code element} or "" if no such attribute is * present. */ String getAriaActivedescendantProperty(Element element); /** * Removes the <a * href="http://www.w3.org/TR/wai-aria/states_and_properties#aria-activedescendant"> * aria-activedescendant</a> attribute from the {@code element}. */ void removeAriaActivedescendantProperty(Element element); /** * Sets the <a href="http://www.w3.org/TR/wai-aria/states_and_properties#aria-activedescendant"> * aria-activedescendant</a> attribute for the {@code element} to the given {@code value}. */ void setAriaActivedescendantProperty(Element element, Id value); }
{ "content_hash": "7c630201deea3d5baf10b36638856a68", "timestamp": "", "source": "github", "line_count": 38, "max_line_length": 99, "avg_line_length": 33.973684210526315, "alnum_prop": 0.6444616576297444, "repo_name": "gwtproject/gwt-aria", "id": "f1c52260c521c12863ef55d3043046768f587761", "size": "1900", "binary": false, "copies": "1", "ref": "refs/heads/master", "path": "gwt-aria/src/main/java/org/gwtproject/aria/client/GroupRole.java", "mode": "33188", "license": "apache-2.0", "language": [ { "name": "Java", "bytes": "321177" } ], "symlink_target": "" }
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <!--NewPage--> <HTML> <HEAD> <!-- Generated by javadoc (build 1.6.0-beta2) on Mon Mar 19 19:32:17 CST 2007 --> <META http-equiv="Content-Type" content="text/html; charset=utf-8"> <TITLE> 类 org.omg.CORBA.PolicyListHelper 的使用 (Java Platform SE 6) </TITLE><script>var _hmt = _hmt || [];(function() {var hm = document.createElement("script");hm.src = "//hm.baidu.com/hm.js?dd1361ca20a10cc161e72d4bc4fef6df";var s = document.getElementsByTagName("script")[0];s.parentNode.insertBefore(hm, s);})();</script> <META NAME="date" CONTENT="2007-03-19"> <LINK REL ="stylesheet" TYPE="text/css" HREF="../../../../stylesheet.css" TITLE="Style"> <SCRIPT type="text/javascript"> function windowTitle() { if (location.href.indexOf('is-external=true') == -1) { parent.document.title="类 org.omg.CORBA.PolicyListHelper 的使用 (Java Platform SE 6)"; } } </SCRIPT> <NOSCRIPT> </NOSCRIPT> </HEAD> <BODY BGCOLOR="white" onload="windowTitle();"> <HR> <!-- ========= START OF TOP NAVBAR ======= --> <A NAME="navbar_top"><!-- --></A> <A HREF="#skip-navbar_top" title="跳过导航链接"></A> <TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0" SUMMARY=""> <TR> <TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A NAME="navbar_top_firstrow"><!-- --></A> <TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3" SUMMARY=""> <TR ALIGN="center" VALIGN="top"> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>概述</B></FONT></A>&nbsp;</TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../package-summary.html"><FONT CLASS="NavBarFont1"><B>软件包</B></FONT></A>&nbsp;</TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../org/omg/CORBA/PolicyListHelper.html" title="org.omg.CORBA 中的类"><FONT CLASS="NavBarFont1"><B>类</B></FONT></A>&nbsp;</TD> <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> &nbsp;<FONT CLASS="NavBarFont1Rev"><B>使用</B></FONT>&nbsp;</TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../package-tree.html"><FONT CLASS="NavBarFont1"><B>树</B></FONT></A>&nbsp;</TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>已过时</B></FONT></A>&nbsp;</TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../index-files/index-1.html"><FONT CLASS="NavBarFont1"><B>索引</B></FONT></A>&nbsp;</TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../help-doc.html"><FONT CLASS="NavBarFont1"><B>帮助</B></FONT></A>&nbsp;</TD> </TR> </TABLE> </TD> <TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM> <b>Java<sup><font size=-2>TM</font></sup>&nbsp;Platform<br>Standard&nbsp;Ed. 6</b></EM> </TD> </TR> <TR> <TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2"> &nbsp;上一个&nbsp; &nbsp;下一个</FONT></TD> <TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2"> <A HREF="../../../../index.html?org/omg/CORBA//class-usePolicyListHelper.html" target="_top"><B>框架</B></A> &nbsp; &nbsp;<A HREF="PolicyListHelper.html" target="_top"><B>无框架</B></A> &nbsp; &nbsp;<SCRIPT type="text/javascript"> <!-- if(window==top) { document.writeln('<A HREF="../../../../allclasses-noframe.html"><B>所有类</B></A>'); } //--> </SCRIPT> <NOSCRIPT> <A HREF="../../../../allclasses-noframe.html"><B>所有类</B></A> </NOSCRIPT> </FONT></TD> </TR> </TABLE> <A NAME="skip-navbar_top"></A> <!-- ========= END OF TOP NAVBAR ========= --> <HR> <CENTER> <H2> <B>类 org.omg.CORBA.PolicyListHelper<br>的使用</B></H2> </CENTER> 没有 org.omg.CORBA.PolicyListHelper 的用法 <P> <HR> <!-- ======= START OF BOTTOM NAVBAR ====== --> <A NAME="navbar_bottom"><!-- --></A> <A HREF="#skip-navbar_bottom" title="跳过导航链接"></A> <TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0" SUMMARY=""> <TR> <TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A NAME="navbar_bottom_firstrow"><!-- --></A> <TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3" SUMMARY=""> <TR ALIGN="center" VALIGN="top"> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>概述</B></FONT></A>&nbsp;</TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../package-summary.html"><FONT CLASS="NavBarFont1"><B>软件包</B></FONT></A>&nbsp;</TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../org/omg/CORBA/PolicyListHelper.html" title="org.omg.CORBA 中的类"><FONT CLASS="NavBarFont1"><B>类</B></FONT></A>&nbsp;</TD> <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> &nbsp;<FONT CLASS="NavBarFont1Rev"><B>使用</B></FONT>&nbsp;</TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../package-tree.html"><FONT CLASS="NavBarFont1"><B>树</B></FONT></A>&nbsp;</TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>已过时</B></FONT></A>&nbsp;</TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../index-files/index-1.html"><FONT CLASS="NavBarFont1"><B>索引</B></FONT></A>&nbsp;</TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../help-doc.html"><FONT CLASS="NavBarFont1"><B>帮助</B></FONT></A>&nbsp;</TD> </TR> </TABLE> </TD> <TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM> <b>Java<sup><font size=-2>TM</font></sup>&nbsp;Platform<br>Standard&nbsp;Ed. 6</b></EM> </TD> </TR> <TR> <TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2"> &nbsp;上一个&nbsp; &nbsp;下一个</FONT></TD> <TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2"> <A HREF="../../../../index.html?org/omg/CORBA//class-usePolicyListHelper.html" target="_top"><B>框架</B></A> &nbsp; &nbsp;<A HREF="PolicyListHelper.html" target="_top"><B>无框架</B></A> &nbsp; &nbsp;<SCRIPT type="text/javascript"> <!-- if(window==top) { document.writeln('<A HREF="../../../../allclasses-noframe.html"><B>所有类</B></A>'); } //--> </SCRIPT> <NOSCRIPT> <A HREF="../../../../allclasses-noframe.html"><B>所有类</B></A> </NOSCRIPT> </FONT></TD> </TR> </TABLE> <A NAME="skip-navbar_bottom"></A> <!-- ======== END OF BOTTOM NAVBAR ======= --> <HR> <font size="-1"><a href="http://bugs.sun.com/services/bugreport/index.jsp">提交错误或意见</a><br>有关更多的 API 参考资料和开发人员文档,请参阅 <a href="http://java.sun.com/javase/6/webnotes/devdocs-vs-specs.html">Java SE 开发人员文档</a>。该文档包含更详细的、面向开发人员的描述,以及总体概述、术语定义、使用技巧和工作代码示例。 <p>版权所有 2007 Sun Microsystems, Inc. 保留所有权利。 请遵守<a href="http://java.sun.com/javase/6/docs/legal/license.html">许可证条款</a>。另请参阅<a href="http://java.sun.com/docs/redist.html">文档重新分发政策</a>。</font> </BODY> </HTML>
{ "content_hash": "c1b42cf95e9c9b7218587e7c413f1cf8", "timestamp": "", "source": "github", "line_count": 145, "max_line_length": 441, "avg_line_length": 45.33793103448276, "alnum_prop": 0.6241253422573776, "repo_name": "piterlin/piterlin.github.io", "id": "aef5ea52ac1d1075171eb02c68004cd7554f009f", "size": "6998", "binary": false, "copies": "1", "ref": "refs/heads/master", "path": "doc/jdk6_cn/org/omg/CORBA/class-use/PolicyListHelper.html", "mode": "33188", "license": "mit", "language": [ { "name": "CSS", "bytes": "479" }, { "name": "HTML", "bytes": "9480869" }, { "name": "JavaScript", "bytes": "246" } ], "symlink_target": "" }
<html> <body> {% if filename %} <audio controls src="{{url_for('static', filename=filename)}}" type="wav"> </audio> {% else %} No audio available for record. {% endif %} </body> </html>
{ "content_hash": "2a95ed4aab0c261aa8401f4cf74c802f", "timestamp": "", "source": "github", "line_count": 10, "max_line_length": 74, "avg_line_length": 18.6, "alnum_prop": 0.6236559139784946, "repo_name": "guyrt/court-reminder", "id": "9bd3f64b0439e1dfb985391ceeca8b857f58b806", "size": "186", "binary": false, "copies": "2", "ref": "refs/heads/master", "path": "server/templates/audio.html", "mode": "33188", "license": "mit", "language": [ { "name": "HTML", "bytes": "186" }, { "name": "Python", "bytes": "66801" } ], "symlink_target": "" }
<?php namespace app\assets; use yii\web\AssetBundle; /** * @author Qiang Xue <[email protected]> * @since 2.0 */ class AppAsset extends AssetBundle { public $basePath = '@webroot'; public $baseUrl = '@web'; public $css = [ 'plugins/font-awesome/css/font-awesome.min.css', 'plugins/simple-line-icons/simple-line-icons.min.css', 'plugins/bootstrap/css/bootstrap.min.css', 'plugins/bootstrap-switch/css/bootstrap-switch.min.css', 'plugins/bootstrap-daterangepicker/daterangepicker.min.css', 'css/components.min.css', 'css/plugins.min.css', 'layouts/layout/css/layout.min.css', 'layouts/layout/css/themes/darkblue.min.css', 'layouts/layout/css/custom.min.css' ]; public $js = [ 'plugins/jquery.js', 'plugins/jquery.min.js', 'plugins/bootstrap/js/bootstrap.min.js', 'plugins/js.cookie.min.js', 'plugins/jquery-slimscroll/jquery.slimscroll.min.js', 'plugins/jquery.blockui.min.js', 'plugins/bootstrap-switch/js/bootstrap-switch.min.js', 'plugins/moment.min.js', 'scripts/app.min.js', 'scripts/dashboard.min.js', 'layouts/layout/scripts/layout.min.js', 'layouts/layout/scripts/demo.min.js', 'layouts/global/scripts/quick-sidebar.min.js', ]; public $jsOptions = array( 'position' => \yii\web\View::POS_HEAD ); }
{ "content_hash": "01ed9edea331ccb7922f1c8798d31168", "timestamp": "", "source": "github", "line_count": 65, "max_line_length": 68, "avg_line_length": 24.06153846153846, "alnum_prop": 0.5735294117647058, "repo_name": "rpeerbits/demo-yii", "id": "cc5ef22ad24b72306472627e36fddd7fc6fa1064", "size": "1708", "binary": false, "copies": "1", "ref": "refs/heads/master", "path": "assets/AppAsset.php", "mode": "33188", "license": "bsd-3-clause", "language": [ { "name": "ApacheConf", "bytes": "420" }, { "name": "Batchfile", "bytes": "1030" }, { "name": "CSS", "bytes": "8380521" }, { "name": "CoffeeScript", "bytes": "164184" }, { "name": "HTML", "bytes": "1538499" }, { "name": "JavaScript", "bytes": "18031792" }, { "name": "Makefile", "bytes": "163" }, { "name": "PHP", "bytes": "93588" }, { "name": "Shell", "bytes": "444" } ], "symlink_target": "" }
/* Ractive.js v1.3.0 Build: 57f1a675a961008dbe2e58f6bb058a9413eb2959 Date: Mon Feb 04 2019 20:06:47 GMT+0000 (UTC) Website: https://ractive.js.org License: MIT */ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : typeof define === 'function' && define.amd ? define(factory) : (function() { var current = global.Ractive; var exports = factory(); global.Ractive = exports; exports.noConflict = function() { global.Ractive = current; return exports; }; })(); }(this, (function () { 'use strict'; /* istanbul ignore if */ if (!Object.assign) { Object.assign = function(target) { var sources = [], len = arguments.length - 1; while ( len-- > 0 ) sources[ len ] = arguments[ len + 1 ]; if (target == null) { throw new TypeError('Cannot convert undefined or null to object'); } var to = Object(target); var sourcesLength = sources.length; for (var index = 0; index < sourcesLength; index++) { var nextSource = sources[index]; for (var nextKey in nextSource) { if (!Object.prototype.hasOwnProperty.call(nextSource, nextKey)) { continue; } to[nextKey] = nextSource[nextKey]; } } return to; }; } function hasOwn(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); } function fillGaps(target) { var sources = [], len = arguments.length - 1; while ( len-- > 0 ) sources[ len ] = arguments[ len + 1 ]; for (var i = 0; i < sources.length; i++) { var source = sources[i]; for (var key in source) { // Source can be a prototype-less object. if (key in target || !hasOwn(source, key)) { continue; } target[key] = source[key]; } } return target; } function toPairs(obj) { if ( obj === void 0 ) obj = {}; var pairs = []; for (var key in obj) { // Source can be a prototype-less object. if (!hasOwn(obj, key)) { continue; } pairs.push([key, obj[key]]); } return pairs; } var obj = Object; var assign = obj.assign; var create = obj.create; var defineProperty = obj.defineProperty; var defineProperties = obj.defineProperties; var keys = obj.keys; var toString = Object.prototype.toString; var isArray = Array.isArray; function isEqual(a, b) { if (a === null && b === null) { return true; } if (isObjectType(a) || isObjectType(b)) { return false; } return a === b; } // http://stackoverflow.com/questions/18082/validate-numbers-in-javascript-isnumeric function isNumeric(thing) { return !isNaN(parseFloat(thing)) && isFinite(thing); } function isObject(thing) { return thing && toString.call(thing) === '[object Object]'; } function isObjectLike(thing) { return !!(thing && (isObjectType(thing) || isFunction(thing))); } function isObjectType(thing) { return typeof thing === 'object'; } function isFunction(thing) { return typeof thing === 'function'; } function isString(thing) { return typeof thing === 'string'; } function isNumber(thing) { return typeof thing === 'number'; } function isUndefined(thing) { return thing === undefined; } /* istanbul ignore if */ if (!Array.prototype.find) { defineProperty(Array.prototype, 'find', { value: function value(callback, thisArg) { if (this === null || isUndefined(this)) { throw new TypeError('Array.prototype.find called on null or undefined'); } if (!isFunction(callback)) { throw new TypeError((callback + " is not a function")); } var array = Object(this); var arrayLength = array.length >>> 0; for (var index = 0; index < arrayLength; index++) { if (!hasOwn(array, index)) { continue; } if (!callback.call(thisArg, array[index], index, array)) { continue; } return array[index]; } return undefined; }, configurable: true, writable: true }); } // NOTE: Node doesn't exist in IE8. Nothing can be done. /* istanbul ignore if */ if ( typeof window !== 'undefined' && window.Node && window.Node.prototype && !window.Node.prototype.contains ) { Node.prototype.contains = function(node) { var this$1 = this; if (!node) { throw new TypeError('node required'); } do { if (this$1 === node) { return true; } } while ((node = node && node.parentNode)); return false; }; } /* istanbul ignore if */ if (typeof window !== 'undefined' && window.performance && !window.performance.now) { window.performance = window.performance || {}; var nowOffset = Date.now(); window.performance.now = function() { return Date.now() - nowOffset; }; } /* eslint no-console:"off" */ var win = typeof window !== 'undefined' ? window : null; var doc = win ? document : null; var isClient = !!doc; var base = typeof global !== 'undefined' ? global : win; var hasConsole = typeof console !== 'undefined' && isFunction(console.warn) && isFunction(console.warn.apply); var svg = doc ? doc.implementation.hasFeature('http://www.w3.org/TR/SVG11/feature#BasicStructure', '1.1') : false; var vendors = ['o', 'ms', 'moz', 'webkit']; /* istanbul ignore if */ if (!base.Promise) { var PENDING = {}; var FULFILLED = {}; var REJECTED = {}; var Promise$1 = (base.Promise = function(callback) { var fulfilledHandlers = []; var rejectedHandlers = []; var state = PENDING; var result; var dispatchHandlers; var makeResolver = function (newState) { return function(value) { if (state !== PENDING) { return; } result = value; state = newState; dispatchHandlers = makeDispatcher( state === FULFILLED ? fulfilledHandlers : rejectedHandlers, result ); wait(dispatchHandlers); }; }; var fulfill = makeResolver(FULFILLED); var reject = makeResolver(REJECTED); try { callback(fulfill, reject); } catch (err) { reject(err); } return { // `then()` returns a Promise - 2.2.7 then: function then(onFulfilled, onRejected) { var promise2 = new Promise$1(function (fulfill, reject) { var processResolutionHandler = function (handler, handlers, forward) { if (isFunction(handler)) { handlers.push(function (p1result) { try { resolve$1(promise2, handler(p1result), fulfill, reject); } catch (err) { reject(err); } }); } else { handlers.push(forward); } }; processResolutionHandler(onFulfilled, fulfilledHandlers, fulfill); processResolutionHandler(onRejected, rejectedHandlers, reject); if (state !== PENDING) { wait(dispatchHandlers); } }); return promise2; }, catch: function catch$1(onRejected) { return this.then(null, onRejected); }, finally: function finally$1(callback) { return this.then( function (v) { callback(); return v; }, function (e) { callback(); throw e; } ); } }; }); Promise$1.all = function(promises) { return new Promise$1(function (fulfill, reject) { var result = []; var pending; var i; if (!promises.length) { fulfill(result); return; } var processPromise = function (promise, i) { if (promise && isFunction(promise.then)) { promise.then(function (value) { result[i] = value; --pending || fulfill(result); }, reject); } else { result[i] = promise; --pending || fulfill(result); } }; pending = i = promises.length; while (i--) { processPromise(promises[i], i); } }); }; Promise$1.race = function(promises) { return new Promise$1(function (fulfill, reject) { var pending = true; function ok(v) { if (!pending) { return; } pending = false; fulfill(v); } function fail(e) { if (!pending) { return; } pending = false; reject(e); } for (var i = 0; i < promises.length; i++) { if (promises[i] && isFunction(promises[i].then)) { promises[i].then(ok, fail); } } }); }; Promise$1.resolve = function(value) { if (value && isFunction(value.then)) { return value; } return new Promise$1(function (fulfill) { fulfill(value); }); }; Promise$1.reject = function(reason) { if (reason && isFunction(reason.then)) { return reason; } return new Promise$1(function (fulfill, reject) { reject(reason); }); }; // TODO use MutationObservers or something to simulate setImmediate var wait = function(callback) { setTimeout(callback, 0); }; var makeDispatcher = function(handlers, result) { return function() { for (var handler = (void 0); (handler = handlers.shift()); ) { handler(result); } }; }; var resolve$1 = function(promise, x, fulfil, reject) { var then; if (x === promise) { throw new TypeError("A promise's fulfillment handler cannot return the same promise"); } if (x instanceof Promise$1) { x.then(fulfil, reject); } else if (x && (isObjectType(x) || isFunction(x))) { try { then = x.then; } catch (e) { reject(e); return; } if (isFunction(then)) { var called; var resolvePromise = function(y) { if (called) { return; } called = true; resolve$1(promise, y, fulfil, reject); }; var rejectPromise = function(r) { if (called) { return; } called = true; reject(r); }; try { then.call(x, resolvePromise, rejectPromise); } catch (e) { if (!called) { reject(e); called = true; return; } } } else { fulfil(x); } } else { fulfil(x); } }; } /* istanbul ignore if */ if ( typeof window !== 'undefined' && !(window.requestAnimationFrame && window.cancelAnimationFrame) ) { var lastTime = 0; window.requestAnimationFrame = function(callback) { var currentTime = Date.now(); var timeToNextCall = Math.max(0, 16 - (currentTime - lastTime)); var id = window.setTimeout(function () { callback(currentTime + timeToNextCall); }, timeToNextCall); lastTime = currentTime + timeToNextCall; return id; }; window.cancelAnimationFrame = function(id) { clearTimeout(id); }; } var defaults = { // render placement: el: void 0, append: false, delegate: true, enhance: false, // template: template: null, // parse: allowExpressions: true, delimiters: ['{{', '}}'], tripleDelimiters: ['{{{', '}}}'], staticDelimiters: ['[[', ']]'], staticTripleDelimiters: ['[[[', ']]]'], csp: true, interpolate: false, preserveWhitespace: false, sanitize: false, stripComments: true, contextLines: 0, // data & binding: data: create(null), helpers: create(null), computed: create(null), syncComputedChildren: false, resolveInstanceMembers: false, warnAboutAmbiguity: false, adapt: [], isolated: true, twoway: true, lazy: false, // transitions: noIntro: false, noOutro: false, transitionsEnabled: true, complete: void 0, nestedTransitions: true, // css: css: null, noCSSTransform: false }; // These are a subset of the easing equations found at // https://raw.github.com/danro/easing-js - license info // follows: // -------------------------------------------------- // easing.js v0.5.4 // Generic set of easing functions with AMD support // https://github.com/danro/easing-js // This code may be freely distributed under the MIT license // http://danro.mit-license.org/ // -------------------------------------------------- // All functions adapted from Thomas Fuchs & Jeremy Kahn // Easing Equations (c) 2003 Robert Penner, BSD license // https://raw.github.com/danro/easing-js/master/LICENSE // -------------------------------------------------- // In that library, the functions named easeIn, easeOut, and // easeInOut below are named easeInCubic, easeOutCubic, and // (you guessed it) easeInOutCubic. // // You can add additional easing functions to this list, and they // will be globally available. var easing = { linear: function linear(pos) { return pos; }, easeIn: function easeIn(pos) { /* istanbul ignore next */ return Math.pow(pos, 3); }, easeOut: function easeOut(pos) { return Math.pow(pos - 1, 3) + 1; }, easeInOut: function easeInOut(pos) { /* istanbul ignore next */ if ((pos /= 0.5) < 1) { return 0.5 * Math.pow(pos, 3); } /* istanbul ignore next */ return 0.5 * (Math.pow(pos - 2, 3) + 2); } }; function noop() {} /* global console */ /* eslint no-console:"off" */ var alreadyWarned = {}; var log; var printWarning; var welcome; if (hasConsole) { var welcomeIntro = [ "%cRactive.js %c1.3.0 %cin debug mode, %cmore...", 'color: rgb(114, 157, 52); font-weight: normal;', 'color: rgb(85, 85, 85); font-weight: normal;', 'color: rgb(85, 85, 85); font-weight: normal;', 'color: rgb(82, 140, 224); font-weight: normal; text-decoration: underline;' ]; var welcomeMessage = "You're running Ractive 1.3.0 in debug mode - messages will be printed to the console to help you fix problems and optimise your application.\n\nTo disable debug mode, add this line at the start of your app:\n Ractive.DEBUG = false;\n\nTo disable debug mode when your app is minified, add this snippet:\n Ractive.DEBUG = /unminified/.test(function(){/*unminified*/});\n\nGet help and support:\n http://ractive.js.org\n http://stackoverflow.com/questions/tagged/ractivejs\n http://groups.google.com/forum/#!forum/ractive-js\n http://twitter.com/ractivejs\n\nFound a bug? Raise an issue:\n https://github.com/ractivejs/ractive/issues\n\n"; welcome = function () { if (Ractive.WELCOME_MESSAGE === false) { welcome = noop; return; } var message = 'WELCOME_MESSAGE' in Ractive ? Ractive.WELCOME_MESSAGE : welcomeMessage; var hasGroup = !!console.groupCollapsed; if (hasGroup) { console.groupCollapsed.apply(console, welcomeIntro); } console.log(message); if (hasGroup) { console.groupEnd(welcomeIntro); } welcome = noop; }; printWarning = function (message, args) { welcome(); // extract information about the instance this message pertains to, if applicable if (isObjectType(args[args.length - 1])) { var options = args.pop(); var ractive = options ? options.ractive : null; if (ractive) { // if this is an instance of a component that we know the name of, add // it to the message var name; if (ractive.component && (name = ractive.component.name)) { message = "<" + name + "> " + message; } var node; if ( (node = options.node || (ractive.fragment && ractive.fragment.rendered && ractive.find('*'))) ) { args.push(node); } } } console.warn.apply( console, ['%cRactive.js: %c' + message, 'color: rgb(114, 157, 52);', 'color: rgb(85, 85, 85);'].concat( args ) ); }; log = function() { console.log.apply(console, arguments); }; } else { printWarning = log = welcome = noop; } function format(message, args) { return message.replace(/%s/g, function () { return args.shift(); }); } function fatal(message) { var args = [], len = arguments.length - 1; while ( len-- > 0 ) args[ len ] = arguments[ len + 1 ]; message = format(message, args); throw new Error(message); } function logIfDebug() { if (Ractive.DEBUG) { log.apply(null, arguments); } } function warn(message) { var args = [], len = arguments.length - 1; while ( len-- > 0 ) args[ len ] = arguments[ len + 1 ]; message = format(message, args); printWarning(message, args); } function warnOnce(message) { var args = [], len = arguments.length - 1; while ( len-- > 0 ) args[ len ] = arguments[ len + 1 ]; message = format(message, args); if (alreadyWarned[message]) { return; } alreadyWarned[message] = true; printWarning(message, args); } function warnIfDebug() { if (Ractive.DEBUG) { warn.apply(null, arguments); } } function warnOnceIfDebug() { if (Ractive.DEBUG) { warnOnce.apply(null, arguments); } } // Error messages that are used (or could be) in multiple places var badArguments = 'Bad arguments'; var noRegistryFunctionReturn = 'A function was specified for "%s" %s, but no %s was returned'; var missingPlugin = function (name, type) { return ("Missing \"" + name + "\" " + type + " plugin. You may need to download a plugin via http://ractive.js.org/integrations/#" + type + "s"); }; function findInViewHierarchy(registryName, ractive, name) { var instance = findInstance(registryName, ractive, name); return instance ? instance[registryName][name] : null; } function findInstance(registryName, ractive, name) { while (ractive) { if (name in ractive[registryName]) { return ractive; } if (ractive.isolated) { return null; } ractive = ractive.parent; } } function interpolate(from, to, ractive, type) { if (from === to) { return null; } if (type) { var interpol = findInViewHierarchy('interpolators', ractive, type); if (interpol) { return interpol(from, to) || null; } fatal(missingPlugin(type, 'interpolator')); } return ( interpolators.number(from, to) || interpolators.array(from, to) || interpolators.object(from, to) || null ); } var interpolators = { number: function number(from, to) { if (!isNumeric(from) || !isNumeric(to)) { return null; } from = +from; to = +to; var delta = to - from; if (!delta) { return function() { return from; }; } return function(t) { return from + t * delta; }; }, array: function array(from, to) { var len, i; if (!isArray(from) || !isArray(to)) { return null; } var intermediate = []; var interpolators = []; i = len = Math.min(from.length, to.length); while (i--) { interpolators[i] = interpolate(from[i], to[i]); } // surplus values - don't interpolate, but don't exclude them either for (i = len; i < from.length; i += 1) { intermediate[i] = from[i]; } for (i = len; i < to.length; i += 1) { intermediate[i] = to[i]; } return function(t) { var i = len; while (i--) { intermediate[i] = interpolators[i](t); } return intermediate; }; }, object: function object(from, to) { if (!isObject(from) || !isObject(to)) { return null; } var properties = []; var intermediate = {}; var interpolators = {}; var loop = function ( prop ) { if (hasOwn(from, prop)) { if (hasOwn(to, prop)) { properties.push(prop); interpolators[prop] = interpolate(from[prop], to[prop]) || (function () { return to[prop]; }); } else { intermediate[prop] = from[prop]; } } }; for (var prop in from) loop( prop ); for (var prop$1 in to) { if (hasOwn(to, prop$1) && !hasOwn(from, prop$1)) { intermediate[prop$1] = to[prop$1]; } } var len = properties.length; return function(t) { var i = len; while (i--) { var prop = properties[i]; intermediate[prop] = interpolators[prop](t); } return intermediate; }; } }; var refPattern = /\[\s*(\*|[0-9]|[1-9][0-9]+)\s*\]/g; var splitPattern = /([^\\](?:\\\\)*)\./; var escapeKeyPattern = /\\|\./g; var unescapeKeyPattern = /((?:\\)+)\1|\\(\.)/g; function escapeKey(key) { if (isString(key)) { return key.replace(escapeKeyPattern, '\\$&'); } return key; } function normalise(ref) { return ref ? ref.replace(refPattern, '.$1') : ''; } function splitKeypath(keypath) { var result = []; var match; keypath = normalise(keypath); while ((match = splitPattern.exec(keypath))) { var index = match.index + match[1].length; result.push(keypath.substr(0, index)); keypath = keypath.substr(index + 1); } result.push(keypath); return result; } function unescapeKey(key) { if (isString(key)) { return key.replace(unescapeKeyPattern, '$1$2'); } return key; } function addToArray(array, value) { var index = array.indexOf(value); if (index === -1) { array.push(value); } } function arrayContains(array, value) { for (var i = 0, c = array.length; i < c; i++) { if (array[i] == value) { return true; } } return false; } function arrayContentsMatch(a, b) { var i; if (!isArray(a) || !isArray(b)) { return false; } if (a.length !== b.length) { return false; } i = a.length; while (i--) { if (a[i] !== b[i]) { return false; } } return true; } function ensureArray(x) { if (isString(x)) { return [x]; } if (isUndefined(x)) { return []; } return x; } function lastItem(array) { return array[array.length - 1]; } function removeFromArray(array, member) { if (!array) { return; } var index = array.indexOf(member); if (index !== -1) { array.splice(index, 1); } } function combine() { var arrays = [], len = arguments.length; while ( len-- ) arrays[ len ] = arguments[ len ]; var res = arrays.concat.apply([], arrays); var i = res.length; while (i--) { var idx = res.indexOf(res[i]); if (~idx && idx < i) { res.splice(i, 1); } } return res; } function toArray(arrayLike) { var array = []; var i = arrayLike.length; while (i--) { array[i] = arrayLike[i]; } return array; } function findMap(array, fn) { var len = array.length; for (var i = 0; i < len; i++) { var result = fn(array[i]); if (result) { return result; } } } function buildNewIndices(one, two, comparator) { var oldArray = one; var newArray = two; if (comparator) { oldArray = oldArray.map(comparator); newArray = newArray.map(comparator); } var oldLength = oldArray.length; var usedIndices = {}; var firstUnusedIndex = 0; var result = oldArray.map(function (item) { var index; var start = firstUnusedIndex; do { index = newArray.indexOf(item, start); if (index === -1) { return -1; } start = index + 1; } while (usedIndices[index] === true && start < oldLength); // keep track of the first unused index, so we don't search // the whole of newArray for each item in oldArray unnecessarily if (index === firstUnusedIndex) { firstUnusedIndex += 1; } // allow next instance of next "equal" to be found item usedIndices[index] = true; return index; }); var len = (result.oldLen = oldArray.length); result.newLen = newArray.length; if (len === result.newLen) { var i = 0; for (i; i < len; i++) { if (result[i] !== i) { break; } } if (i === len) { result.same = true; } } return result; } var fnBind = Function.prototype.bind; function bind(fn, context) { if (!/this/.test(fn.toString())) { return fn; } var bound = fnBind.call(fn, context); for (var prop in fn) { bound[prop] = fn[prop]; } return bound; } var shuffleTasks = { early: [], mark: [] }; var registerQueue = { early: [], mark: [] }; var noVirtual = { virtual: false }; var ModelBase = function ModelBase(parent) { this.deps = []; this.children = []; this.childByKey = {}; this.links = []; this.bindings = []; if (parent) { this.parent = parent; this.root = parent.root; } }; var ModelBase__proto__ = ModelBase.prototype; ModelBase__proto__.addShuffleTask = function addShuffleTask (task, stage) { if ( stage === void 0 ) stage = 'early'; shuffleTasks[stage].push(task); }; ModelBase__proto__.addShuffleRegister = function addShuffleRegister (item, stage) { if ( stage === void 0 ) stage = 'early'; registerQueue[stage].push({ model: this, item: item }); }; ModelBase__proto__.downstreamChanged = function downstreamChanged () {}; ModelBase__proto__.findMatches = function findMatches (keys$$1) { var len = keys$$1.length; var existingMatches = [this]; var matches; var i; var loop = function ( ) { var key = keys$$1[i]; if (key === '*') { matches = []; existingMatches.forEach(function (model) { matches.push.apply(matches, model.getValueChildren(model.get())); }); } else { matches = existingMatches.map(function (model) { return model.joinKey(key); }); } existingMatches = matches; }; for (i = 0; i < len; i += 1) loop( ); return matches; }; ModelBase__proto__.getKeypath = function getKeypath (ractive) { if (ractive !== this.ractive && this._link) { return this._link.target.getKeypath(ractive); } if (!this.keypath) { var parent = this.parent && this.parent.getKeypath(ractive); this.keypath = parent ? ((this.parent.getKeypath(ractive)) + "." + (escapeKey(this.key))) : escapeKey(this.key); } return this.keypath; }; ModelBase__proto__.getValueChildren = function getValueChildren (value) { var this$1 = this; var children; if (isArray(value)) { children = []; if ('length' in this && this.length !== value.length) { children.push(this.joinKey('length')); } value.forEach(function (m, i) { children.push(this$1.joinKey(i)); }); } else if (isObject(value) || isFunction(value)) { children = keys(value).map(function (key) { return this$1.joinKey(key); }); } else if (value != null) { children = []; } var computed = this.computed; if (computed) { children.push.apply(children, keys(computed).map(function (k) { return this$1.joinKey(k); })); } return children; }; ModelBase__proto__.getVirtual = function getVirtual (shouldCapture) { var this$1 = this; var value = this.get(shouldCapture, { virtual: false }); if (isObject(value)) { var result = isArray(value) ? [] : create(null); var keys$$1 = keys(value); var i = keys$$1.length; while (i--) { var child = this$1.childByKey[keys$$1[i]]; if (!child) { result[keys$$1[i]] = value[keys$$1[i]]; } else if (child._link) { result[keys$$1[i]] = child._link.getVirtual(); } else { result[keys$$1[i]] = child.getVirtual(); } } i = this.children.length; while (i--) { var child$1 = this$1.children[i]; if (!(child$1.key in result) && child$1._link) { result[child$1.key] = child$1._link.getVirtual(); } } if (this.computed) { keys$$1 = keys(this.computed); i = keys$$1.length; while (i--) { result[keys$$1[i]] = this$1.computed[keys$$1[i]].get(); } } return result; } else { return value; } }; ModelBase__proto__.has = function has (key) { var this$1 = this; if (this._link) { return this._link.has(key); } var value = this.get(false, noVirtual); if (!value) { return false; } key = unescapeKey(key); if ((isFunction(value) || isObject(value)) && key in value) { return true; } var computed = this.computed; if (computed && key in this.computed) { return true; } computed = this.root.ractive && this.root.ractive.computed; if (computed) { keys(computed).forEach(function (k) { if (computed[k].pattern && computed[k].pattern.test(this$1.getKeypath())) { return true; } }); } return false; }; ModelBase__proto__.joinAll = function joinAll (keys$$1, opts) { var model = this; for (var i = 0; i < keys$$1.length; i += 1) { if ( opts && opts.lastLink === false && i + 1 === keys$$1.length && model.childByKey[keys$$1[i]] && model.childByKey[keys$$1[i]]._link ) { return model.childByKey[keys$$1[i]]; } model = model.joinKey(keys$$1[i], opts); } return model; }; ModelBase__proto__.notifyUpstream = function notifyUpstream (startPath) { var this$1 = this; var parent = this.parent; var path = startPath || [this.key]; while (parent) { if (parent.patterns) { parent.patterns.forEach(function (o) { return o.notify(path.slice()); }); } path.unshift(parent.key); parent.links.forEach(function (l) { return l.notifiedUpstream(path, this$1.root); }); parent.deps.forEach(function (d) { return d.handleChange(path); }); parent.downstreamChanged(startPath); parent = parent.parent; } }; ModelBase__proto__.rebind = function rebind (next, previous, safe) { var this$1 = this; if (this._link) { this._link.rebind(next, previous, false); } // tell the deps to move to the new target var i = this.deps.length; while (i--) { if (this$1.deps[i].rebind) { this$1.deps[i].rebind(next, previous, safe); } } i = this.links.length; while (i--) { var link = this$1.links[i]; // only relink the root of the link tree if (link.owner && link.owner._link) { link.relinking(next, safe); } } i = this.children.length; while (i--) { var child = this$1.children[i]; child.rebind(next ? next.joinKey(child.key) : undefined, child._link || child, safe); if (this$1.dataModel) { this$1.addShuffleTask(function () { return checkDataLink(this$1, this$1.retrieve()); }, 'early'); } } i = this.bindings.length; while (i--) { this$1.bindings[i].rebind(next, previous, safe); } }; ModelBase__proto__.reference = function reference () { 'refs' in this ? this.refs++ : (this.refs = 1); }; ModelBase__proto__.register = function register (dep) { this.deps.push(dep); }; ModelBase__proto__.registerLink = function registerLink (link) { addToArray(this.links, link); }; ModelBase__proto__.registerPatternObserver = function registerPatternObserver (observer) { (this.patterns || (this.patterns = [])).push(observer); this.register(observer); }; ModelBase__proto__.registerTwowayBinding = function registerTwowayBinding (binding) { this.bindings.push(binding); }; ModelBase__proto__.unreference = function unreference () { if ('refs' in this) { this.refs--; } }; ModelBase__proto__.unregister = function unregister (dep) { removeFromArray(this.deps, dep); }; ModelBase__proto__.unregisterLink = function unregisterLink (link) { removeFromArray(this.links, link); }; ModelBase__proto__.unregisterPatternObserver = function unregisterPatternObserver (observer) { removeFromArray(this.patterns, observer); this.unregister(observer); }; ModelBase__proto__.unregisterTwowayBinding = function unregisterTwowayBinding (binding) { removeFromArray(this.bindings, binding); }; ModelBase__proto__.updateFromBindings = function updateFromBindings$1 (cascade) { var this$1 = this; var i = this.bindings.length; while (i--) { var value = this$1.bindings[i].getValue(); if (value !== this$1.value) { this$1.set(value); } } // check for one-way bindings if there are no two-ways if (!this.bindings.length) { var oneway = findBoundValue(this.deps); if (oneway && oneway.value !== this.value) { this.set(oneway.value); } } if (cascade) { this.children.forEach(updateFromBindings); this.links.forEach(updateFromBindings); if (this._link) { this._link.updateFromBindings(cascade); } } }; // TODO: this may be better handled by overriding `get` on models with a parent that isRoot function maybeBind(model, value, shouldBind) { if (shouldBind && isFunction(value) && model.parent && model.parent.isRoot) { if (!model.boundValue) { model.boundValue = bind(value._r_unbound || value, model.parent.ractive); } return model.boundValue; } return value; } function updateFromBindings(model) { model.updateFromBindings(true); } function findBoundValue(list) { var i = list.length; while (i--) { if (list[i].bound) { var owner = list[i].owner; if (owner) { var value = owner.name === 'checked' ? owner.node.checked : owner.node.value; return { value: value }; } } } } function fireShuffleTasks(stage) { if (!stage) { fireShuffleTasks('early'); fireShuffleTasks('mark'); } else { var tasks = shuffleTasks[stage]; shuffleTasks[stage] = []; var i = tasks.length; while (i--) { tasks[i](); } var register = registerQueue[stage]; registerQueue[stage] = []; i = register.length; while (i--) { register[i].model.register(register[i].item); } } } function shuffle(model, newIndices, link, unsafe) { model.shuffling = true; var i = newIndices.length; while (i--) { var idx = newIndices[i]; // nothing is actually changing, so move in the index and roll on if (i === idx) { continue; } // rebind the children on i to idx if (i in model.childByKey) { model.childByKey[i].rebind( !~idx ? undefined : model.joinKey(idx), model.childByKey[i], !unsafe ); } } var upstream = model.source().length !== model.source().value.length; model.links.forEach(function (l) { return l.shuffle(newIndices); }); if (!link) { fireShuffleTasks('early'); } i = model.deps.length; while (i--) { if (model.deps[i].shuffle) { model.deps[i].shuffle(newIndices); } } model[link ? 'marked' : 'mark'](); if (!link) { fireShuffleTasks('mark'); } if (upstream) { model.notifyUpstream(); } model.shuffling = false; } function checkDataLink(model, value) { if (value !== model.dataModel) { if (value && value.viewmodel && value.viewmodel.isRoot && model.childByKey.data) { model.childByKey.data.link(value.viewmodel, 'data'); model.dataModel = value; } else if (model.dataModel) { model.childByKey.data.unlink(); model.dataModel = true; } } } var stack = []; var captureGroup; function startCapturing() { stack.push((captureGroup = [])); } function stopCapturing() { var dependencies = stack.pop(); captureGroup = stack[stack.length - 1]; return dependencies; } function capture(model) { if (captureGroup) { captureGroup.push(model); } } function bind$1(x) { x.bind(); } function cancel(x) { x.cancel(); } function destroyed(x) { x.destroyed(); } function handleChange(x) { x.handleChange(); } function mark(x) { x.mark(); } function markForce(x) { x.mark(true); } function marked(x) { x.marked(); } function markedAll(x) { x.markedAll(); } function render(x) { x.render(); } function shuffled(x) { x.shuffled(); } function teardown(x) { x.teardown(); } function unbind(x) { x.unbind(); } function unrender(x) { x.unrender(); } function update(x) { x.update(); } function toString$1(x) { return x.toString(); } function toEscapedString(x) { return x.toString(true); } // this is the dry method of checking to see if a rebind applies to // a particular keypath because in some cases, a dep may be bound // directly to a particular keypath e.g. foo.bars.0.baz and need // to avoid getting kicked to foo.bars.1.baz if foo.bars is unshifted function rebindMatch(template, next, previous, fragment) { var keypath = template.r || template; // no valid keypath, go with next if (!keypath || !isString(keypath)) { return next; } // completely contextual ref, go with next if ( keypath === '.' || keypath[0] === '@' || (next || previous).isKey || (next || previous).isKeypath ) { return next; } var parts = keypath.split('/'); var keys = splitKeypath(parts[parts.length - 1]); var last = keys[keys.length - 1]; // check the keypath against the model keypath to see if it matches var model = next || previous; // check to see if this was an alias if (model && keys.length === 1 && last !== model.key && fragment) { keys = findAlias(last, fragment) || keys; } var i = keys.length; var match = true; var shuffling = false; while (model && i--) { if (model.shuffling) { shuffling = true; } // non-strict comparison to account for indices in keypaths if (keys[i] != model.key) { match = false; } model = model.parent; } // next is undefined, but keypath is shuffling and previous matches if (!next && match && shuffling) { return previous; } else if (next && !match && shuffling) // next is defined, but doesn't match the keypath { return previous; } else { return next; } } function findAlias(name, fragment) { while (fragment) { var z = fragment.aliases; if (z && z[name]) { var aliases = (fragment.owner.iterations ? fragment.owner : fragment).owner.template.z; for (var i = 0; i < aliases.length; i++) { if (aliases[i].n === name) { var alias = aliases[i].x; if (!alias.r) { return false; } var parts = alias.r.split('/'); return splitKeypath(parts[parts.length - 1]); } } return; } fragment = fragment.componentParent || fragment.parent; } } // temporary placeholder target for detached implicit links var Missing = { key: '@missing', animate: noop, applyValue: noop, get: noop, getKeypath: function getKeypath() { return this.key; }, joinAll: function joinAll() { return this; }, joinKey: function joinKey() { return this; }, mark: noop, registerLink: noop, shufle: noop, set: noop, unregisterLink: noop }; Missing.parent = Missing; var LinkModel = (function (ModelBase) { function LinkModel(parent, owner, target, key) { ModelBase.call(this, parent); this.owner = owner; this.target = target; this.key = isUndefined(key) ? owner.key : key; if (owner && owner.isLink) { this.sourcePath = (owner.sourcePath) + "." + (this.key); } if (target) { target.registerLink(this); } if (parent) { this.isReadonly = parent.isReadonly; } this.isLink = true; } if ( ModelBase ) LinkModel.__proto__ = ModelBase; var LinkModel__proto__ = LinkModel.prototype = Object.create( ModelBase && ModelBase.prototype ); LinkModel__proto__.constructor = LinkModel; LinkModel__proto__.animate = function animate (from, to, options, interpolator) { return this.target.animate(from, to, options, interpolator); }; LinkModel__proto__.applyValue = function applyValue (value) { if (this.boundValue) { this.boundValue = null; } this.target.applyValue(value); }; LinkModel__proto__.attach = function attach (fragment) { var model = resolveReference(fragment, this.key); if (model) { this.relinking(model, false); } else { // if there is no link available, move everything here to real models this.owner.unlink(); } }; LinkModel__proto__.detach = function detach () { this.relinking(Missing, false); }; LinkModel__proto__.get = function get (shouldCapture, opts) { if ( opts === void 0 ) opts = {}; if (shouldCapture) { capture(this); // may need to tell the target to unwrap opts.unwrap = 'unwrap' in opts ? opts.unwrap : true; } var bind = 'shouldBind' in opts ? opts.shouldBind : true; opts.shouldBind = this.mapping && this.target.parent && this.target.parent.isRoot; return maybeBind(this, this.target.get(false, opts), bind); }; LinkModel__proto__.getKeypath = function getKeypath (ractive) { if (ractive && ractive !== this.root.ractive) { return this.target.getKeypath(ractive); } return ModelBase.prototype.getKeypath.call(this, ractive); }; LinkModel__proto__.handleChange = function handleChange$1 () { this.deps.forEach(handleChange); this.links.forEach(handleChange); this.notifyUpstream(); }; LinkModel__proto__.isDetached = function isDetached () { return this.virtual && this.target === Missing; }; LinkModel__proto__.joinKey = function joinKey (key) { // TODO: handle nested links if (isUndefined(key) || key === '') { return this; } if (!hasOwn(this.childByKey, key)) { var child = new LinkModel(this, this, this.target.joinKey(key), key); this.children.push(child); this.childByKey[key] = child; } return this.childByKey[key]; }; LinkModel__proto__.mark = function mark (force) { this.target.mark(force); }; LinkModel__proto__.marked = function marked$1 () { if (this.boundValue) { this.boundValue = null; } this.links.forEach(marked); this.deps.forEach(handleChange); }; LinkModel__proto__.markedAll = function markedAll$1 () { this.children.forEach(markedAll); this.marked(); }; LinkModel__proto__.notifiedUpstream = function notifiedUpstream (startPath, root) { var this$1 = this; this.links.forEach(function (l) { return l.notifiedUpstream(startPath, this$1.root); }); this.deps.forEach(handleChange); if (startPath && this.rootLink && this.root !== root) { var path = startPath.slice(1); path.unshift(this.key); this.notifyUpstream(path); } }; LinkModel__proto__.relinked = function relinked () { this.target.registerLink(this); this.children.forEach(function (c) { return c.relinked(); }); }; LinkModel__proto__.relinking = function relinking (target, safe) { var this$1 = this; if (this.rootLink && this.sourcePath) { target = rebindMatch(this.sourcePath, target, this.target); } if (!target || this.target === target) { return; } this.target && this.target.unregisterLink(this); this.target = target; this.children.forEach(function (c) { c.relinking(target.joinKey(c.key), safe); }); if (this.rootLink) { this.addShuffleTask(function () { this$1.relinked(); if (!safe) { this$1.markedAll(); this$1.notifyUpstream(); } }); } }; LinkModel__proto__.set = function set (value) { if (this.boundValue) { this.boundValue = null; } this.target.set(value); }; LinkModel__proto__.shuffle = function shuffle$1 (newIndices) { // watch for extra shuffles caused by a shuffle in a downstream link if (this.shuffling) { return; } // let the real model handle firing off shuffles if (!this.target.shuffling) { if (this.target.shuffle) { this.target.shuffle(newIndices); } else { // the target is a computation, which can't shuffle this.target.mark(); } } else { shuffle(this, newIndices, true); } }; LinkModel__proto__.source = function source () { if (this.target.source) { return this.target.source(); } else { return this.target; } }; LinkModel__proto__.teardown = function teardown$3 () { if (this._link) { this._link.teardown(); } this.target.unregisterLink(this); this.children.forEach(teardown); }; return LinkModel; }(ModelBase)); ModelBase.prototype.link = function link(model, keypath, options) { var lnk = this._link || new LinkModel(this.parent, this, model, this.key); lnk.implicit = options && options.implicit; lnk.mapping = options && options.mapping; lnk.sourcePath = keypath; lnk.rootLink = true; if (this._link) { this._link.relinking(model, false); } this.rebind(lnk, this, false); fireShuffleTasks(); this._link = lnk; lnk.markedAll(); this.notifyUpstream(); return lnk; }; ModelBase.prototype.unlink = function unlink() { if (this._link) { var ln = this._link; this._link = undefined; ln.rebind(this, ln, false); fireShuffleTasks(); ln.teardown(); this.notifyUpstream(); } }; function fromExpression(body, length) { if ( length === void 0 ) length = 0; var args = new Array(length); while (length--) { args[length] = "_" + length; } // Functions created directly with new Function() look like this: // function anonymous (_0 /**/) { return _0*2 } // // With this workaround, we get a little more compact: // function (_0){return _0*2} return new Function([], ("return function (" + (args.join(',')) + "){return(" + body + ");};"))(); } var functions = create(null); function getFunction(str, i) { if (functions[str]) { return functions[str]; } return (functions[str] = createFunction(str, i)); } function addFunctions(template) { if (!template) { return; } var exp = template.e; if (!exp) { return; } keys(exp).forEach(function (str) { if (functions[str]) { return; } functions[str] = exp[str]; }); } var TEMPLATE_VERSION = 4; var leadingWhitespace = /^\s+/; var ParseError = function(message) { this.name = 'ParseError'; this.message = message; try { throw new Error(message); } catch (e) { this.stack = e.stack; } }; ParseError.prototype = Error.prototype; var Parser = function(str, options) { var item; var lineStart = 0; this.str = str; this.options = options || {}; this.pos = 0; this.lines = this.str.split('\n'); this.lineEnds = this.lines.map(function (line) { var lineEnd = lineStart + line.length + 1; // +1 for the newline lineStart = lineEnd; return lineEnd; }, 0); // Custom init logic if (this.init) { this.init(str, options); } var items = []; while (this.pos < this.str.length && (item = this.read())) { items.push(item); } this.leftover = this.remaining(); this.result = this.postProcess ? this.postProcess(items, options) : items; }; Parser.prototype = { read: function read(converters) { var this$1 = this; var i, item; if (!converters) { converters = this.converters; } var pos = this.pos; var len = converters.length; for (i = 0; i < len; i += 1) { this$1.pos = pos; // reset for each attempt if ((item = converters[i](this$1))) { return item; } } return null; }, getContextMessage: function getContextMessage(pos, message) { var ref = this.getLinePos(pos); var lineNum = ref[0]; var columnNum = ref[1]; if (this.options.contextLines === -1) { return [lineNum, columnNum, (message + " at line " + lineNum + " character " + columnNum)]; } var line = this.lines[lineNum - 1]; var contextUp = ''; var contextDown = ''; if (this.options.contextLines) { var start = lineNum - 1 - this.options.contextLines < 0 ? 0 : lineNum - 1 - this.options.contextLines; contextUp = this.lines .slice(start, lineNum - 1 - start) .join('\n') .replace(/\t/g, ' '); contextDown = this.lines .slice(lineNum, lineNum + this.options.contextLines) .join('\n') .replace(/\t/g, ' '); if (contextUp) { contextUp += '\n'; } if (contextDown) { contextDown = '\n' + contextDown; } } var numTabs = 0; var annotation = contextUp + line.replace(/\t/g, function (match, char) { if (char < columnNum) { numTabs += 1; } return ' '; }) + '\n' + new Array(columnNum + numTabs).join(' ') + '^----' + contextDown; return [ lineNum, columnNum, (message + " at line " + lineNum + " character " + columnNum + ":\n" + annotation) ]; }, getLinePos: function getLinePos(char) { var this$1 = this; var lineNum = 0; var lineStart = 0; while (char >= this.lineEnds[lineNum]) { lineStart = this$1.lineEnds[lineNum]; lineNum += 1; } var columnNum = char - lineStart; return [lineNum + 1, columnNum + 1, char]; // line/col should be one-based, not zero-based! }, error: function error(message) { var ref = this.getContextMessage(this.pos, message); var lineNum = ref[0]; var columnNum = ref[1]; var msg = ref[2]; var error = new ParseError(msg); error.line = lineNum; error.character = columnNum; error.shortMessage = message; throw error; }, matchString: function matchString(string) { if (this.str.substr(this.pos, string.length) === string) { this.pos += string.length; return string; } }, matchPattern: function matchPattern(pattern) { var match; if ((match = pattern.exec(this.remaining()))) { this.pos += match[0].length; return match[1] || match[0]; } }, sp: function sp() { this.matchPattern(leadingWhitespace); }, remaining: function remaining() { return this.str.substring(this.pos); }, nextChar: function nextChar() { return this.str.charAt(this.pos); }, warn: function warn(message) { var msg = this.getContextMessage(this.pos, message)[2]; warnIfDebug(msg); } }; Parser.extend = function(proto) { var Parent = this; var Child = function(str, options) { Parser.call(this, str, options); }; Child.prototype = create(Parent.prototype); for (var key in proto) { if (hasOwn(proto, key)) { Child.prototype[key] = proto[key]; } } Child.extend = Parser.extend; return Child; }; var TEXT = 1; var INTERPOLATOR = 2; var TRIPLE = 3; var SECTION = 4; var INVERTED = 5; var CLOSING = 6; var ELEMENT = 7; var PARTIAL = 8; var COMMENT = 9; var DELIMCHANGE = 10; var ANCHOR = 11; var ATTRIBUTE = 13; var CLOSING_TAG = 14; var COMPONENT = 15; var YIELDER = 16; var INLINE_PARTIAL = 17; var DOCTYPE = 18; var ALIAS = 19; var AWAIT = 55; var NUMBER_LITERAL = 20; var STRING_LITERAL = 21; var ARRAY_LITERAL = 22; var OBJECT_LITERAL = 23; var BOOLEAN_LITERAL = 24; var REGEXP_LITERAL = 25; var GLOBAL = 26; var KEY_VALUE_PAIR = 27; var REFERENCE = 30; var REFINEMENT = 31; var MEMBER = 32; var PREFIX_OPERATOR = 33; var BRACKETED = 34; var CONDITIONAL = 35; var INFIX_OPERATOR = 36; var INVOCATION = 40; var SECTION_IF = 50; var SECTION_UNLESS = 51; var SECTION_EACH = 52; var SECTION_WITH = 53; var SECTION_IF_WITH = 54; var ELSE = 60; var ELSEIF = 61; var THEN = 62; var CATCH = 63; var EVENT = 70; var DECORATOR = 71; var TRANSITION = 72; var BINDING_FLAG = 73; var DELEGATE_FLAG = 74; var delimiterChangePattern = /^[^\s=]+/; var whitespacePattern = /^\s+/; function readDelimiterChange(parser) { if (!parser.matchString('=')) { return null; } var start = parser.pos; // allow whitespace before new opening delimiter parser.sp(); var opening = parser.matchPattern(delimiterChangePattern); if (!opening) { parser.pos = start; return null; } // allow whitespace (in fact, it's necessary...) if (!parser.matchPattern(whitespacePattern)) { return null; } var closing = parser.matchPattern(delimiterChangePattern); if (!closing) { parser.pos = start; return null; } // allow whitespace before closing '=' parser.sp(); if (!parser.matchString('=')) { parser.pos = start; return null; } return [opening, closing]; } var regexpPattern = /^(\/(?:[^\n\r\u2028\u2029/\\[]|\\.|\[(?:[^\n\r\u2028\u2029\]\\]|\\.)*])+\/(?:([gimuy])(?![a-z]*\2))*(?![a-zA-Z_$0-9]))/; function readNumberLiteral(parser) { var result; if ((result = parser.matchPattern(regexpPattern))) { return { t: REGEXP_LITERAL, v: result }; } return null; } var pattern = /[-/\\^$*+?.()|[\]{}]/g; function escapeRegExp(str) { return str.replace(pattern, '\\$&'); } var regExpCache = {}; function getLowestIndex(haystack, needles) { return haystack.search( regExpCache[needles.join()] || (regExpCache[needles.join()] = new RegExp(needles.map(escapeRegExp).join('|'))) ); } // https://github.com/kangax/html-minifier/issues/63#issuecomment-37763316 //export const booleanAttributes = /^(allowFullscreen|async|autofocus|autoplay|checked|compact|controls|declare|default|defaultChecked|defaultMuted|defaultSelected|defer|disabled|enabled|formNoValidate|hidden|indeterminate|inert|isMap|itemScope|loop|multiple|muted|noHref|noResize|noShade|noValidate|noWrap|open|pauseOnExit|readOnly|required|reversed|scoped|seamless|selected|sortable|translate|trueSpeed|typeMustMatch|visible)$/i; var booleanAttributes = { allowfullscreen: 1, async: 1, autofocus: 1, autoplay: 1, checked: 1, compact: 1, controls: 1, declare: 1, default: 1, defaultchecked: 1, defaultmuted: 1, defaultselected: 1, defer: 1, disabled: 1, enabled: 1, formnovalidate: 1, hidden: 1, indeterminate: 1, inert: 1, ismap: 1, itemscope: 1, loop: 1, multiple: 1, muted: 1, nohref: 1, noresize: 1, noshade: 1, novalidate: 1, nowrap: 1, open: 1, pauseonexit: 1, readonly: 1, required: 1, reversed: 1, scoped: 1, seamless: 1, selected: 1, sortable: 1, translate: 1, truespeed: 1, typemustmatch: 1, visible: 1 }; var voidElements = { area: 1, base: 1, br: 1, col: 1, command: 1, doctype: 1, embed: 1, hr: 1, img: 1, input: 1, keygen: 1, link: 1, meta: 1, param: 1, source: 1, track: 1, wbr: 1 }; var htmlEntities = { quot: 34, amp: 38, apos: 39, lt: 60, gt: 62, nbsp: 160, iexcl: 161, cent: 162, pound: 163, curren: 164, yen: 165, brvbar: 166, sect: 167, uml: 168, copy: 169, ordf: 170, laquo: 171, not: 172, shy: 173, reg: 174, macr: 175, deg: 176, plusmn: 177, sup2: 178, sup3: 179, acute: 180, micro: 181, para: 182, middot: 183, cedil: 184, sup1: 185, ordm: 186, raquo: 187, frac14: 188, frac12: 189, frac34: 190, iquest: 191, Agrave: 192, Aacute: 193, Acirc: 194, Atilde: 195, Auml: 196, Aring: 197, AElig: 198, Ccedil: 199, Egrave: 200, Eacute: 201, Ecirc: 202, Euml: 203, Igrave: 204, Iacute: 205, Icirc: 206, Iuml: 207, ETH: 208, Ntilde: 209, Ograve: 210, Oacute: 211, Ocirc: 212, Otilde: 213, Ouml: 214, times: 215, Oslash: 216, Ugrave: 217, Uacute: 218, Ucirc: 219, Uuml: 220, Yacute: 221, THORN: 222, szlig: 223, agrave: 224, aacute: 225, acirc: 226, atilde: 227, auml: 228, aring: 229, aelig: 230, ccedil: 231, egrave: 232, eacute: 233, ecirc: 234, euml: 235, igrave: 236, iacute: 237, icirc: 238, iuml: 239, eth: 240, ntilde: 241, ograve: 242, oacute: 243, ocirc: 244, otilde: 245, ouml: 246, divide: 247, oslash: 248, ugrave: 249, uacute: 250, ucirc: 251, uuml: 252, yacute: 253, thorn: 254, yuml: 255, OElig: 338, oelig: 339, Scaron: 352, scaron: 353, Yuml: 376, fnof: 402, circ: 710, tilde: 732, Alpha: 913, Beta: 914, Gamma: 915, Delta: 916, Epsilon: 917, Zeta: 918, Eta: 919, Theta: 920, Iota: 921, Kappa: 922, Lambda: 923, Mu: 924, Nu: 925, Xi: 926, Omicron: 927, Pi: 928, Rho: 929, Sigma: 931, Tau: 932, Upsilon: 933, Phi: 934, Chi: 935, Psi: 936, Omega: 937, alpha: 945, beta: 946, gamma: 947, delta: 948, epsilon: 949, zeta: 950, eta: 951, theta: 952, iota: 953, kappa: 954, lambda: 955, mu: 956, nu: 957, xi: 958, omicron: 959, pi: 960, rho: 961, sigmaf: 962, sigma: 963, tau: 964, upsilon: 965, phi: 966, chi: 967, psi: 968, omega: 969, thetasym: 977, upsih: 978, piv: 982, ensp: 8194, emsp: 8195, thinsp: 8201, zwnj: 8204, zwj: 8205, lrm: 8206, rlm: 8207, ndash: 8211, mdash: 8212, lsquo: 8216, rsquo: 8217, sbquo: 8218, ldquo: 8220, rdquo: 8221, bdquo: 8222, dagger: 8224, Dagger: 8225, bull: 8226, hellip: 8230, permil: 8240, prime: 8242, Prime: 8243, lsaquo: 8249, rsaquo: 8250, oline: 8254, frasl: 8260, euro: 8364, image: 8465, weierp: 8472, real: 8476, trade: 8482, alefsym: 8501, larr: 8592, uarr: 8593, rarr: 8594, darr: 8595, harr: 8596, crarr: 8629, lArr: 8656, uArr: 8657, rArr: 8658, dArr: 8659, hArr: 8660, forall: 8704, part: 8706, exist: 8707, empty: 8709, nabla: 8711, isin: 8712, notin: 8713, ni: 8715, prod: 8719, sum: 8721, minus: 8722, lowast: 8727, radic: 8730, prop: 8733, infin: 8734, ang: 8736, and: 8743, or: 8744, cap: 8745, cup: 8746, int: 8747, there4: 8756, sim: 8764, cong: 8773, asymp: 8776, ne: 8800, equiv: 8801, le: 8804, ge: 8805, sub: 8834, sup: 8835, nsub: 8836, sube: 8838, supe: 8839, oplus: 8853, otimes: 8855, perp: 8869, sdot: 8901, lceil: 8968, rceil: 8969, lfloor: 8970, rfloor: 8971, lang: 9001, rang: 9002, loz: 9674, spades: 9824, clubs: 9827, hearts: 9829, diams: 9830 }; var controlCharacters = [ 8364, 129, 8218, 402, 8222, 8230, 8224, 8225, 710, 8240, 352, 8249, 338, 141, 381, 143, 144, 8216, 8217, 8220, 8221, 8226, 8211, 8212, 732, 8482, 353, 8250, 339, 157, 382, 376 ]; var entityPattern = new RegExp( '&(#?(?:x[\\w\\d]+|\\d+|' + keys(htmlEntities).join('|') + '));?', 'g' ); var codePointSupport = isFunction(String.fromCodePoint); var codeToChar = codePointSupport ? String.fromCodePoint : String.fromCharCode; function decodeCharacterReferences(html) { return html.replace(entityPattern, function (match, entity) { var code; // Handle named entities if (entity[0] !== '#') { code = htmlEntities[entity]; } else if (entity[1] === 'x') { code = parseInt(entity.substring(2), 16); } else { code = parseInt(entity.substring(1), 10); } if (!code) { return match; } return codeToChar(validateCode(code)); }); } var lessThan = /</g; var greaterThan = />/g; var amp = /&/g; var invalid = 65533; function escapeHtml(str) { return str .replace(amp, '&amp;') .replace(lessThan, '&lt;') .replace(greaterThan, '&gt;'); } // some code points are verboten. If we were inserting HTML, the browser would replace the illegal // code points with alternatives in some cases - since we're bypassing that mechanism, we need // to replace them ourselves // // Source: http://en.wikipedia.org/wiki/Character_encodings_in_HTML#Illegal_characters /* istanbul ignore next */ function validateCode(code) { if (!code) { return invalid; } // line feed becomes generic whitespace if (code === 10) { return 32; } // ASCII range. (Why someone would use HTML entities for ASCII characters I don't know, but...) if (code < 128) { return code; } // code points 128-159 are dealt with leniently by browsers, but they're incorrect. We need // to correct the mistake or we'll end up with missing € signs and so on if (code <= 159) { return controlCharacters[code - 128]; } // basic multilingual plane if (code < 55296) { return code; } // UTF-16 surrogate halves if (code <= 57343) { return invalid; } // rest of the basic multilingual plane if (code <= 65535) { return code; } else if (!codePointSupport) { return invalid; } // supplementary multilingual plane 0x10000 - 0x1ffff if (code >= 65536 && code <= 131071) { return code; } // supplementary ideographic plane 0x20000 - 0x2ffff if (code >= 131072 && code <= 196607) { return code; } return invalid; } var expectedExpression = 'Expected a JavaScript expression'; var expectedParen = 'Expected closing paren'; // bulletproof number regex from https://gist.github.com/Rich-Harris/7544330 var numberPattern = /^(?:[+-]?)0*(?:(?:(?:[1-9]\d*)?\.\d+)|(?:(?:0|[1-9]\d*)\.)|(?:0|[1-9]\d*))(?:[eE][+-]?\d+)?/; function readNumberLiteral$1(parser) { var result; if ((result = parser.matchPattern(numberPattern))) { return { t: NUMBER_LITERAL, v: result }; } return null; } function readBooleanLiteral(parser) { var remaining = parser.remaining(); if (remaining.substr(0, 4) === 'true') { parser.pos += 4; return { t: BOOLEAN_LITERAL, v: 'true' }; } if (remaining.substr(0, 5) === 'false') { parser.pos += 5; return { t: BOOLEAN_LITERAL, v: 'false' }; } return null; } // Match one or more characters until: ", ', \, or EOL/EOF. // EOL/EOF is written as (?!.) (meaning there's no non-newline char next). var stringMiddlePattern = /^(?=.)[^"'\\]+?(?:(?!.)|(?=["'\\]))/; // Match one escape sequence, including the backslash. var escapeSequencePattern = /^\\(?:[`'"\\bfnrt]|0(?![0-9])|x[0-9a-fA-F]{2}|u[0-9a-fA-F]{4}|(?=.)[^ux0-9])/; // Match one ES5 line continuation (backslash + line terminator). var lineContinuationPattern = /^\\(?:\r\n|[\u000A\u000D\u2028\u2029])/; // Helper for defining getDoubleQuotedString and getSingleQuotedString. function makeQuotedStringMatcher(okQuote) { return function(parser) { var literal = '"'; var done = false; var next; while (!done) { next = parser.matchPattern(stringMiddlePattern) || parser.matchPattern(escapeSequencePattern) || parser.matchString(okQuote); if (next) { if (next === "\"") { literal += "\\\""; } else if (next === "\\'") { literal += "'"; } else { literal += next; } } else { next = parser.matchPattern(lineContinuationPattern); if (next) { // convert \(newline-like) into a \u escape, which is allowed in JSON literal += '\\u' + ('000' + next.charCodeAt(1).toString(16)).slice(-4); } else { done = true; } } } literal += '"'; // use JSON.parse to interpret escapes return JSON.parse(literal); }; } var singleMatcher = makeQuotedStringMatcher("\""); var doubleMatcher = makeQuotedStringMatcher("'"); function readStringLiteral(parser) { var start = parser.pos; var quote = parser.matchString("'") || parser.matchString("\""); if (quote) { var string = (quote === "'" ? singleMatcher : doubleMatcher)(parser); if (!parser.matchString(quote)) { parser.pos = start; return null; } return { t: STRING_LITERAL, v: string }; } return null; } // Match one or more characters until: ", ', or \ var stringMiddlePattern$1 = /^[^`"\\\$]+?(?:(?=[`"\\\$]))/; var escapes = /[\r\n\t\b\f]/g; function getString(literal) { return JSON.parse(("\"" + (literal.replace(escapes, escapeChar)) + "\"")); } function escapeChar(c) { switch (c) { case '\n': return '\\n'; case '\r': return '\\r'; case '\t': return '\\t'; case '\b': return '\\b'; case '\f': return '\\f'; } } function readTemplateStringLiteral(parser) { if (!parser.matchString('`')) { return null; } var literal = ''; var done = false; var next; var parts = []; while (!done) { next = parser.matchPattern(stringMiddlePattern$1) || parser.matchPattern(escapeSequencePattern) || parser.matchString('$') || parser.matchString('"'); if (next) { if (next === "\"") { literal += "\\\""; } else if (next === '\\`') { literal += '`'; } else if (next === '$') { if (parser.matchString('{')) { parts.push({ t: STRING_LITERAL, v: getString(literal) }); literal = ''; parser.sp(); var expr = readExpression(parser); if (!expr) { parser.error('Expected valid expression'); } parts.push({ t: BRACKETED, x: expr }); parser.sp(); if (!parser.matchString('}')) { parser.error("Expected closing '}' after interpolated expression"); } } else { literal += '$'; } } else { literal += next; } } else { next = parser.matchPattern(lineContinuationPattern); if (next) { // convert \(newline-like) into a \u escape, which is allowed in JSON literal += '\\u' + ('000' + next.charCodeAt(1).toString(16)).slice(-4); } else { done = true; } } } if (literal.length) { parts.push({ t: STRING_LITERAL, v: getString(literal) }); } if (!parser.matchString('`')) { parser.error("Expected closing '`'"); } if (parts.length === 1) { return parts[0]; } else { var result = parts.pop(); var part; while ((part = parts.pop())) { result = { t: INFIX_OPERATOR, s: '+', o: [part, result] }; } return { t: BRACKETED, x: result }; } } var name = /^[a-zA-Z_$][a-zA-Z_$0-9]*/; var spreadPattern = /^\s*\.{3}/; var legalReference = /^(?:[a-zA-Z$_0-9]|\\\.)+(?:(?:\.(?:[a-zA-Z$_0-9]|\\\.)+)|(?:\[[0-9]+\]))*/; var relaxedName = /^[a-zA-Z_$][-\/a-zA-Z_$0-9]*(?:\.(?:[a-zA-Z_$][-\/a-zA-Z_$0-9]*))*/; var identifier = /^[a-zA-Z_$][a-zA-Z_$0-9]*$/; // http://mathiasbynens.be/notes/javascript-properties // can be any name, string literal, or number literal function readKey(parser) { var token; if ((token = readStringLiteral(parser))) { return identifier.test(token.v) ? token.v : '"' + token.v.replace(/"/g, '\\"') + '"'; } if ((token = readNumberLiteral$1(parser))) { return token.v; } if ((token = parser.matchPattern(name))) { return token; } return null; } function readKeyValuePair(parser) { var spread; var start = parser.pos; // allow whitespace between '{' and key parser.sp(); var refKey = parser.nextChar() !== "'" && parser.nextChar() !== '"'; if (refKey) { spread = parser.matchPattern(spreadPattern); } var key = spread ? readExpression(parser) : readKey(parser); if (key === null) { parser.pos = start; return null; } // allow whitespace between key and ':' parser.sp(); // es2015 shorthand property if (refKey && (parser.nextChar() === ',' || parser.nextChar() === '}')) { if (!spread && !name.test(key)) { parser.error(("Expected a valid reference, but found '" + key + "' instead.")); } var pair = { t: KEY_VALUE_PAIR, k: key, v: { t: REFERENCE, n: key } }; if (spread) { pair.p = true; } return pair; } // next character must be ':' if (!parser.matchString(':')) { parser.pos = start; return null; } // allow whitespace between ':' and value parser.sp(); // next expression must be a, well... expression var value = readExpression(parser); if (value === null) { parser.pos = start; return null; } return { t: KEY_VALUE_PAIR, k: key, v: value }; } function readKeyValuePairs(parser) { var start = parser.pos; var pair = readKeyValuePair(parser); if (pair === null) { return null; } var pairs = [pair]; if (parser.matchString(',')) { var keyValuePairs = readKeyValuePairs(parser); if (!keyValuePairs) { parser.pos = start; return null; } return pairs.concat(keyValuePairs); } return pairs; } function readObjectLiteral(parser) { var start = parser.pos; // allow whitespace parser.sp(); if (!parser.matchString('{')) { parser.pos = start; return null; } var keyValuePairs = readKeyValuePairs(parser); // allow whitespace between final value and '}' parser.sp(); if (!parser.matchString('}')) { parser.pos = start; return null; } return { t: OBJECT_LITERAL, m: keyValuePairs }; } function readArrayLiteral(parser) { var start = parser.pos; // allow whitespace before '[' parser.sp(); if (!parser.matchString('[')) { parser.pos = start; return null; } var expressionList = readExpressionList(parser, true); if (!parser.matchString(']')) { parser.pos = start; return null; } return { t: ARRAY_LITERAL, m: expressionList }; } function readLiteral(parser) { return ( readNumberLiteral$1(parser) || readBooleanLiteral(parser) || readStringLiteral(parser) || readTemplateStringLiteral(parser) || readObjectLiteral(parser) || readArrayLiteral(parser) || readNumberLiteral(parser) ); } // if a reference is a browser global, we don't deference it later, so it needs special treatment var globals = /^(?:Array|console|Date|RegExp|decodeURIComponent|decodeURI|encodeURIComponent|encodeURI|isFinite|isNaN|parseFloat|parseInt|JSON|Math|NaN|undefined|null|Object|Number|String|Boolean)\b/; // keywords are not valid references, with the exception of `this` var keywords = /^(?:break|case|catch|continue|debugger|default|delete|do|else|finally|for|function|if|in|instanceof|new|return|switch|throw|try|typeof|var|void|while|with)$/; var prefixPattern = /^(?:\@\.|\@|~\/|(?:\^\^\/(?:\^\^\/)*(?:\.\.\/)*)|(?:\.\.\/)+|\.\/(?:\.\.\/)*|\.)/; var specials = /^(key|index|keypath|rootpath|this|global|shared|context|event|node|local|style|helpers|last|macro)/; function readReference(parser) { var prefix, name$$1, global, reference, lastDotIndex; var startPos = parser.pos; prefix = parser.matchPattern(prefixPattern) || ''; name$$1 = (!prefix && parser.relaxedNames && parser.matchPattern(relaxedName)) || parser.matchPattern(legalReference); var actual = prefix.length + ((name$$1 && name$$1.length) || 0); if (prefix === '@.') { prefix = '@'; if (name$$1) { name$$1 = 'this.' + name$$1; } else { name$$1 = 'this'; } } if (!name$$1 && prefix) { name$$1 = prefix; prefix = ''; } if (!name$$1) { return null; } if (prefix === '@') { if (!specials.test(name$$1)) { parser.error(("Unrecognized special reference @" + name$$1)); } else if ((!name$$1.indexOf('event') || !name$$1.indexOf('node')) && !parser.inEvent) { parser.error("@event and @node are only valid references within an event directive"); } else if (~name$$1.indexOf('context')) { parser.pos = parser.pos - (name$$1.length - 7); return { t: BRACKETED, x: { t: REFERENCE, n: '@context' } }; } } // bug out if it's a keyword (exception for ancestor/restricted refs - see https://github.com/ractivejs/ractive/issues/1497) if (!prefix && !parser.relaxedNames && keywords.test(name$$1)) { parser.pos = startPos; return null; } // if this is a browser global, stop here if (!prefix && globals.test(name$$1)) { global = globals.exec(name$$1)[0]; parser.pos = startPos + global.length; return { t: GLOBAL, v: global }; } reference = (prefix || '') + normalise(name$$1); if (parser.matchString('(')) { // if this is a method invocation (as opposed to a function) we need // to strip the method name from the reference combo, else the context // will be wrong // but only if the reference was actually a member and not a refinement lastDotIndex = reference.lastIndexOf('.'); if (lastDotIndex !== -1 && name$$1[name$$1.length - 1] !== ']') { if (lastDotIndex === 0) { reference = '.'; parser.pos = startPos; } else { var refLength = reference.length; reference = reference.substr(0, lastDotIndex); parser.pos = startPos + (actual - (refLength - lastDotIndex)); } } else { parser.pos -= 1; } } return { t: REFERENCE, n: reference.replace(/^this\./, './').replace(/^this$/, '.') }; } function readBracketedExpression(parser) { if (!parser.matchString('(')) { return null; } parser.sp(); var expr = readExpression(parser); if (!expr) { parser.error(expectedExpression); } parser.sp(); if (!parser.matchString(')')) { parser.error(expectedParen); } return { t: BRACKETED, x: expr }; } function readPrimary(parser) { return readLiteral(parser) || readReference(parser) || readBracketedExpression(parser); } function readRefinement(parser) { // some things call for strict refinement (partial names), meaning no space between reference and refinement if (!parser.strictRefinement) { parser.sp(); } // "." name if (parser.matchString('.')) { parser.sp(); var name$$1 = parser.matchPattern(name); if (name$$1) { return { t: REFINEMENT, n: name$$1 }; } parser.error('Expected a property name'); } // "[" expression "]" if (parser.matchString('[')) { parser.sp(); var expr = readExpression(parser); if (!expr) { parser.error(expectedExpression); } parser.sp(); if (!parser.matchString(']')) { parser.error("Expected ']'"); } return { t: REFINEMENT, x: expr }; } return null; } function readMemberOrInvocation(parser) { var expression = readPrimary(parser); if (!expression) { return null; } while (expression) { var refinement = readRefinement(parser); if (refinement) { expression = { t: MEMBER, x: expression, r: refinement }; } else if (parser.matchString('(')) { parser.sp(); var expressionList = readExpressionList(parser, true); parser.sp(); if (!parser.matchString(')')) { parser.error(expectedParen); } expression = { t: INVOCATION, x: expression }; if (expressionList) { expression.o = expressionList; } } else { break; } } return expression; } var readTypeOf; var makePrefixSequenceMatcher = function(symbol, fallthrough) { return function(parser) { var expression; if ((expression = fallthrough(parser))) { return expression; } if (!parser.matchString(symbol)) { return null; } parser.sp(); expression = readExpression(parser); if (!expression) { parser.error(expectedExpression); } return { s: symbol, o: expression, t: PREFIX_OPERATOR }; }; }; // create all prefix sequence matchers, return readTypeOf (function() { var i, len, matcher, fallthrough; var prefixOperators = '! ~ + - typeof'.split(' '); fallthrough = readMemberOrInvocation; for (i = 0, len = prefixOperators.length; i < len; i += 1) { matcher = makePrefixSequenceMatcher(prefixOperators[i], fallthrough); fallthrough = matcher; } // typeof operator is higher precedence than multiplication, so provides the // fallthrough for the multiplication sequence matcher we're about to create // (we're skipping void and delete) readTypeOf = fallthrough; })(); var readTypeof = readTypeOf; var readLogicalOr; var makeInfixSequenceMatcher = function(symbol, fallthrough) { return function(parser) { // > and / have to be quoted if (parser.inUnquotedAttribute && (symbol === '>' || symbol === '/')) { return fallthrough(parser); } var start, left, right; left = fallthrough(parser); if (!left) { return null; } // Loop to handle left-recursion in a case like `a * b * c` and produce // left association, i.e. `(a * b) * c`. The matcher can't call itself // to parse `left` because that would be infinite regress. while (true) { start = parser.pos; parser.sp(); if (!parser.matchString(symbol)) { parser.pos = start; return left; } // special case - in operator must not be followed by [a-zA-Z_$0-9] if (symbol === 'in' && /[a-zA-Z_$0-9]/.test(parser.remaining().charAt(0))) { parser.pos = start; return left; } parser.sp(); // right operand must also consist of only higher-precedence operators right = fallthrough(parser); if (!right) { parser.pos = start; return left; } left = { t: INFIX_OPERATOR, s: symbol, o: [left, right] }; // Loop back around. If we don't see another occurrence of the symbol, // we'll return left. } }; }; // create all infix sequence matchers, and return readLogicalOr (function() { var i, len, matcher, fallthrough; // All the infix operators on order of precedence (source: https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Operators/Operator_Precedence) // Each sequence matcher will initially fall through to its higher precedence // neighbour, and only attempt to match if one of the higher precedence operators // (or, ultimately, a literal, reference, or bracketed expression) already matched var infixOperators = '* / % + - << >> >>> < <= > >= in instanceof == != === !== & ^ | && ||'.split( ' ' ); // A typeof operator is higher precedence than multiplication fallthrough = readTypeof; for (i = 0, len = infixOperators.length; i < len; i += 1) { matcher = makeInfixSequenceMatcher(infixOperators[i], fallthrough); fallthrough = matcher; } // Logical OR is the fallthrough for the conditional matcher readLogicalOr = fallthrough; })(); var readLogicalOr$1 = readLogicalOr; // The conditional operator is the lowest precedence operator, so we start here function getConditional(parser) { var expression = readLogicalOr$1(parser); if (!expression) { return null; } var start = parser.pos; parser.sp(); if (!parser.matchString('?')) { parser.pos = start; return expression; } parser.sp(); var ifTrue = readExpression(parser); if (!ifTrue) { parser.error(expectedExpression); } parser.sp(); if (!parser.matchString(':')) { parser.error('Expected ":"'); } parser.sp(); var ifFalse = readExpression(parser); if (!ifFalse) { parser.error(expectedExpression); } return { t: CONDITIONAL, o: [expression, ifTrue, ifFalse] }; } function readExpression(parser) { // if eval is false, no expressions if (parser.allowExpressions === false) { var ref = readReference(parser); parser.sp(); return ref; } // The conditional operator is the lowest precedence operator (except yield, // assignment operators, and commas, none of which are supported), so we // start there. If it doesn't match, it 'falls through' to progressively // higher precedence operators, until it eventually matches (or fails to // match) a 'primary' - a literal or a reference. This way, the abstract syntax // tree has everything in its proper place, i.e. 2 + 3 * 4 === 14, not 20. return getConditional(parser); } function readExpressionList(parser, spread) { var isSpread; var expressions = []; var pos = parser.pos; do { parser.sp(); if (spread) { isSpread = parser.matchPattern(spreadPattern); } var expr = readExpression(parser); if (expr === null && expressions.length) { parser.error(expectedExpression); } else if (expr === null) { parser.pos = pos; return null; } if (isSpread) { expr.p = true; } expressions.push(expr); parser.sp(); } while (parser.matchString(',')); return expressions; } function readExpressionOrReference(parser, expectedFollowers) { var start = parser.pos; var expression = readExpression(parser); if (!expression) { // valid reference but invalid expression e.g. `{{new}}`? var ref = parser.matchPattern(/^(\w+)/); if (ref) { return { t: REFERENCE, n: ref }; } return null; } for (var i = 0; i < expectedFollowers.length; i += 1) { if (parser.remaining().substr(0, expectedFollowers[i].length) === expectedFollowers[i]) { return expression; } } parser.pos = start; return readReference(parser); } function flattenExpression(expression) { var refs; var count = 0; extractRefs(expression, (refs = [])); var stringified = stringify(expression); return { r: refs, s: getVars(stringified) }; function getVars(expr) { var vars = []; for (var i = count - 1; i >= 0; i--) { vars.push(("x$" + i)); } return vars.length ? ("(function(){var " + (vars.join(',')) + ";return(" + expr + ");})()") : expr; } function stringify(node) { if (isString(node)) { return node; } switch (node.t) { case BOOLEAN_LITERAL: case GLOBAL: case NUMBER_LITERAL: case REGEXP_LITERAL: return node.v; case STRING_LITERAL: return JSON.stringify(String(node.v)); case ARRAY_LITERAL: if (node.m && hasSpread(node.m)) { return ("[].concat(" + (makeSpread(node.m, '[', ']', stringify)) + ")"); } else { return '[' + (node.m ? node.m.map(stringify).join(',') : '') + ']'; } case OBJECT_LITERAL: if (node.m && hasSpread(node.m)) { return ("Object.assign({}," + (makeSpread(node.m, '{', '}', stringifyPair)) + ")"); } else { return '{' + (node.m ? node.m.map(function (n) { return ((n.k) + ":" + (stringify(n.v))); }).join(',') : '') + '}'; } case PREFIX_OPERATOR: return (node.s === 'typeof' ? 'typeof ' : node.s) + stringify(node.o); case INFIX_OPERATOR: return ( stringify(node.o[0]) + (node.s.substr(0, 2) === 'in' ? ' ' + node.s + ' ' : node.s) + stringify(node.o[1]) ); case INVOCATION: if (node.o && hasSpread(node.o)) { var id = count++; return ("(x$" + id + "=" + (stringify(node.x)) + ").apply(x$" + id + "," + (stringify({ t: ARRAY_LITERAL, m: node.o })) + ")"); } else { return stringify(node.x) + '(' + (node.o ? node.o.map(stringify).join(',') : '') + ')'; } case BRACKETED: return '(' + stringify(node.x) + ')'; case MEMBER: return stringify(node.x) + stringify(node.r); case REFINEMENT: return node.n ? '.' + node.n : '[' + stringify(node.x) + ']'; case CONDITIONAL: return stringify(node.o[0]) + '?' + stringify(node.o[1]) + ':' + stringify(node.o[2]); case REFERENCE: return '_' + refs.indexOf(node.n); default: throw new Error('Expected legal JavaScript'); } } function stringifyPair(node) { return node.p ? stringify(node.k) : ((node.k) + ":" + (stringify(node.v))); } function makeSpread(list, open, close, fn) { var out = list.reduce( function (a, c) { if (c.p) { a.str += "" + (a.open ? close + ',' : a.str.length ? ',' : '') + (fn(c)); } else { a.str += "" + (!a.str.length ? open : !a.open ? ',' + open : ',') + (fn(c)); } a.open = !c.p; return a; }, { open: false, str: '' } ); if (out.open) { out.str += close; } return out.str; } } function hasSpread(list) { for (var i = 0; i < list.length; i++) { if (list[i].p) { return true; } } return false; } // TODO maybe refactor this? function extractRefs(node, refs) { if (node.t === REFERENCE && isString(node.n)) { if (!~refs.indexOf(node.n)) { refs.unshift(node.n); } } var list = node.o || node.m; if (list) { if (isObject(list)) { extractRefs(list, refs); } else { var i = list.length; while (i--) { extractRefs(list[i], refs); } } } if (node.k && node.t === KEY_VALUE_PAIR && !isString(node.k)) { extractRefs(node.k, refs); } if (node.x) { extractRefs(node.x, refs); } if (node.r) { extractRefs(node.r, refs); } if (node.v) { extractRefs(node.v, refs); } } function refineExpression(expression, mustache) { var referenceExpression; if (expression) { while (expression.t === BRACKETED && expression.x) { expression = expression.x; } if (expression.t === REFERENCE) { var n = expression.n; if (!~n.indexOf('@context')) { mustache.r = expression.n; } else { mustache.x = flattenExpression(expression); } } else { if ((referenceExpression = getReferenceExpression(expression))) { mustache.rx = referenceExpression; } else { mustache.x = flattenExpression(expression); } } return mustache; } } // TODO refactor this! it's bewildering function getReferenceExpression(expression) { var members = []; var refinement; while (expression.t === MEMBER && expression.r.t === REFINEMENT) { refinement = expression.r; if (refinement.x) { if (refinement.x.t === REFERENCE) { members.unshift(refinement.x); } else { members.unshift(flattenExpression(refinement.x)); } } else { members.unshift(refinement.n); } expression = expression.x; } if (expression.t !== REFERENCE) { return null; } return { r: expression.n, m: members }; } var attributeNamePattern = /^[^\s"'>\/=(]+/; var onPattern = /^on/; var eventPattern = /^on-([a-zA-Z\*\.$_]((?:[a-zA-Z\*\.$_0-9\-]|\\-)+))$/; var reservedEventNames = /^(?:change|reset|teardown|update|construct|config|init|render|complete|unrender|detach|insert|destruct|attachchild|detachchild)$/; var decoratorPattern = /^as-([a-z-A-Z][-a-zA-Z_0-9]*)$/; var transitionPattern = /^([a-zA-Z](?:(?!-in-out)[-a-zA-Z_0-9])*)-(in|out|in-out)$/; var boundPattern = /^((bind|class)-(([-a-zA-Z0-9_])+))$/; var directives = { lazy: { t: BINDING_FLAG, v: 'l' }, twoway: { t: BINDING_FLAG, v: 't' }, 'no-delegation': { t: DELEGATE_FLAG } }; var unquotedAttributeValueTextPattern = /^[^\s"'=<>\/`]+/; var proxyEvent = /^[^\s"'=<>@\[\]()]*/; var whitespace = /^\s+/; var slashes = /\\/g; function splitEvent(str) { var result = []; var s = 0; for (var i = 0; i < str.length; i++) { if (str[i] === '-' && str[i - 1] !== '\\') { result.push(str.substring(s, i).replace(slashes, '')); s = i + 1; } } result.push(str.substring(s).replace(slashes, '')); return result; } function readAttribute(parser) { var name, i, nearest, idx; parser.sp(); name = parser.matchPattern(attributeNamePattern); if (!name) { return null; } // check for accidental delimiter consumption e.g. <tag bool{{>attrs}} /> nearest = name.length; for (i = 0; i < parser.tags.length; i++) { if (~(idx = name.indexOf(parser.tags[i].open))) { if (idx < nearest) { nearest = idx; } } } if (nearest < name.length) { parser.pos -= name.length - nearest; name = name.substr(0, nearest); if (!name) { return null; } } return { n: name }; } function readAttributeValue(parser) { var start = parser.pos; // next character must be `=`, `/`, `>` or whitespace if (!/[=\/>\s]/.test(parser.nextChar())) { parser.error('Expected `=`, `/`, `>` or whitespace'); } parser.sp(); if (!parser.matchString('=')) { parser.pos = start; return null; } parser.sp(); var valueStart = parser.pos; var startDepth = parser.sectionDepth; var value = readQuotedAttributeValue(parser, "'") || readQuotedAttributeValue(parser, "\"") || readUnquotedAttributeValue(parser); if (value === null) { parser.error('Expected valid attribute value'); } if (parser.sectionDepth !== startDepth) { parser.pos = valueStart; parser.error( 'An attribute value must contain as many opening section tags as closing section tags' ); } if (!value.length) { return ''; } if (value.length === 1 && isString(value[0])) { return decodeCharacterReferences(value[0]); } return value; } function readUnquotedAttributeValueToken(parser) { var text, index; var start = parser.pos; text = parser.matchPattern(unquotedAttributeValueTextPattern); if (!text) { return null; } var haystack = text; var needles = parser.tags.map(function (t) { return t.open; }); // TODO refactor... we do this in readText.js as well if ((index = getLowestIndex(haystack, needles)) !== -1) { text = text.substr(0, index); parser.pos = start + text.length; } return text; } function readUnquotedAttributeValue(parser) { parser.inAttribute = true; var tokens = []; var token = readMustache(parser) || readUnquotedAttributeValueToken(parser); while (token) { tokens.push(token); token = readMustache(parser) || readUnquotedAttributeValueToken(parser); } if (!tokens.length) { return null; } parser.inAttribute = false; return tokens; } function readQuotedAttributeValue(parser, quoteMark) { var start = parser.pos; if (!parser.matchString(quoteMark)) { return null; } parser.inAttribute = quoteMark; var tokens = []; var token = readMustache(parser) || readQuotedStringToken(parser, quoteMark); while (token !== null) { tokens.push(token); token = readMustache(parser) || readQuotedStringToken(parser, quoteMark); } if (!parser.matchString(quoteMark)) { parser.pos = start; return null; } parser.inAttribute = false; return tokens; } function readQuotedStringToken(parser, quoteMark) { var haystack = parser.remaining(); var needles = parser.tags.map(function (t) { return t.open; }); // TODO refactor... we do this in readText.js as well needles.push(quoteMark); var index = getLowestIndex(haystack, needles); if (index === -1) { parser.error('Quoted attribute value must have a closing quote'); } if (!index) { return null; } parser.pos += index; return haystack.substr(0, index); } function readAttributeOrDirective(parser) { var match, directive; var attribute = readAttribute(parser, false); if (!attribute) { return null; } // lazy, twoway if ((directive = directives[attribute.n])) { attribute.t = directive.t; if (directive.v) { attribute.v = directive.v; } delete attribute.n; // no name necessary parser.sp(); if (parser.nextChar() === '=') { attribute.f = readAttributeValue(parser); } } else if ((match = decoratorPattern.exec(attribute.n))) { // decorators attribute.n = match[1]; attribute.t = DECORATOR; readArguments(parser, attribute); } else if ((match = transitionPattern.exec(attribute.n))) { // transitions attribute.n = match[1]; attribute.t = TRANSITION; readArguments(parser, attribute); attribute.v = match[2] === 'in-out' ? 't0' : match[2] === 'in' ? 't1' : 't2'; } else if ((match = eventPattern.exec(attribute.n))) { // on-click etc attribute.n = splitEvent(match[1]); attribute.t = EVENT; if (parser.matchString('(')) { attribute.a = flattenExpression({ t: ARRAY_LITERAL, m: readExpressionList(parser) }); if (!parser.matchString(')')) { parser.error("Expected closing ')'"); } } parser.inEvent = true; // check for a proxy event if (!readProxyEvent(parser, attribute)) { // otherwise, it's an expression readArguments(parser, attribute, true); } else if (reservedEventNames.test(attribute.f)) { parser.pos -= attribute.f.length; parser.error( 'Cannot use reserved event names (change, reset, teardown, update, construct, config, init, render, unrender, complete, detach, insert, destruct, attachchild, detachchild)' ); } parser.inEvent = false; } else if ((match = boundPattern.exec(attribute.n))) { // bound directives var bind = match[2] === 'bind'; attribute.n = bind ? match[3] : match[1]; attribute.t = ATTRIBUTE; readArguments(parser, attribute, false, true); if (!attribute.f && bind) { attribute.f = [{ t: INTERPOLATOR, r: match[3] }]; } } else { parser.sp(); var value = parser.nextChar() === '=' ? readAttributeValue(parser) : null; attribute.f = value != null ? value : attribute.f; if (parser.sanitizeEventAttributes && onPattern.test(attribute.n)) { return { exclude: true }; } else { attribute.f = attribute.f || (attribute.f === '' ? '' : 0); attribute.t = ATTRIBUTE; } } return attribute; } function readProxyEvent(parser, attribute) { var start = parser.pos; if (!parser.matchString('=')) { parser.error("Missing required directive arguments"); } var quote = parser.matchString("'") || parser.matchString("\""); parser.sp(); var proxy = parser.matchPattern(proxyEvent); if (proxy !== undefined) { if (quote) { parser.sp(); if (!parser.matchString(quote)) { parser.pos = start; } else { return (attribute.f = proxy) || true; } } else if (!parser.matchPattern(whitespace)) { parser.pos = start; } else { return (attribute.f = proxy) || true; } } else { parser.pos = start; } } function readArguments(parser, attribute, required, single) { if ( required === void 0 ) required = false; if ( single === void 0 ) single = false; parser.sp(); if (!parser.matchString('=')) { if (required) { parser.error("Missing required directive arguments"); } return; } parser.sp(); var quote = parser.matchString('"') || parser.matchString("'"); var spread = parser.spreadArgs; parser.spreadArgs = true; parser.inUnquotedAttribute = !quote; var expr = single ? readExpressionOrReference(parser, [quote || ' ', '/', '>']) : { m: readExpressionList(parser), t: ARRAY_LITERAL }; parser.inUnquotedAttribute = false; parser.spreadArgs = spread; if (quote) { parser.sp(); if (parser.matchString(quote) !== quote) { parser.error(("Expected matching quote '" + quote + "'")); } } if (single) { var interpolator = { t: INTERPOLATOR }; refineExpression(expr, interpolator); attribute.f = [interpolator]; } else { attribute.f = flattenExpression(expr); } } var delimiterChangeToken = { t: DELIMCHANGE, exclude: true }; function readMustache(parser) { var mustache, i; // If we're inside a <script> or <style> tag, and we're not // interpolating, bug out if (parser.interpolate[parser.inside] === false) { return null; } for (i = 0; i < parser.tags.length; i += 1) { if ((mustache = readMustacheOfType(parser, parser.tags[i]))) { return mustache; } } if (parser.inTag && !parser.inAttribute) { mustache = readAttributeOrDirective(parser); if (mustache) { parser.sp(); return mustache; } } } function readMustacheOfType(parser, tag) { var mustache, reader, i; var start = parser.pos; if (parser.matchString('\\' + tag.open)) { if (start === 0 || parser.str[start - 1] !== '\\') { return tag.open; } } else if (!parser.matchString(tag.open)) { return null; } // delimiter change? if ((mustache = readDelimiterChange(parser))) { // find closing delimiter or abort... if (!parser.matchString(tag.close)) { return null; } // ...then make the switch tag.open = mustache[0]; tag.close = mustache[1]; parser.sortMustacheTags(); return delimiterChangeToken; } parser.sp(); // illegal section closer if (parser.matchString('/')) { parser.pos -= 1; var rewind = parser.pos; if (!readNumberLiteral(parser)) { parser.pos = rewind - tag.close.length; if (parser.inAttribute) { parser.pos = start; return null; } else { parser.error("Attempted to close a section that wasn't open"); } } else { parser.pos = rewind; } } for (i = 0; i < tag.readers.length; i += 1) { reader = tag.readers[i]; if ((mustache = reader(parser, tag))) { if (tag.isStatic) { mustache.s = 1; } if (parser.includeLinePositions) { mustache.q = parser.getLinePos(start); } return mustache; } } parser.pos = start; return null; } function readTriple(parser, tag) { var expression = readExpression(parser); if (!expression) { return null; } if (!parser.matchString(tag.close)) { parser.error(("Expected closing delimiter '" + (tag.close) + "'")); } var triple = { t: TRIPLE }; refineExpression(expression, triple); // TODO handle this differently - it's mysterious return triple; } function readUnescaped(parser, tag) { if (!parser.matchString('&')) { return null; } parser.sp(); var expression = readExpression(parser); if (!expression) { return null; } if (!parser.matchString(tag.close)) { parser.error(("Expected closing delimiter '" + (tag.close) + "'")); } var triple = { t: TRIPLE }; refineExpression(expression, triple); // TODO handle this differently - it's mysterious return triple; } var legalAlias = /^(?:[a-zA-Z$_0-9]|\\\.)+(?:(?:(?:[a-zA-Z$_0-9]|\\\.)+)|(?:\[[0-9]+\]))*/; var asRE = /^as/i; function readAliases(parser) { var aliases = []; var alias; var start = parser.pos; parser.sp(); alias = readAlias(parser); if (alias) { alias.x = refineExpression(alias.x, {}); aliases.push(alias); parser.sp(); while (parser.matchString(',')) { alias = readAlias(parser); if (!alias) { parser.error('Expected another alias.'); } alias.x = refineExpression(alias.x, {}); aliases.push(alias); parser.sp(); } return aliases; } parser.pos = start; return null; } function readAlias(parser) { var start = parser.pos; parser.sp(); var expr = readExpression(parser, []); if (!expr) { parser.pos = start; return null; } parser.sp(); parser.matchPattern(asRE); parser.sp(); var alias = parser.matchPattern(legalAlias); if (!alias) { parser.pos = start; return null; } return { n: alias, x: expr }; } function readPartial(parser, tag) { var type = parser.matchString('>') || parser.matchString('yield'); var partial = { t: type === '>' ? PARTIAL : YIELDER }; var aliases; if (!type) { return null; } parser.sp(); if (type === '>' || !(aliases = parser.matchString('with'))) { // Partial names can include hyphens, so we can't use readExpression // blindly. Instead, we use the `relaxedNames` flag to indicate that // `foo-bar` should be read as a single name, rather than 'subtract // bar from foo' parser.relaxedNames = parser.strictRefinement = true; var expression = readExpression(parser); parser.relaxedNames = parser.strictRefinement = false; if (!expression && type === '>') { return null; } if (expression) { refineExpression(expression, partial); // TODO... parser.sp(); if (type !== '>') { aliases = parser.matchString('with'); } } } parser.sp(); // check for alias context e.g. `{{>foo bar as bat, bip as bop}}` if (aliases || type === '>') { aliases = readAliases(parser); if (aliases && aliases.length) { partial.z = aliases; } else { // otherwise check for literal context e.g. `{{>foo bar}}` then // turn it into `{{#with bar}}{{>foo}}{{/with}}` var context = readExpression(parser); if (context) { partial.c = {}; refineExpression(context, partial.c); } // allow aliases after context if (parser.matchString(',')) { aliases = readAliases(parser); if (aliases && aliases.length) { partial.z = aliases; } } } if (type !== '>' && (!partial.c && !partial.z)) { // {{yield with}} requires some aliases parser.error("Expected a context or one or more aliases"); } } parser.sp(); if (!parser.matchString(tag.close)) { parser.error(("Expected closing delimiter '" + (tag.close) + "'")); } return partial; } function readComment(parser, tag) { if (!parser.matchString('!')) { return null; } var index = parser.remaining().indexOf(tag.close); if (index !== -1) { parser.pos += index + tag.close.length; return { t: COMMENT }; } } function readInterpolator(parser, tag) { var expression, err; var start = parser.pos; // TODO would be good for perf if we could do away with the try-catch try { expression = readExpressionOrReference(parser, [tag.close]); } catch (e) { err = e; } if (!expression) { if (parser.str.charAt(start) === '!') { // special case - comment parser.pos = start; return null; } if (err) { throw err; } } if (!parser.matchString(tag.close)) { parser.error(("Expected closing delimiter '" + (tag.close) + "' after reference")); if (!expression) { // special case - comment if (parser.nextChar() === '!') { return null; } parser.error("Expected expression or legal reference"); } } var interpolator = { t: INTERPOLATOR }; refineExpression(expression, interpolator); // TODO handle this differently - it's mysterious return interpolator; } function readClosing(parser, tag) { var start = parser.pos; if (!parser.matchString(tag.open)) { return null; } parser.sp(); if (!parser.matchString('/')) { parser.pos = start; return null; } parser.sp(); var remaining = parser.remaining(); var index = remaining.indexOf(tag.close); if (index !== -1) { var closing = { t: CLOSING, r: remaining.substr(0, index).split(' ')[0] }; parser.pos += index; if (!parser.matchString(tag.close)) { parser.error(("Expected closing delimiter '" + (tag.close) + "'")); } return closing; } parser.pos = start; return null; } var patterns = { else: /^\s*else\s*/, elseif: /^\s*elseif\s+/, then: /^\s*then\s*/, catch: /^\s*catch\s*/ }; var types = { else: ELSE, elseif: ELSEIF, then: THEN, catch: CATCH }; function readInlineBlock(parser, tag, type) { var start = parser.pos; if (!parser.matchString(tag.open)) { return null; } if (!parser.matchPattern(patterns[type])) { parser.pos = start; return null; } var res = { t: types[type] }; if (type === 'elseif') { res.x = readExpression(parser); } else if (type === 'catch' || type === 'then') { var nm = parser.matchPattern(name); if (nm) { res.n = nm; } } if (!parser.matchString(tag.close)) { parser.error(("Expected closing delimiter '" + (tag.close) + "'")); } return res; } var handlebarsBlockCodes = { each: SECTION_EACH, if: SECTION_IF, with: SECTION_IF_WITH, unless: SECTION_UNLESS }; var indexRefPattern = /^\s*:\s*([a-zA-Z_$][a-zA-Z_$0-9]*)/; var keyIndexRefPattern = /^\s*,\s*([a-zA-Z_$][a-zA-Z_$0-9]*)/; var handlebarsBlockPattern = new RegExp('^(' + keys(handlebarsBlockCodes).join('|') + ')\\b'); function readSection(parser, tag) { var expression, section, child, children, hasElse, block, unlessBlock, closed, i, expectedClose, hasThen, hasCatch, inlineThen; var aliasOnly = false; var start = parser.pos; if (parser.matchString('^')) { // watch out for parent context refs - {{^^/^^/foo}} if (parser.matchString('^/')) { parser.pos = start; return null; } section = { t: SECTION, f: [], n: SECTION_UNLESS }; } else if (parser.matchString('#')) { section = { t: SECTION, f: [] }; if (parser.matchString('partial')) { parser.pos = start - parser.standardDelimiters[0].length; parser.error( 'Partial definitions can only be at the top level of the template, or immediately inside components' ); } if ((block = parser.matchString('await'))) { expectedClose = block; section.t = AWAIT; } else if ((block = parser.matchPattern(handlebarsBlockPattern))) { expectedClose = block; section.n = handlebarsBlockCodes[block]; } } else { return null; } parser.sp(); if (block === 'with') { var aliases = readAliases(parser); if (aliases) { aliasOnly = true; section.z = aliases; section.t = ALIAS; } } else if (block === 'each') { var alias = readAlias(parser); if (alias) { section.z = [{ n: alias.n, x: { r: '.' } }]; expression = alias.x; } } if (!aliasOnly) { if (!expression) { expression = readExpression(parser); } if (!expression) { parser.error('Expected expression'); } // extra each aliases if (block === 'each' && parser.matchString(',')) { var aliases$1 = readAliases(parser); if (aliases$1) { if (section.z) { aliases$1.unshift(section.z[0]); } section.z = aliases$1; } } // optional index and key references if ((block === 'each' || !block) && (i = parser.matchPattern(indexRefPattern))) { var extra; if ((extra = parser.matchPattern(keyIndexRefPattern))) { section.i = i + ',' + extra; } else { section.i = i; } } else if (block === 'await' && parser.matchString('then')) { parser.sp(); hasThen = true; inlineThen = parser.matchPattern(name); if (!inlineThen) { inlineThen = true; } } if (!block && expression.n) { expectedClose = expression.n; } } parser.sp(); if (!parser.matchString(tag.close)) { parser.error(("Expected closing delimiter '" + (tag.close) + "'")); } parser.sectionDepth += 1; children = section.f; var pos; do { pos = parser.pos; if ((child = readClosing(parser, tag))) { if (expectedClose && child.r !== expectedClose) { if (!block) { if (child.r) { parser.warn( ("Expected " + (tag.open) + "/" + expectedClose + (tag.close) + " but found " + (tag.open) + "/" + (child.r) + (tag.close)) ); } } else { parser.pos = pos; parser.error(("Expected " + (tag.open) + "/" + expectedClose + (tag.close))); } } parser.sectionDepth -= 1; closed = true; } else if ( !aliasOnly && ((child = readInlineBlock(parser, tag, 'elseif')) || (child = readInlineBlock(parser, tag, 'else')) || (block === 'await' && ((child = readInlineBlock(parser, tag, 'then')) || (child = readInlineBlock(parser, tag, 'catch'))))) ) { if (section.n === SECTION_UNLESS) { parser.error('{{else}} not allowed in {{#unless}}'); } if (hasElse) { if (child.t === ELSE) { parser.error('there can only be one {{else}} block, at the end of a section'); } else if (child.t === ELSEIF) { parser.error('illegal {{elseif...}} after {{else}}'); } } if (!unlessBlock && (inlineThen || !hasThen) && !hasCatch) { if (block === 'await') { var s = { f: children }; section.f = [s]; if (inlineThen) { s.t = THEN; inlineThen !== true && (s.n = inlineThen); } else { s.t = SECTION; } } else { unlessBlock = []; } } var mustache = { t: SECTION, f: (children = []) }; if (child.t === ELSE) { if (block === 'await') { section.f.push(mustache); mustache.t = ELSE; } else { mustache.n = SECTION_UNLESS; unlessBlock.push(mustache); } hasElse = true; } else if (child.t === ELSEIF) { mustache.n = SECTION_IF; refineExpression(child.x, mustache); unlessBlock.push(mustache); } else if (child.t === THEN) { if (hasElse) { parser.error('{{then}} block must appear before any {{else}} block'); } if (hasCatch) { parser.error('{{then}} block must appear before any {{catch}} block'); } if (hasThen) { parser.error('there can only be one {{then}} block per {{#await}}'); } mustache.t = THEN; hasThen = true; child.n && (mustache.n = child.n); section.f.push(mustache); } else if (child.t === CATCH) { if (hasElse) { parser.error('{{catch}} block must appear before any {{else}} block'); } if (hasCatch) { parser.error('there can only be one {{catch}} block per {{#await}}'); } mustache.t = CATCH; hasCatch = true; mustache.n = child.n; section.f.push(mustache); } } else { child = parser.read(READERS); if (!child) { break; } children.push(child); } } while (!closed); if (unlessBlock) { section.l = unlessBlock; } if (!aliasOnly) { refineExpression(expression, section); } if (block === 'await' && (inlineThen || !hasThen) && !hasCatch && !hasElse) { var s$1 = { f: section.f }; section.f = [s$1]; if (inlineThen) { s$1.t = THEN; inlineThen !== true && (s$1.n = inlineThen); } else { s$1.t = SECTION; } } // TODO if a section is empty it should be discarded. Don't do // that here though - we need to clean everything up first, as // it may contain removeable whitespace. As a temporary measure, // to pass the existing tests, remove empty `f` arrays if (!section.f.length) { delete section.f; } return section; } var OPEN_COMMENT = '<!--'; var CLOSE_COMMENT = '-->'; function readHtmlComment(parser) { var start = parser.pos; if (parser.textOnlyMode || !parser.matchString(OPEN_COMMENT)) { return null; } var remaining = parser.remaining(); var endIndex = remaining.indexOf(CLOSE_COMMENT); if (endIndex === -1) { parser.error("Illegal HTML - expected closing comment sequence ('-->')"); } var content = remaining.substr(0, endIndex); parser.pos += endIndex + 3; var comment = { t: COMMENT, c: content }; if (parser.includeLinePositions) { comment.q = parser.getLinePos(start); } return comment; } var leadingLinebreak = /^[ \t\f\r\n]*\r?\n/; var trailingLinebreak = /\r?\n[ \t\f\r\n]*$/; function stripStandalones(items) { var i, current, backOne, backTwo, lastSectionItem; for (i = 1; i < items.length; i += 1) { current = items[i]; backOne = items[i - 1]; backTwo = items[i - 2]; // if we're at the end of a [text][comment][text] sequence... if (isString(current) && isComment(backOne) && isString(backTwo)) { // ... and the comment is a standalone (i.e. line breaks either side)... if (trailingLinebreak.test(backTwo) && leadingLinebreak.test(current)) { // ... then we want to remove the whitespace after the first line break items[i - 2] = backTwo.replace(trailingLinebreak, '\n'); // and the leading line break of the second text token items[i] = current.replace(leadingLinebreak, ''); } } // if the current item is a section, and it is preceded by a linebreak, and // its first item is a linebreak... if (isSection(current) && isString(backOne)) { if ( trailingLinebreak.test(backOne) && isString(current.f[0]) && leadingLinebreak.test(current.f[0]) ) { items[i - 1] = backOne.replace(trailingLinebreak, '\n'); current.f[0] = current.f[0].replace(leadingLinebreak, ''); } } // if the last item was a section, and it is followed by a linebreak, and // its last item is a linebreak... if (isString(current) && isSection(backOne)) { lastSectionItem = lastItem(backOne.f); if ( isString(lastSectionItem) && trailingLinebreak.test(lastSectionItem) && leadingLinebreak.test(current) ) { backOne.f[backOne.f.length - 1] = lastSectionItem.replace(trailingLinebreak, '\n'); items[i] = current.replace(leadingLinebreak, ''); } } } return items; } function isComment(item) { return item.t === COMMENT || item.t === DELIMCHANGE; } function isSection(item) { return (item.t === SECTION || item.t === INVERTED) && item.f; } function trimWhitespace(items, leadingPattern, trailingPattern) { var item; if (leadingPattern) { item = items[0]; if (isString(item)) { item = item.replace(leadingPattern, ''); if (!item) { items.shift(); } else { items[0] = item; } } } if (trailingPattern) { item = lastItem(items); if (isString(item)) { item = item.replace(trailingPattern, ''); if (!item) { items.pop(); } else { items[items.length - 1] = item; } } } } var contiguousWhitespace = /[ \t\f\r\n]+/g; var leadingWhitespace$1 = /^[ \t\f\r\n]+/; var trailingWhitespace = /[ \t\f\r\n]+$/; var leadingNewLine = /^(?:\r\n|\r|\n)/; var trailingNewLine = /(?:\r\n|\r|\n)$/; function cleanup( items, stripComments, preserveWhitespace, removeLeadingWhitespace, removeTrailingWhitespace, whiteSpaceElements ) { if (isString(items)) { return; } var i, item, previousItem, nextItem, preserveWhitespaceInsideFragment, removeLeadingWhitespaceInsideFragment, removeTrailingWhitespaceInsideFragment; // First pass - remove standalones and comments etc stripStandalones(items); i = items.length; while (i--) { item = items[i]; // Remove delimiter changes, unsafe elements etc if (item.exclude) { items.splice(i, 1); } else if (stripComments && item.t === COMMENT) { // Remove comments, unless we want to keep them items.splice(i, 1); } } // If necessary, remove leading and trailing whitespace trimWhitespace( items, removeLeadingWhitespace ? leadingWhitespace$1 : null, removeTrailingWhitespace ? trailingWhitespace : null ); i = items.length; while (i--) { item = items[i]; removeLeadingWhitespaceInsideFragment = removeTrailingWhitespaceInsideFragment = false; // Recurse if (item.f) { var isPreserveWhitespaceElement = item.t === ELEMENT && (whiteSpaceElements[item.e.toLowerCase()] || whiteSpaceElements[item.e]); preserveWhitespaceInsideFragment = preserveWhitespace || isPreserveWhitespaceElement; if (!preserveWhitespace && isPreserveWhitespaceElement) { trimWhitespace(item.f, leadingNewLine, trailingNewLine); } if (!preserveWhitespaceInsideFragment) { previousItem = items[i - 1]; nextItem = items[i + 1]; // if the previous item was a text item with trailing whitespace, // remove leading whitespace inside the fragment if (!previousItem || (isString(previousItem) && trailingWhitespace.test(previousItem))) { removeLeadingWhitespaceInsideFragment = true; } // and vice versa if (!nextItem || (isString(nextItem) && leadingWhitespace$1.test(nextItem))) { removeTrailingWhitespaceInsideFragment = true; } } cleanup( item.f, stripComments, preserveWhitespaceInsideFragment, removeLeadingWhitespaceInsideFragment, removeTrailingWhitespaceInsideFragment, whiteSpaceElements ); } // Split if-else blocks into two (an if, and an unless) if (item.l) { cleanup( item.l, stripComments, preserveWhitespace, removeLeadingWhitespaceInsideFragment, removeTrailingWhitespaceInsideFragment, whiteSpaceElements ); item.l.forEach(function (s) { return (s.l = 1); }); item.l.unshift(i + 1, 0); items.splice.apply(items, item.l); delete item.l; // TODO would be nice if there was a way around this } // Clean up conditional attributes if (item.m) { cleanup( item.m, stripComments, preserveWhitespace, removeLeadingWhitespaceInsideFragment, removeTrailingWhitespaceInsideFragment, whiteSpaceElements ); if (item.m.length < 1) { delete item.m; } } } // final pass - fuse text nodes together i = items.length; while (i--) { if (isString(items[i])) { if (isString(items[i + 1])) { items[i] = items[i] + items[i + 1]; items.splice(i + 1, 1); } if (!preserveWhitespace) { items[i] = items[i].replace(contiguousWhitespace, ' '); } if (items[i] === '') { items.splice(i, 1); } } } } var closingTagPattern = /^([a-zA-Z]{1,}:?[a-zA-Z0-9\-]*)\s*\>/; function readClosingTag(parser) { var tag; var start = parser.pos; // are we looking at a closing tag? if (!parser.matchString('</')) { return null; } if ((tag = parser.matchPattern(closingTagPattern))) { if (parser.inside && tag !== parser.inside) { parser.pos = start; return null; } return { t: CLOSING_TAG, e: tag }; } // We have an illegal closing tag, report it parser.pos -= 2; parser.error('Illegal closing tag'); } function hyphenateCamel(camelCaseStr) { return camelCaseStr.replace(/([A-Z])/g, function (match, $1) { return '-' + $1.toLowerCase(); }); } var tagNamePattern = /^[a-zA-Z]{1,}:?[a-zA-Z0-9\-]*/; var anchorPattern = /^[a-zA-Z_$][-a-zA-Z0-9_$]*/; var validTagNameFollower = /^[\s\n\/>]/; var semiEnd = /;\s*$/; var exclude = { exclude: true }; // based on http://developers.whatwg.org/syntax.html#syntax-tag-omission var disallowedContents = { li: ['li'], dt: ['dt', 'dd'], dd: ['dt', 'dd'], p: 'address article aside blockquote div dl fieldset footer form h1 h2 h3 h4 h5 h6 header hgroup hr main menu nav ol p pre section table ul'.split( ' ' ), rt: ['rt', 'rp'], rp: ['rt', 'rp'], optgroup: ['optgroup'], option: ['option', 'optgroup'], thead: ['tbody', 'tfoot'], tbody: ['tbody', 'tfoot'], tfoot: ['tbody'], tr: ['tr', 'tbody'], td: ['td', 'th', 'tr'], th: ['td', 'th', 'tr'] }; function readElement$1(parser) { var attribute, selfClosing, children, partials, hasPartials, child, closed, pos, remaining, closingTag, anchor; var start = parser.pos; if (parser.inside || parser.inAttribute || parser.textOnlyMode) { return null; } if (!parser.matchString('<')) { return null; } // if this is a closing tag, abort straight away if (parser.nextChar() === '/') { return null; } var element = {}; if (parser.includeLinePositions) { element.q = parser.getLinePos(start); } // check for doctype decl if (parser.matchString('!')) { element.t = DOCTYPE; if (!parser.matchPattern(/^doctype/i)) { parser.error('Expected DOCTYPE declaration'); } element.a = parser.matchPattern(/^(.+?)>/); return element; } else if ((anchor = parser.matchString('#'))) { // check for anchor parser.sp(); element.t = ANCHOR; element.n = parser.matchPattern(anchorPattern); } else { // otherwise, it's an element/component element.t = ELEMENT; // element name element.e = parser.matchPattern(tagNamePattern); if (!element.e) { return null; } } // next character must be whitespace, closing solidus or '>' if (!validTagNameFollower.test(parser.nextChar())) { parser.error('Illegal tag name'); } parser.sp(); parser.inTag = true; // directives and attributes while ((attribute = readMustache(parser))) { if (attribute !== false) { if (!element.m) { element.m = []; } element.m.push(attribute); } parser.sp(); } parser.inTag = false; // allow whitespace before closing solidus parser.sp(); // self-closing solidus? if (parser.matchString('/')) { selfClosing = true; } // closing angle bracket if (!parser.matchString('>')) { return null; } var lowerCaseName = (element.e || element.n).toLowerCase(); var preserveWhitespace = parser.preserveWhitespace; if (!selfClosing && (anchor || !voidElements[element.e.toLowerCase()])) { if (!anchor) { parser.elementStack.push(lowerCaseName); // Special case - if we open a script element, further tags should // be ignored unless they're a closing script element if (lowerCaseName in parser.interpolate) { parser.inside = lowerCaseName; } } children = []; partials = create(null); do { pos = parser.pos; remaining = parser.remaining(); if (!remaining) { // if this happens to be a script tag and there's no content left, it's because // a closing script tag can't appear in a script if (parser.inside === 'script') { closed = true; break; } parser.error( ("Missing end " + (parser.elementStack.length > 1 ? 'tags' : 'tag') + " (" + (parser.elementStack .reverse() .map(function (x) { return ("</" + x + ">"); }) .join('')) + ")") ); } // if for example we're in an <li> element, and we see another // <li> tag, close the first so they become siblings if (!anchor && !canContain(lowerCaseName, remaining)) { closed = true; } else if (!anchor && (closingTag = readClosingTag(parser))) { // closing tag closed = true; var closingTagName = closingTag.e.toLowerCase(); // if this *isn't* the closing tag for the current element... if (closingTagName !== lowerCaseName) { // rewind parser parser.pos = pos; // if it doesn't close a parent tag, error if (!~parser.elementStack.indexOf(closingTagName)) { var errorMessage = 'Unexpected closing tag'; // add additional help for void elements, since component names // might clash with them if (voidElements[closingTagName.toLowerCase()]) { errorMessage += " (<" + closingTagName + "> is a void element - it cannot contain children)"; } parser.error(errorMessage); } } } else if (anchor && readAnchorClose(parser, element.n)) { closed = true; } else { // implicit close by closing section tag. TODO clean this up var tag = { open: parser.standardDelimiters[0], close: parser.standardDelimiters[1] }; if (readClosing(parser, tag) || readInline(parser, tag)) { closed = true; parser.pos = pos; } else if ((child = parser.read(PARTIAL_READERS))) { if (partials[child.n]) { parser.pos = pos; parser.error('Duplicate partial definition'); } cleanup( child.f, parser.stripComments, preserveWhitespace, !preserveWhitespace, !preserveWhitespace, parser.whiteSpaceElements ); partials[child.n] = child.f; hasPartials = true; } else { if ((child = parser.read(READERS))) { children.push(child); } else { closed = true; } } } } while (!closed); if (children.length) { element.f = children; } if (hasPartials) { element.p = partials; } parser.elementStack.pop(); } parser.inside = null; if (parser.sanitizeElements && parser.sanitizeElements.indexOf(lowerCaseName) !== -1) { return exclude; } if ( element.m && lowerCaseName !== 'input' && lowerCaseName !== 'select' && lowerCaseName !== 'textarea' && lowerCaseName !== 'option' ) { var attrs = element.m; var classes, styles, cls, style; var i = 0; var a; while (i < attrs.length) { a = attrs[i]; if (a.t !== ATTRIBUTE) { i++; continue; } if (a.n.indexOf('class-') === 0 && !a.f) { // static class directives (classes || (classes = [])).push(a.n.slice(6)); attrs.splice(i, 1); } else if (a.n.indexOf('style-') === 0 && isString(a.f)) { // static style directives (styles || (styles = [])).push(((hyphenateCamel(a.n.slice(6))) + ": " + (a.f) + ";")); attrs.splice(i, 1); } else if (a.n === 'class' && isString(a.f)) { // static class attrs (classes || (classes = [])).push(a.f); attrs.splice(i, 1); } else if (a.n === 'style' && isString(a.f)) { // static style attrs (styles || (styles = [])).push(a.f + (semiEnd.test(a.f) ? '' : ';')); attrs.splice(i, 1); } else if (a.n === 'class') { cls = a; i++; } else if (a.n === 'style') { style = a; i++; } else if ( !~a.n.indexOf(':') && a.n !== 'value' && a.n !== 'contenteditable' && isString(a.f) ) { a.g = 1; i++; } else { i++; } } if (classes) { if (!cls || !isString(cls.f)) { attrs.unshift({ t: ATTRIBUTE, n: 'class', f: classes.join(' '), g: 1 }); } else { cls.f += ' ' + classes.join(' '); } } else if (cls && isString(cls.f)) { cls.g = 1; } if (styles) { if (!style || !isString(style.f)) { attrs.unshift({ t: ATTRIBUTE, n: 'style', f: styles.join(' '), g: 1 }); } else { style.f += '; ' + styles.join(' '); } } else if (style && isString(style.f)) { style.g = 1; } } return element; } function canContain(name, remaining) { var match = /^<([a-zA-Z][a-zA-Z0-9]*)/.exec(remaining); var disallowed = disallowedContents[name]; if (!match || !disallowed) { return true; } return !~disallowed.indexOf(match[1].toLowerCase()); } function readAnchorClose(parser, name) { var pos = parser.pos; if (!parser.matchString('</')) { return null; } parser.matchString('#'); parser.sp(); if (!parser.matchString(name)) { parser.pos = pos; return null; } parser.sp(); if (!parser.matchString('>')) { parser.pos = pos; return null; } return true; } var inlines = /^\s*(elseif|else|then|catch)\s*/; function readInline(parser, tag) { var pos = parser.pos; if (!parser.matchString(tag.open)) { return; } if (parser.matchPattern(inlines)) { return true; } else { parser.pos = pos; } } function readText(parser) { var index, disallowed, barrier; var remaining = parser.remaining(); if (parser.textOnlyMode) { disallowed = parser.tags.map(function (t) { return t.open; }); disallowed = disallowed.concat(parser.tags.map(function (t) { return '\\' + t.open; })); index = getLowestIndex(remaining, disallowed); } else { barrier = parser.inside ? '</' + parser.inside : '<'; if (parser.inside && !parser.interpolate[parser.inside]) { index = remaining.indexOf(barrier); } else { disallowed = parser.tags.map(function (t) { return t.open; }); disallowed = disallowed.concat(parser.tags.map(function (t) { return '\\' + t.open; })); // http://developers.whatwg.org/syntax.html#syntax-attributes if (parser.inAttribute === true) { // we're inside an unquoted attribute value disallowed.push("\"", "'", "=", "<", ">", '`'); } else if (parser.inAttribute) { // quoted attribute value disallowed.push(parser.inAttribute); } else { disallowed.push(barrier); } index = getLowestIndex(remaining, disallowed); } } if (!index) { return null; } if (index === -1) { index = remaining.length; } parser.pos += index; if ((parser.inside && parser.inside !== 'textarea') || parser.textOnlyMode) { return remaining.substr(0, index); } else { return decodeCharacterReferences(remaining.substr(0, index)); } } var partialDefinitionSectionPattern = /^\s*#\s*partial\s+/; function readPartialDefinitionSection(parser) { var child, closed; var start = parser.pos; var delimiters = parser.standardDelimiters; if (!parser.matchString(delimiters[0])) { return null; } if (!parser.matchPattern(partialDefinitionSectionPattern)) { parser.pos = start; return null; } var name = parser.matchPattern(/^[a-zA-Z_$][a-zA-Z_$0-9\-\/]*/); if (!name) { parser.error('expected legal partial name'); } parser.sp(); if (!parser.matchString(delimiters[1])) { parser.error(("Expected closing delimiter '" + (delimiters[1]) + "'")); } var content = []; var open = delimiters[0]; var close = delimiters[1]; do { if ((child = readClosing(parser, { open: open, close: close }))) { if (child.r !== 'partial') { parser.error(("Expected " + open + "/partial" + close)); } closed = true; } else { child = parser.read(READERS); if (!child) { parser.error(("Expected " + open + "/partial" + close)); } content.push(child); } } while (!closed); return { t: INLINE_PARTIAL, n: name, f: content }; } function readTemplate(parser) { var fragment = []; var partials = create(null); var hasPartials = false; var preserveWhitespace = parser.preserveWhitespace; while (parser.pos < parser.str.length) { var pos = parser.pos; var item = (void 0), partial = (void 0); if ((partial = parser.read(PARTIAL_READERS))) { if (partials[partial.n]) { parser.pos = pos; parser.error('Duplicated partial definition'); } cleanup( partial.f, parser.stripComments, preserveWhitespace, !preserveWhitespace, !preserveWhitespace, parser.whiteSpaceElements ); partials[partial.n] = partial.f; hasPartials = true; } else if ((item = parser.read(READERS))) { fragment.push(item); } else { parser.error('Unexpected template content'); } } var result = { v: TEMPLATE_VERSION, t: fragment }; if (hasPartials) { result.p = partials; } return result; } function insertExpressions(obj, expr) { keys(obj).forEach(function (key) { if (isExpression(key, obj)) { return addTo(obj, expr); } var ref = obj[key]; if (hasChildren(ref)) { insertExpressions(ref, expr); } }); } function isExpression(key, obj) { return key === 's' && isArray(obj.r); } function addTo(obj, expr) { var s = obj.s; var r = obj.r; if (!expr[s]) { expr[s] = fromExpression(s, r.length); } } function hasChildren(ref) { return isArray(ref) || isObject(ref); } var shared = {}; // See https://github.com/ractivejs/template-spec for information // about the Ractive template specification var STANDARD_READERS = [ readPartial, readUnescaped, readSection, readInterpolator, readComment ]; var TRIPLE_READERS = [readTriple]; var READERS = [readMustache, readHtmlComment, readElement$1, readText]; var PARTIAL_READERS = [readPartialDefinitionSection]; var preserveWhitespaceElements = { pre: 1, script: 1, style: 1, textarea: 1 }; var defaultInterpolate = { textarea: true, script: true, style: true, template: true }; var StandardParser = Parser.extend({ init: function init(str, options) { var tripleDelimiters = options.tripleDelimiters || shared.defaults.tripleDelimiters; var staticDelimiters = options.staticDelimiters || shared.defaults.staticDelimiters; var staticTripleDelimiters = options.staticTripleDelimiters || shared.defaults.staticTripleDelimiters; this.standardDelimiters = options.delimiters || shared.defaults.delimiters; this.tags = [ { isStatic: false, isTriple: false, open: this.standardDelimiters[0], close: this.standardDelimiters[1], readers: STANDARD_READERS }, { isStatic: false, isTriple: true, open: tripleDelimiters[0], close: tripleDelimiters[1], readers: TRIPLE_READERS }, { isStatic: true, isTriple: false, open: staticDelimiters[0], close: staticDelimiters[1], readers: STANDARD_READERS }, { isStatic: true, isTriple: true, open: staticTripleDelimiters[0], close: staticTripleDelimiters[1], readers: TRIPLE_READERS } ]; this.contextLines = options.contextLines || shared.defaults.contextLines; this.sortMustacheTags(); this.sectionDepth = 0; this.elementStack = []; this.interpolate = assign( {}, defaultInterpolate, shared.defaults.interpolate, options.interpolate ); if (options.sanitize === true) { options.sanitize = { // blacklist from https://code.google.com/p/google-caja/source/browse/trunk/src/com/google/caja/lang/html/html4-elements-whitelist.json elements: 'applet base basefont body frame frameset head html isindex link meta noframes noscript object param script style title'.split( ' ' ), eventAttributes: true }; } this.stripComments = options.stripComments !== false; this.preserveWhitespace = isObjectType(options.preserveWhitespace) ? false : options.preserveWhitespace; this.sanitizeElements = options.sanitize && options.sanitize.elements; this.sanitizeEventAttributes = options.sanitize && options.sanitize.eventAttributes; this.includeLinePositions = options.includeLinePositions; this.textOnlyMode = options.textOnlyMode; this.csp = options.csp; this.allowExpressions = options.allowExpressions; if (options.expression) { this.converters = [readExpression]; } if (options.attributes) { this.inTag = true; } // special whitespace handling requested for certain elements this.whiteSpaceElements = assign({}, options.preserveWhitespace, preserveWhitespaceElements); }, postProcess: function postProcess(result, options) { var parserResult = result[0]; if (options.expression) { var expr = flattenExpression(parserResult); expr.e = fromExpression(expr.s, expr.r.length); return expr; } else { // special case - empty string if (!result.length) { return { t: [], v: TEMPLATE_VERSION }; } if (this.sectionDepth > 0) { this.error('A section was left open'); } cleanup( parserResult.t, this.stripComments, this.preserveWhitespace, !this.preserveWhitespace, !this.preserveWhitespace, this.whiteSpaceElements ); if (this.csp !== false) { var expr$1 = {}; insertExpressions(parserResult.t, expr$1); insertExpressions(parserResult.p || {}, expr$1); if (keys(expr$1).length) { parserResult.e = expr$1; } } return parserResult; } }, converters: [readTemplate], sortMustacheTags: function sortMustacheTags() { // Sort in order of descending opening delimiter length (longer first), // to protect against opening delimiters being substrings of each other this.tags.sort(function (a, b) { return b.open.length - a.open.length; }); } }); function parse(template, options) { return new StandardParser(template, options || {}).result; } var parseOptions = [ 'delimiters', 'tripleDelimiters', 'staticDelimiters', 'staticTripleDelimiters', 'csp', 'interpolate', 'preserveWhitespace', 'sanitize', 'stripComments', 'contextLines', 'allowExpressions', 'attributes' ]; var TEMPLATE_INSTRUCTIONS = "Either preparse or use a ractive runtime source that includes the parser. "; var COMPUTATION_INSTRUCTIONS = "Either include a version of Ractive that can parse or convert your computation strings to functions."; function throwNoParse(method, error, instructions) { if (!method) { fatal(("Missing Ractive.parse - cannot parse " + error + ". " + instructions)); } } function createFunction(body, length) { throwNoParse(fromExpression, 'new expression function', TEMPLATE_INSTRUCTIONS); return fromExpression(body, length); } function createFunctionFromString(str, bindTo) { throwNoParse(parse, 'compution string "${str}"', COMPUTATION_INSTRUCTIONS); var tpl = parse(str, { expression: true }); return function() { return tpl.e.apply(bindTo, tpl.r.map(function (r) { return bindTo.get(r); })); }; } var parser = { fromId: function fromId(id, options) { if (!doc) { if (options && options.noThrow) { return; } throw new Error(("Cannot retrieve template #" + id + " as Ractive is not running in a browser.")); } if (id) { id = id.replace(/^#/, ''); } var template; if (!(template = doc.getElementById(id))) { if (options && options.noThrow) { return; } throw new Error(("Could not find template element with id #" + id)); } if (template.tagName.toUpperCase() !== 'SCRIPT') { if (options && options.noThrow) { return; } throw new Error(("Template element with id #" + id + ", must be a <script> element")); } return 'textContent' in template ? template.textContent : template.innerHTML; }, isParsed: function isParsed(template) { return !isString(template); }, getParseOptions: function getParseOptions(ractive) { // Could be Ractive or a Component if (ractive.defaults) { ractive = ractive.defaults; } return parseOptions.reduce(function (val, key) { val[key] = ractive[key]; return val; }, {}); }, parse: function parse$1(template, options) { throwNoParse(parse, 'template', TEMPLATE_INSTRUCTIONS); var parsed = parse(template, options); addFunctions(parsed); return parsed; }, parseFor: function parseFor(template, ractive) { return this.parse(template, this.getParseOptions(ractive)); } }; function getComputationSignature(ractive, key, signature) { var getter; var setter; // useful for debugging var getterString; var getterUseStack; var setterString; if (isFunction(signature)) { getter = bind(signature, ractive); getterString = signature.toString(); getterUseStack = true; } if (isString(signature)) { getter = createFunctionFromString(signature, ractive); getterString = signature; } if (isObjectType(signature)) { if (isString(signature.get)) { getter = createFunctionFromString(signature.get, ractive); getterString = signature.get; } else if (isFunction(signature.get)) { getter = bind(signature.get, ractive); getterString = signature.get.toString(); getterUseStack = true; } else { fatal('`%s` computation must have a `get()` method', key); } if (isFunction(signature.set)) { setter = bind(signature.set, ractive); setterString = signature.set.toString(); } } return { getter: getter, setter: setter, getterString: getterString, setterString: setterString, getterUseStack: getterUseStack }; } var id = 0; var TransitionManager = function TransitionManager(callback, parent) { this.callback = callback; this.parent = parent; this.intros = []; this.outros = []; this.children = []; this.totalChildren = this.outroChildren = 0; this.detachQueue = []; this.outrosComplete = false; this.id = id++; if (parent) { parent.addChild(this); } }; var TransitionManager__proto__ = TransitionManager.prototype; TransitionManager__proto__.add = function add (transition) { var list = transition.isIntro ? this.intros : this.outros; transition.starting = true; list.push(transition); }; TransitionManager__proto__.addChild = function addChild (child) { this.children.push(child); this.totalChildren += 1; this.outroChildren += 1; }; TransitionManager__proto__.checkStart = function checkStart () { if (this.parent && this.parent.started) { this.start(); } }; TransitionManager__proto__.decrementOutros = function decrementOutros () { this.outroChildren -= 1; check(this); }; TransitionManager__proto__.decrementTotal = function decrementTotal () { this.totalChildren -= 1; check(this); }; TransitionManager__proto__.detachNodes = function detachNodes () { var this$1 = this; var len = this.detachQueue.length; for (var i = 0; i < len; i++) { this$1.detachQueue[i].detach(); } len = this.children.length; for (var i$1 = 0; i$1 < len; i$1++) { this$1.children[i$1].detachNodes(); } this.detachQueue = []; }; TransitionManager__proto__.ready = function ready () { if (this.detachQueue.length) { detachImmediate(this); } }; TransitionManager__proto__.remove = function remove (transition) { var list = transition.isIntro ? this.intros : this.outros; removeFromArray(list, transition); check(this); }; TransitionManager__proto__.start = function start () { this.started = true; this.children.forEach(function (c) { return c.start(); }); this.intros.concat(this.outros).forEach(function (t) { return t.start(); }); check(this); }; function check(tm) { if (!tm.started || tm.outros.length || tm.outroChildren) { return; } // If all outros are complete, and we haven't already done this, // we notify the parent if there is one, otherwise // start detaching nodes if (!tm.outrosComplete) { tm.outrosComplete = true; if (tm.parent) { tm.parent.decrementOutros(tm); } if (!tm.parent || tm.parent.outrosComplete) { tm.detachNodes(); } } // Once everything is done, we can notify parent transition // manager and call the callback if (!tm.intros.length && !tm.totalChildren) { if (isFunction(tm.callback)) { tm.callback(); } if (tm.parent && !tm.notifiedTotal) { tm.notifiedTotal = true; tm.parent.decrementTotal(); } } } // check through the detach queue to see if a node is up or downstream from a // transition and if not, go ahead and detach it function detachImmediate(manager) { var queue = manager.detachQueue; var outros = collectAllOutros(manager); if (!outros.length) { manager.detachNodes(); } else { var i = queue.length; var j = 0; var node, trans; var nqueue = (manager.detachQueue = []); start: while (i--) { node = queue[i].node; j = outros.length; while (j--) { trans = outros[j].element.node; // check to see if the node is, contains, or is contained by the transitioning node if (trans === node || trans.contains(node) || node.contains(trans)) { nqueue.push(queue[i]); continue start; } } // no match, we can drop it queue[i].detach(); } } } function collectAllOutros(manager, _list) { var list = _list; // if there's no list, we're starting at the root to build one if (!list) { list = []; var parent = manager; while (parent.parent) { parent = parent.parent; } return collectAllOutros(parent, list); } else { // grab all outros from child managers var i = manager.children.length; while (i--) { list = collectAllOutros(manager.children[i], list); } // grab any from this manager if there are any if (manager.outros.length) { list = list.concat(manager.outros); } return list; } } var batch; var runloop = { active: function active() { return !!batch; }, start: function start() { var fulfilPromise; var promise = new Promise(function (f) { return (fulfilPromise = f); }); batch = { previousBatch: batch, transitionManager: new TransitionManager(fulfilPromise, batch && batch.transitionManager), fragments: [], tasks: [], immediateObservers: [], deferredObservers: [], promise: promise }; return promise; }, end: function end() { flushChanges(); if (!batch.previousBatch) { batch.transitionManager.start(); } else { batch.transitionManager.checkStart(); } batch = batch.previousBatch; }, addFragment: function addFragment(fragment) { addToArray(batch.fragments, fragment); }, // TODO: come up with a better way to handle fragments that trigger their own update addFragmentToRoot: function addFragmentToRoot(fragment) { if (!batch) { return; } var b = batch; while (b.previousBatch) { b = b.previousBatch; } addToArray(b.fragments, fragment); }, addObserver: function addObserver(observer, defer) { if (!batch) { observer.dispatch(); } else { addToArray(defer ? batch.deferredObservers : batch.immediateObservers, observer); } }, registerTransition: function registerTransition(transition) { transition._manager = batch.transitionManager; batch.transitionManager.add(transition); }, // synchronise node detachments with transition ends detachWhenReady: function detachWhenReady(thing) { batch.transitionManager.detachQueue.push(thing); }, scheduleTask: function scheduleTask(task, postRender) { var _batch; if (!batch) { task(); } else { _batch = batch; while (postRender && _batch.previousBatch) { // this can't happen until the DOM has been fully updated // otherwise in some situations (with components inside elements) // transitions and decorators will initialise prematurely _batch = _batch.previousBatch; } _batch.tasks.push(task); } }, promise: function promise() { if (!batch) { return Promise.resolve(); } var target = batch; while (target.previousBatch) { target = target.previousBatch; } return target.promise || Promise.resolve(); } }; function dispatch(observer) { observer.dispatch(); } function flushChanges() { var which = batch.immediateObservers; batch.immediateObservers = []; which.forEach(dispatch); // Now that changes have been fully propagated, we can update the DOM // and complete other tasks var i = batch.fragments.length; var fragment; which = batch.fragments; batch.fragments = []; while (i--) { fragment = which[i]; fragment.update(); } batch.transitionManager.ready(); which = batch.deferredObservers; batch.deferredObservers = []; which.forEach(dispatch); var tasks = batch.tasks; batch.tasks = []; for (i = 0; i < tasks.length; i += 1) { tasks[i](); } // If updating the view caused some model blowback - e.g. a triple // containing <option> elements caused the binding on the <select> // to update - then we start over if ( batch.fragments.length || batch.immediateObservers.length || batch.deferredObservers.length || batch.tasks.length ) { return flushChanges(); } } // TODO what happens if a transition is aborted? var tickers = []; var running = false; function tick() { runloop.start(); var now = performance.now(); var i; var ticker; for (i = 0; i < tickers.length; i += 1) { ticker = tickers[i]; if (!ticker.tick(now)) { // ticker is complete, remove it from the stack, and decrement i so we don't miss one tickers.splice(i--, 1); } } runloop.end(); if (tickers.length) { requestAnimationFrame(tick); } else { running = false; } } var Ticker = function Ticker(options) { this.duration = options.duration; this.step = options.step; this.complete = options.complete; this.easing = options.easing; this.start = performance.now(); this.end = this.start + this.duration; this.running = true; tickers.push(this); if (!running) { requestAnimationFrame(tick); } }; var Ticker__proto__ = Ticker.prototype; Ticker__proto__.tick = function tick (now) { if (!this.running) { return false; } if (now > this.end) { if (this.step) { this.step(1); } if (this.complete) { this.complete(1); } return false; } var elapsed = now - this.start; var eased = this.easing(elapsed / this.duration); if (this.step) { this.step(eased); } return true; }; Ticker__proto__.stop = function stop () { if (this.abort) { this.abort(); } this.running = false; }; var prefixers = {}; // TODO this is legacy. sooner we can replace the old adaptor API the better /* istanbul ignore next */ function prefixKeypath(obj, prefix) { var prefixed = {}; if (!prefix) { return obj; } prefix += '.'; for (var key in obj) { if (hasOwn(obj, key)) { prefixed[prefix + key] = obj[key]; } } return prefixed; } function getPrefixer(rootKeypath) { var rootDot; if (!prefixers[rootKeypath]) { rootDot = rootKeypath ? rootKeypath + '.' : ''; /* istanbul ignore next */ prefixers[rootKeypath] = function(relativeKeypath, value) { var obj; if (isString(relativeKeypath)) { obj = {}; obj[rootDot + relativeKeypath] = value; return obj; } if (isObjectType(relativeKeypath)) { // 'relativeKeypath' is in fact a hash, not a keypath return rootDot ? prefixKeypath(relativeKeypath, rootKeypath) : relativeKeypath; } }; } return prefixers[rootKeypath]; } var shared$1 = {}; var Model = (function (ModelBase) { function Model(parent, key) { ModelBase.call(this, parent); this.ticker = null; if (parent) { this.key = unescapeKey(key); this.isReadonly = parent.isReadonly; if (parent.value) { this.value = parent.value[this.key]; if (isArray(this.value)) { this.length = this.value.length; } this.adapt(); } } } if ( ModelBase ) Model.__proto__ = ModelBase; var Model__proto__ = Model.prototype = Object.create( ModelBase && ModelBase.prototype ); Model__proto__.constructor = Model; Model__proto__.adapt = function adapt () { var this$1 = this; var adaptors = this.root.adaptors; var len = adaptors.length; this.rewrap = false; // Exit early if no adaptors if (len === 0) { return; } var value = this.wrapper ? 'newWrapperValue' in this ? this.newWrapperValue : this.wrapperValue : this.value; // TODO remove this legacy nonsense var ractive = this.root.ractive; var keypath = this.getKeypath(); // tear previous adaptor down if present if (this.wrapper) { var shouldTeardown = this.wrapperValue === value ? false : !this.wrapper.reset || this.wrapper.reset(value) === false; if (shouldTeardown) { this.wrapper.teardown(); delete this.wrapper; delete this.wrapperValue; delete this.newWrapperValue; // don't branch for undefined values if (this.value !== undefined) { var parentValue = this.parent.value || this.parent.createBranch(this.key); if (parentValue[this.key] !== value) { parentValue[this.key] = value; } this.value = value; } } else { delete this.newWrapperValue; this.value = this.wrapper.get(); return; } } var i; for (i = 0; i < len; i += 1) { var adaptor = adaptors[i]; if (adaptor.filter(value, keypath, ractive)) { this$1.wrapper = adaptor.wrap(ractive, value, keypath, getPrefixer(keypath)); this$1.wrapperValue = value; this$1.wrapper.__model = this$1; // massive temporary hack to enable array adaptor this$1.value = this$1.wrapper.get(); break; } } }; Model__proto__.animate = function animate (from, to, options, interpolator) { var this$1 = this; if (this.ticker) { this.ticker.stop(); } var fulfilPromise; var promise = new Promise(function (fulfil) { return (fulfilPromise = fulfil); }); this.ticker = new Ticker({ duration: options.duration, easing: options.easing, step: function (t) { var value = interpolator(t); this$1.applyValue(value); if (options.step) { options.step(t, value); } }, complete: function () { this$1.applyValue(to); if (options.complete) { options.complete(to); } this$1.ticker = null; fulfilPromise(to); } }); promise.stop = this.ticker.stop; return promise; }; Model__proto__.applyValue = function applyValue (value, notify) { if ( notify === void 0 ) notify = true; if (isEqual(value, this.value)) { return; } if (this.boundValue) { this.boundValue = null; } if (this.parent.wrapper && this.parent.wrapper.set) { this.parent.wrapper.set(this.key, value); this.parent.value = this.parent.wrapper.get(); this.value = this.parent.value[this.key]; if (this.wrapper) { this.newWrapperValue = this.value; } this.adapt(); } else if (this.wrapper) { this.newWrapperValue = value; this.adapt(); } else { var parentValue = this.parent.value || this.parent.createBranch(this.key); if (isObjectLike(parentValue)) { parentValue[this.key] = value; } else { warnIfDebug(("Attempted to set a property of a non-object '" + (this.getKeypath()) + "'")); return; } this.value = value; this.adapt(); } if (this.dataModel || (value && value.viewmodel && value.viewmodel.isRoot)) { checkDataLink(this, value); } // keep track of array stuff if (isArray(value)) { this.length = value.length; this.isArray = true; } else { this.isArray = false; } // notify dependants this.links.forEach(handleChange); this.children.forEach(mark); this.deps.forEach(handleChange); if (notify) { this.notifyUpstream(); } if (this.parent.isArray) { if (this.key === 'length') { this.parent.length = value; } else { this.parent.joinKey('length').mark(); } } }; Model__proto__.compute = function compute (key, computed) { var registry = this.computed || (this.computed = {}); if (registry[key]) { registry[key].signature = getComputationSignature(this.root.ractive, key, computed); registry[key].mark(); } else { registry[key] = new shared$1.Computation( this, getComputationSignature(this.root.ractive, key, computed), key ); } return registry[key]; }; Model__proto__.createBranch = function createBranch (key) { var branch = isNumeric(key) ? [] : {}; this.applyValue(branch, false); return branch; }; Model__proto__.get = function get (shouldCapture, opts) { if (this._link) { return this._link.get(shouldCapture, opts); } if (shouldCapture) { capture(this); } // if capturing, this value needs to be unwrapped because it's for external use if (opts && opts.virtual) { return this.getVirtual(false); } return maybeBind( this, (opts && 'unwrap' in opts ? opts.unwrap !== false : shouldCapture) && this.wrapper ? this.wrapperValue : this.value, !opts || opts.shouldBind !== false ); }; Model__proto__.joinKey = function joinKey (key, opts) { var this$1 = this; if (this._link) { if (opts && opts.lastLink !== false && (isUndefined(key) || key === '')) { return this; } return this._link.joinKey(key); } if (isUndefined(key) || key === '') { return this; } var child; if (hasOwn(this.childByKey, key)) { child = this.childByKey[key]; } else { child = this.computed && this.computed[key]; } if (!child) { var computed; if (this.isRoot && this.ractive && (computed = this.ractive.computed[key])) { child = this.compute(key, computed); } else if (!this.isRoot && this.root.ractive) { var registry = this.root.ractive.computed; for (var k in registry) { computed = registry[k]; if (computed.pattern && computed.pattern.test(this$1.getKeypath() + '.' + key)) { child = this$1.compute(key, computed); } } } } if (!child) { child = new Model(this, key); this.children.push(child); this.childByKey[key] = child; if (key === 'data') { var val = this.retrieve(); if (val && val.viewmodel && val.viewmodel.isRoot) { child.link(val.viewmodel, 'data'); this.dataModel = val; } } } if (child._link && (!opts || opts.lastLink !== false)) { return child._link; } return child; }; Model__proto__.mark = function mark$1 (force) { if (this._link) { return this._link.mark(force); } var old = this.value; var value = this.retrieve(); if (this.dataModel || (value && value.viewmodel && value.viewmodel.isRoot)) { checkDataLink(this, value); } if (force || !isEqual(value, old)) { this.value = value; if (this.boundValue) { this.boundValue = null; } // make sure the wrapper stays in sync if (old !== value || this.rewrap) { if (this.wrapper) { this.newWrapperValue = value; } this.adapt(); } // keep track of array stuff if (isArray(value)) { this.length = value.length; this.isArray = true; } else { this.isArray = false; } this.children.forEach(force ? markForce : mark); this.links.forEach(marked); this.deps.forEach(handleChange); } }; Model__proto__.merge = function merge (array, comparator) { var newIndices = buildNewIndices( this.value === array ? recreateArray(this) : this.value, array, comparator ); this.parent.value[this.key] = array; this.shuffle(newIndices, true); }; Model__proto__.retrieve = function retrieve () { return this.parent.value ? this.parent.value[this.key] : undefined; }; Model__proto__.set = function set (value) { if (this.ticker) { this.ticker.stop(); } this.applyValue(value); }; Model__proto__.shuffle = function shuffle$2 (newIndices, unsafe) { shuffle(this, newIndices, false, unsafe); }; Model__proto__.source = function source () { return this; }; Model__proto__.teardown = function teardown$4 () { var this$1 = this; if (this._link) { this._link.teardown(); this._link = null; } this.children.forEach(teardown); if (this.wrapper) { this.wrapper.teardown(); } if (this.computed) { keys(this.computed).forEach(function (k) { return this$1.computed[k].teardown(); }); } }; return Model; }(ModelBase)); function recreateArray(model) { var array = []; for (var i = 0; i < model.length; i++) { array[i] = (model.childByKey[i] || {}).value; } return array; } /* global global */ var data = {}; var SharedModel = (function (Model) { function SharedModel(value, name, ractive) { Model.call(this, null, ("@" + name)); this.key = "@" + name; this.value = value; this.isRoot = true; this.root = this; this.adaptors = []; this.ractive = ractive; } if ( Model ) SharedModel.__proto__ = Model; var SharedModel__proto__ = SharedModel.prototype = Object.create( Model && Model.prototype ); SharedModel__proto__.constructor = SharedModel; SharedModel__proto__.getKeypath = function getKeypath () { return this.key; }; SharedModel__proto__.retrieve = function retrieve () { return this.value; }; return SharedModel; }(Model)); var SharedModel$1 = new SharedModel(data, 'shared'); var GlobalModel = new SharedModel(base, 'global'); function findContext(fragment) { var frag = fragment; while (frag && !frag.context && !frag.aliases) { frag = frag.parent; } return frag; } function resolveReference(fragment, ref) { var initialFragment = fragment; // current context ref if (ref === '.') { return fragment.findContext(); } // ancestor references if (ref[0] === '~') { return fragment.ractive.viewmodel.joinAll(splitKeypath(ref.slice(2))); } // scoped references if (ref[0] === '.' || ref[0] === '^') { var frag = fragment; var parts = ref.split('/'); var explicitContext = parts[0] === '^^'; // find nearest context node while (frag && !frag.context) { frag = up(frag); } var context$1 = frag && frag.context; // walk up the context chain while (frag && parts[0] === '^^') { parts.shift(); // the current fragment should always be a context, // and if it happens to be an iteration, jump above the each block if (frag.isIteration) { frag = frag.parent.parent; } else { // otherwise jump above the current fragment frag = up(frag); } // walk to the next contexted fragment while (frag && !frag.context) { frag = up(frag); } context$1 = frag && frag.context; } if (!context$1 && explicitContext) { throw new Error( ("Invalid context parent reference ('" + ref + "'). There is not context at that level.") ); } // walk up the context path while (parts[0] === '.' || parts[0] === '..') { var part = parts.shift(); if (part === '..') { context$1 = context$1.parent; } } ref = parts.join('/'); // special case - `{{.foo}}` means the same as `{{./foo}}` if (ref[0] === '.') { ref = ref.slice(1); } return context$1.joinAll(splitKeypath(ref)); } var keys$$1 = splitKeypath(ref); if (!keys$$1.length) { return; } var base = keys$$1.shift(); // special refs if (base[0] === '@') { // shorthand from outside the template // @this referring to local ractive instance if (base === '@this' || base === '@') { return fragment.ractive.viewmodel.getRactiveModel().joinAll(keys$$1); } else if (base === '@index' || base === '@key') { // @index or @key referring to the nearest repeating index or key if (keys$$1.length) { badReference(base); } var repeater = findIter(fragment); return repeater && repeater[("get" + (base[1] === 'i' ? 'Index' : 'Key'))](); } else if (base === '@last') { var repeater$1 = findIter(fragment); return repeater$1 && repeater$1.parent.getLast(); } else if (base === '@global') { // @global referring to window or global return GlobalModel.joinAll(keys$$1); } else if (base === '@shared') { // @global referring to window or global return SharedModel$1.joinAll(keys$$1); } else if (base === '@keypath' || base === '@rootpath') { // @keypath or @rootpath, the current keypath string var root = ref[1] === 'r' ? fragment.ractive.root : null; var f = fragment; while ( f && (!f.context || (f.isRoot && f.ractive.component && (root || !f.ractive.isolated))) ) { f = f.isRoot ? f.componentParent : f.parent; } return f.getKeypath(root); } else if (base === '@context') { return new SharedModel(fragment.getContext(), 'context').joinAll(keys$$1); } else if (base === '@local') { // @context-local data return fragment.getContext()._data.joinAll(keys$$1); } else if (base === '@style') { // @style shared model return fragment.ractive.constructor._cssModel.joinAll(keys$$1); } else if (base === '@helpers') { // @helpers instance model return fragment.ractive.viewmodel.getHelpers().joinAll(keys$$1); } else if (base === '@macro') { var handle = findMacro(fragment); if (handle) { return new SharedModel(handle, 'macro').joinAll(keys$$1); } else { return; } } else { // nope throw new Error(("Invalid special reference '" + base + "'")); } } // helpers if (base && !keys$$1.length) { var helpers = fragment.ractive.viewmodel.getHelpers(); if (helpers.has(base)) { return helpers.joinKey(base); } } var context = findContext(fragment); // check immediate context for a match if (context) { if (context.context) { context = context.context; } else { // alias block, so get next full context for later context = fragment.findContext(); } } else { context = fragment.findContext(); } // walk up the fragment hierarchy looking for a matching ref, alias, or key in a context var createMapping = false; var shouldWarn = fragment.ractive.warnAboutAmbiguity; var crossed = 0; var model; while (fragment) { // repeated fragments if (fragment.isIteration) { if (base === fragment.parent.keyRef) { model = fragment.getKey(); } else if (base === fragment.parent.indexRef) { model = fragment.getIndex(); } if (model && keys$$1.length) { badReference(base); } } // alias node or iteration if (!model && fragment.aliases && hasOwn(fragment.aliases, base)) { model = fragment.aliases[base]; } // check fragment context to see if it has the key we need if (!model && fragment.context && fragment.context.has(base)) { model = fragment.context.joinKey(base); // this is an implicit mapping if (createMapping) { if (shouldWarn) { warnIfDebug( ("'" + ref + "' resolved but is ambiguous and will create a mapping to a parent component.") ); } } else if (shouldWarn && crossed) { warnIfDebug(("'" + ref + "' resolved but is ambiguous.")); } } if (model) { if (createMapping) { model = initialFragment.ractive.viewmodel.createLink(base, model, base, { implicit: true }); } if (keys$$1.length > 0 && isFunction(model.joinAll)) { model = model.joinAll(keys$$1); } return model; } // don't consider alias blocks when checking for ambiguity if (fragment.context && !fragment.aliases) { crossed = 1; } if ( (fragment.componentParent || (!fragment.parent && fragment.ractive.component)) && !fragment.ractive.isolated ) { // ascend through component boundary fragment = fragment.componentParent || fragment.ractive.component.up; createMapping = true; } else { fragment = fragment.parent; } } // if enabled, check the instance for a match var instance = initialFragment.ractive; if (instance.resolveInstanceMembers && base !== 'data' && base in instance) { return instance.viewmodel .getRactiveModel() .joinKey(base) .joinAll(keys$$1); } if (shouldWarn) { warnIfDebug(("'" + ref + "' is ambiguous and did not resolve.")); } // didn't find anything, so go ahead and create the key on the local model return context.joinKey(base).joinAll(keys$$1); } function up(fragment) { return fragment && ((!fragment.ractive.isolated && fragment.componentParent) || fragment.parent); } function findIter(start) { var fragment = start; var next; while (!fragment.isIteration && (next = up(fragment))) { fragment = next; } return fragment.isIteration && fragment; } function findMacro(start) { var fragment = start; while (fragment) { if (fragment.owner.handle) { return fragment.owner.handle; } fragment = up(fragment); } } function badReference(key) { throw new Error(("An index or key reference (" + key + ") cannot have child properties")); } var extern = {}; function getRactiveContext(ractive) { var assigns = [], len = arguments.length - 1; while ( len-- > 0 ) assigns[ len ] = arguments[ len + 1 ]; var fragment = ractive.fragment || ractive._fakeFragment || (ractive._fakeFragment = new FakeFragment(ractive)); return fragment.getContext.apply(fragment, assigns); } function getContext() { var assigns = [], len = arguments.length; while ( len-- ) assigns[ len ] = arguments[ len ]; if (!this.ctx) { this.ctx = new extern.Context(this); } assigns.unshift(create(this.ctx)); return assign.apply(null, assigns); } var FakeFragment = function FakeFragment(ractive) { this.ractive = ractive; }; FakeFragment.prototype.findContext = function findContext () { return this.ractive.viewmodel; }; var proto = FakeFragment.prototype; proto.getContext = getContext; proto.find = proto.findComponent = proto.findAll = proto.findAllComponents = noop; function findParentWithContext(fragment) { var frag = fragment; while (frag && !frag.context) { frag = frag.parent; } if (!frag) { return fragment && fragment.ractive.fragment; } else { return frag; } } var keep = false; function set(pairs, options) { var k = keep; var deep = options && options.deep; var shuffle = options && options.shuffle; var promise = runloop.start(); if (options && 'keep' in options) { keep = options.keep; } var i = pairs.length; while (i--) { var model = pairs[i][0]; var value = pairs[i][1]; var keypath = pairs[i][2]; if (!model) { runloop.end(); throw new Error(("Failed to set invalid keypath '" + keypath + "'")); } if (deep) { deepSet(model, value); } else if (shuffle) { var array = value; var target = model.get(); // shuffle target array with itself if (!array) { array = target; } // if there's not an array there yet, go ahead and set if (isUndefined(target)) { model.set(array); } else { if (!isArray(target) || !isArray(array)) { runloop.end(); throw new Error('You cannot merge an array with a non-array'); } var comparator = getComparator(shuffle); model.merge(array, comparator); } } else { model.set(value); } } runloop.end(); keep = k; return promise; } var star = /\*/; function gather(ractive, keypath, base, isolated) { if (!base && (keypath[0] === '.' || keypath[1] === '^')) { warnIfDebug( "Attempted to set a relative keypath from a non-relative context. You can use a context object to set relative keypaths." ); return []; } var keys$$1 = splitKeypath(keypath); var model = base || ractive.viewmodel; if (star.test(keypath)) { return model.findMatches(keys$$1); } else { if (model === ractive.viewmodel) { // allow implicit mappings if ( ractive.component && !ractive.isolated && !model.has(keys$$1[0]) && keypath[0] !== '@' && keypath[0] && !isolated ) { return [resolveReference(ractive.fragment || new FakeFragment(ractive), keypath)]; } else { return [model.joinAll(keys$$1)]; } } else { return [model.joinAll(keys$$1)]; } } } function build(ractive, keypath, value, isolated) { var sets = []; // set multiple keypaths in one go if (isObject(keypath)) { var loop = function ( k ) { if (hasOwn(keypath, k)) { sets.push.apply(sets, gather(ractive, k, null, isolated).map(function (m) { return [m, keypath[k], k]; })); } }; for (var k in keypath) loop( k ); } else { // set a single keypath sets.push.apply(sets, gather(ractive, keypath, null, isolated).map(function (m) { return [m, value, keypath]; })); } return sets; } var deepOpts = { virtual: false }; function deepSet(model, value) { var dest = model.get(false, deepOpts); // if dest doesn't exist, just set it if (dest == null || !isObjectType(value)) { return model.set(value); } if (!isObjectType(dest)) { return model.set(value); } for (var k in value) { if (hasOwn(value, k)) { deepSet(model.joinKey(k), value[k]); } } } var comparators = {}; function getComparator(option) { if (option === true) { return null; } // use existing arrays if (isFunction(option)) { return option; } if (isString(option)) { return comparators[option] || (comparators[option] = function (thing) { return thing[option]; }); } throw new Error('If supplied, options.compare must be a string, function, or true'); // TODO link to docs } var errorMessage = 'Cannot add to a non-numeric value'; function add(ractive, keypath, d, options) { if (!isString(keypath) || !isNumeric(d)) { throw new Error('Bad arguments'); } var sets = build(ractive, keypath, d, options && options.isolated); return set( sets.map(function (pair) { var model = pair[0]; var add = pair[1]; var value = model.get(); if (!isNumeric(add) || !isNumeric(value)) { throw new Error(errorMessage); } return [model, value + add]; }) ); } function Ractive$add(keypath, d, options) { var num = isNumber(d) ? d : 1; var opts = isObjectType(d) ? d : options; return add(this, keypath, num, opts); } function immediate(value) { var result = Promise.resolve(value); defineProperty(result, 'stop', { value: noop }); return result; } var linear = easing.linear; function getOptions(options, instance) { options = options || {}; var easing$$1; if (options.easing) { easing$$1 = isFunction(options.easing) ? options.easing : instance.easing[options.easing]; } return { easing: easing$$1 || linear, duration: 'duration' in options ? options.duration : 400, complete: options.complete || noop, step: options.step || noop, interpolator: options.interpolator }; } function animate(ractive, model, to, options) { options = getOptions(options, ractive); var from = model.get(); // don't bother animating values that stay the same if (isEqual(from, to)) { options.complete(options.to); return immediate(to); } var interpolator = interpolate(from, to, ractive, options.interpolator); // if we can't interpolate the value, set it immediately if (!interpolator) { runloop.start(); model.set(to); runloop.end(); return immediate(to); } return model.animate(from, to, options, interpolator); } function Ractive$animate(keypath, to, options) { if (isObjectType(keypath)) { var keys$$1 = keys(keypath); throw new Error(("ractive.animate(...) no longer supports objects. Instead of ractive.animate({\n " + (keys$$1.map(function (key) { return ("'" + key + "': " + (keypath[key])); }).join('\n ')) + "\n}, {...}), do\n\n" + (keys$$1.map(function (key) { return ("ractive.animate('" + key + "', " + (keypath[key]) + ", {...});"); }).join('\n')) + "\n")); } return animate(this, this.viewmodel.joinAll(splitKeypath(keypath)), to, options); } function enqueue(ractive, event) { if (ractive.event) { ractive._eventQueue.push(ractive.event); } ractive.event = event; } function dequeue(ractive) { if (ractive._eventQueue.length) { ractive.event = ractive._eventQueue.pop(); } else { ractive.event = null; } } var initStars = {}; var bubbleStars = {}; // cartesian product of name parts and stars // adjusted appropriately for special cases function variants(name, initial) { var map = initial ? initStars : bubbleStars; if (map[name]) { return map[name]; } var parts = name.split('.'); var result = []; var base = false; // initial events the implicit namespace of 'this' if (initial) { parts.unshift('this'); base = true; } // use max - 1 bits as a bitmap to pick a part or a * // need to skip the full star case if the namespace is synthetic var max = Math.pow(2, parts.length) - (initial ? 1 : 0); for (var i = 0; i < max; i++) { var join = []; for (var j = 0; j < parts.length; j++) { join.push(1 & (i >> j) ? '*' : parts[j]); } result.unshift(join.join('.')); } if (base) { // include non-this-namespaced versions if (parts.length > 2) { result.push.apply(result, variants(name, false)); } else { result.push('*'); result.push(name); } } map[name] = result; return result; } function fireEvent(ractive, eventName, context, args) { if ( args === void 0 ) args = []; if (!eventName) { return; } context.name = eventName; args.unshift(context); var eventNames = ractive._nsSubs ? variants(eventName, true) : ['*', eventName]; return fireEventAs(ractive, eventNames, context, args, true); } function fireEventAs(ractive, eventNames, context, args, initialFire) { if ( initialFire === void 0 ) initialFire = false; var bubble = true; if (initialFire || ractive._nsSubs) { enqueue(ractive, context); var i = eventNames.length; while (i--) { if (eventNames[i] in ractive._subs) { bubble = notifySubscribers(ractive, ractive._subs[eventNames[i]], context, args) && bubble; } } dequeue(ractive); } if (ractive.parent && bubble) { if (initialFire && ractive.component) { var fullName = ractive.component.name + '.' + eventNames[eventNames.length - 1]; eventNames = variants(fullName, false); if (context && !context.component) { context.component = ractive; } } bubble = fireEventAs(ractive.parent, eventNames, context, args); } return bubble; } function notifySubscribers(ractive, subscribers, context, args) { var originalEvent = null; var stopEvent = false; // subscribers can be modified inflight, e.g. "once" functionality // so we need to copy to make sure everyone gets called subscribers = subscribers.slice(); for (var i = 0, len = subscribers.length; i < len; i += 1) { if (!subscribers[i].off && subscribers[i].handler.apply(ractive, args) === false) { stopEvent = true; } } if (context && stopEvent && (originalEvent = context.event)) { originalEvent.preventDefault && originalEvent.preventDefault(); originalEvent.stopPropagation && originalEvent.stopPropagation(); } return !stopEvent; } var Hook = function Hook(event) { this.event = event; this.method = 'on' + event; }; Hook.prototype.fire = function fire (ractive, arg) { var context = getRactiveContext(ractive); var method = this.method; if (ractive[method]) { arg ? ractive[method](context, arg) : ractive[method](context); } fireEvent(ractive, this.event, context, arg ? [arg, ractive] : [ractive]); }; function getChildQueue(queue, ractive) { return queue[ractive._guid] || (queue[ractive._guid] = []); } function fire(hookQueue, ractive) { var childQueue = getChildQueue(hookQueue.queue, ractive); hookQueue.hook.fire(ractive); // queue is "live" because components can end up being // added while hooks fire on parents that modify data values. while (childQueue.length) { fire(hookQueue, childQueue.shift()); } delete hookQueue.queue[ractive._guid]; } var HookQueue = function HookQueue(event) { this.hook = new Hook(event); this.inProcess = {}; this.queue = {}; }; var HookQueue__proto__ = HookQueue.prototype; HookQueue__proto__.begin = function begin (ractive) { this.inProcess[ractive._guid] = true; }; HookQueue__proto__.end = function end (ractive) { var parent = ractive.parent; // If this is *isn't* a child of a component that's in process, // it should call methods or fire at this point if (!parent || !this.inProcess[parent._guid]) { fire(this, ractive); } else { // elsewise, handoff to parent to fire when ready getChildQueue(this.queue, parent).push(ractive); } delete this.inProcess[ractive._guid]; }; var hooks = {}; [ 'construct', 'config', 'attachchild', 'detach', 'detachchild', 'insert', 'complete', 'reset', 'render', 'unrendering', 'unrender', 'teardown', 'destruct', 'update' ].forEach(function (hook) { hooks[hook] = new Hook(hook); }); hooks.init = new HookQueue('init'); function findAnchors(fragment, name) { if ( name === void 0 ) name = null; var res = []; findAnchorsIn(fragment, name, res); return res; } function findAnchorsIn(item, name, result) { if (item.isAnchor) { if (!name || item.name === name) { result.push(item); } } else if (item.items) { item.items.forEach(function (i) { return findAnchorsIn(i, name, result); }); } else if (item.iterations) { item.iterations.forEach(function (i) { return findAnchorsIn(i, name, result); }); } else if (item.fragment && !item.component) { findAnchorsIn(item.fragment, name, result); } } function updateAnchors(instance, name) { if ( name === void 0 ) name = null; var anchors = findAnchors(instance.fragment, name); var idxs = {}; var children = instance._children.byName; anchors.forEach(function (a) { var name = a.name; if (!(name in idxs)) { idxs[name] = 0; } var idx = idxs[name]; var child = (children[name] || [])[idx]; if (child && child.lastBound !== a) { if (child.lastBound) { child.lastBound.removeChild(child); } a.addChild(child); } idxs[name]++; }); } function unrenderChild(meta) { if (meta.instance.fragment.rendered) { meta.shouldDestroy = true; meta.instance.unrender(); } meta.instance.el = null; } function attachChild(child, options) { if ( options === void 0 ) options = {}; var children = this._children; var idx; if (child.parent && child.parent !== this) { throw new Error( ("Instance " + (child._guid) + " is already attached to a different instance " + (child.parent._guid) + ". Please detach it from the other instance using detachChild first.") ); } else if (child.parent) { throw new Error(("Instance " + (child._guid) + " is already attached to this instance.")); } var meta = { instance: child, ractive: this, name: options.name || child.constructor.name || 'Ractive', target: options.target || false, bubble: bubble, findNextNode: findNextNode }; meta.nameOption = options.name; // child is managing itself if (!meta.target) { meta.up = this.fragment; meta.external = true; } else { var list; if (!(list = children.byName[meta.target])) { list = []; this.set(("@this.children.byName." + (meta.target)), list); } idx = options.prepend ? 0 : options.insertAt !== undefined ? options.insertAt : list.length; } child.parent = this; child.root = this.root; child.component = meta; children.push(meta); var promise = runloop.start(); var rm = child.viewmodel.getRactiveModel(); rm.joinKey('parent', { lastLink: false }).link(this.viewmodel.getRactiveModel()); rm.joinKey('root', { lastLink: false }).link(this.root.viewmodel.getRactiveModel()); hooks.attachchild.fire(child); if (meta.target) { unrenderChild(meta); this.splice(("@this.children.byName." + (meta.target)), idx, 0, meta); updateAnchors(this, meta.target); } else { if (!child.isolated) { child.viewmodel.attached(this.fragment); } } runloop.end(); promise.ractive = child; return promise.then(function () { return child; }); } function bubble() { runloop.addFragment(this.instance.fragment); } function findNextNode() { if (this.anchor) { return this.anchor.findNextNode(); } } function compute(path, computed) { this.computed[path] = computed; if (isString(computed) || isFunction(computed)) { computed = this.computed[path] = { get: computed }; } var keys = splitKeypath(path); if (!~path.indexOf('*')) { var last = keys.pop(); return this.viewmodel.joinAll(keys).compute(last, computed); } else { computed.pattern = new RegExp( '^' + keys .map(function (k) { return k.replace(/\*\*/g, '(.+)').replace(/\*/g, '((?:\\\\.|[^\\.])+)'); }) .join('\\.') + '$' ); } } function Ractive$compute(path, computed) { var promise = runloop.start(); var comp = compute.call(this, path, computed); if (comp) { var keys = splitKeypath(path); if (keys.length === 1 && !comp.isReadonly) { comp.set(this.viewmodel.value[keys[0]]); } var first = keys.reduce(function (a, c) { return a && a.childByKey[c]; }, this.viewmodel); if (first) { first.rebind(comp, first, false); if (first.parent) { delete first.parent.childByKey[first.key]; } fireShuffleTasks(); } } runloop.end(); return promise; } function Ractive$detach() { if (this.isDetached) { return this.el; } if (this.el) { removeFromArray(this.el.__ractive_instances__, this); } this.el = this.fragment.detach(); this.isDetached = true; hooks.detach.fire(this); return this.el; } function detachChild(child) { var children = this._children; var meta, index; var i = children.length; while (i--) { if (children[i].instance === child) { index = i; meta = children[i]; break; } } if (!meta || child.parent !== this) { throw new Error(("Instance " + (child._guid) + " is not attached to this instance.")); } var promise = runloop.start(); if (meta.anchor) { meta.anchor.removeChild(meta); } if (!child.isolated) { child.viewmodel.detached(); } children.splice(index, 1); if (meta.target) { this.splice( ("@this.children.byName." + (meta.target)), children.byName[meta.target].indexOf(meta), 1 ); updateAnchors(this, meta.target); } var rm = child.viewmodel.getRactiveModel(); rm.joinKey('parent', { lastLink: false }).unlink(); rm.joinKey('root', { lastLink: false }).link(rm); child.root = child; child.parent = null; child.component = null; hooks.detachchild.fire(child); runloop.end(); promise.ractive = child; return promise.then(function () { return child; }); } function Ractive$find(selector, options) { var this$1 = this; if ( options === void 0 ) options = {}; if (!this.rendered) { throw new Error( ("Cannot call ractive.find('" + selector + "') unless instance is rendered to the DOM") ); } var node = this.fragment.find(selector, options); if (node) { return node; } if (options.remote) { for (var i = 0; i < this._children.length; i++) { if (!this$1._children[i].instance.fragment.rendered) { continue; } node = this$1._children[i].instance.find(selector, options); if (node) { return node; } } } } function Ractive$findAll(selector, options) { if ( options === void 0 ) options = {}; if (!this.rendered) { throw new Error( ("Cannot call ractive.findAll('" + selector + "', ...) unless instance is rendered to the DOM") ); } if (!isArray(options.result)) { options.result = []; } this.fragment.findAll(selector, options); if (options.remote) { // seach non-fragment children this._children.forEach(function (c) { if (!c.target && c.instance.fragment && c.instance.fragment.rendered) { c.instance.findAll(selector, options); } }); } return options.result; } function Ractive$findAllComponents(selector, options) { if (!options && isObjectType(selector)) { options = selector; selector = ''; } options = options || {}; if (!isArray(options.result)) { options.result = []; } this.fragment.findAllComponents(selector, options); if (options.remote) { // search non-fragment children this._children.forEach(function (c) { if (!c.target && c.instance.fragment && c.instance.fragment.rendered) { if (!selector || c.name === selector) { options.result.push(c.instance); } c.instance.findAllComponents(selector, options); } }); } return options.result; } function Ractive$findComponent(selector, options) { var this$1 = this; if ( options === void 0 ) options = {}; if (isObjectType(selector)) { options = selector; selector = ''; } var child = this.fragment.findComponent(selector, options); if (child) { return child; } if (options.remote) { if (!selector && this._children.length) { return this._children[0].instance; } for (var i = 0; i < this._children.length; i++) { // skip children that are or should be in an anchor if (this$1._children[i].target) { continue; } if (this$1._children[i].name === selector) { return this$1._children[i].instance; } child = this$1._children[i].instance.findComponent(selector, options); if (child) { return child; } } } } function Ractive$findContainer(selector) { if (this.container) { if (this.container.component && this.container.component.name === selector) { return this.container; } else { return this.container.findContainer(selector); } } return null; } function Ractive$findParent(selector) { if (this.parent) { if (this.parent.component && this.parent.component.name === selector) { return this.parent; } else { return this.parent.findParent(selector); } } return null; } function findElement(start, orComponent, name) { if ( orComponent === void 0 ) orComponent = true; while ( start && (start.type !== ELEMENT || (name && start.name !== name)) && (!orComponent || (start.type !== COMPONENT && start.type !== ANCHOR)) ) { // start is a fragment - look at the owner if (start.owner) { start = start.owner; } else if (start.component) // start is a component or yielder - look at the container { start = start.containerFragment || start.component.up; } else if (start.parent) // start is an item - look at the parent { start = start.parent; } else if (start.up) // start is an item without a parent - look at the parent fragment { start = start.up; } else { start = undefined; } } return start; } // This function takes an array, the name of a mutator method, and the // arguments to call that mutator method with, and returns an array that // maps the old indices to their new indices. // So if you had something like this... // // array = [ 'a', 'b', 'c', 'd' ]; // array.push( 'e' ); // // ...you'd get `[ 0, 1, 2, 3 ]` - in other words, none of the old indices // have changed. If you then did this... // // array.unshift( 'z' ); // // ...the indices would be `[ 1, 2, 3, 4, 5 ]` - every item has been moved // one higher to make room for the 'z'. If you removed an item, the new index // would be -1... // // array.splice( 2, 2 ); // // ...this would result in [ 0, 1, -1, -1, 2, 3 ]. // // This information is used to enable fast, non-destructive shuffling of list // sections when you do e.g. `ractive.splice( 'items', 2, 2 ); function getNewIndices(length, methodName, args) { var newIndices = []; var spliceArguments = getSpliceEquivalent(length, methodName, args); if (!spliceArguments) { return null; // TODO support reverse and sort? } var balance = spliceArguments.length - 2 - spliceArguments[1]; var removeStart = Math.min(length, spliceArguments[0]); var removeEnd = removeStart + spliceArguments[1]; newIndices.startIndex = removeStart; var i; for (i = 0; i < removeStart; i += 1) { newIndices.push(i); } for (; i < removeEnd; i += 1) { newIndices.push(-1); } for (; i < length; i += 1) { newIndices.push(i + balance); } // there is a net shift for the rest of the array starting with index + balance if (balance !== 0) { newIndices.touchedFrom = spliceArguments[0]; } else { newIndices.touchedFrom = length; } return newIndices; } // The pop, push, shift an unshift methods can all be represented // as an equivalent splice function getSpliceEquivalent(length, methodName, args) { switch (methodName) { case 'splice': if (args[0] !== undefined && args[0] < 0) { args[0] = length + Math.max(args[0], -length); } if (isUndefined(args[0])) { args[0] = 0; } while (args.length < 2) { args.push(length - args[0]); } if (!isNumber(args[1])) { args[1] = length - args[0]; } // ensure we only remove elements that exist args[1] = Math.min(args[1], length - args[0]); return args; case 'sort': case 'reverse': return null; case 'pop': if (length) { return [length - 1, 1]; } return [0, 0]; case 'push': return [length, 0].concat(args); case 'shift': return [0, length ? 1 : 0]; case 'unshift': return [0, 0].concat(args); } } var arrayProto = Array.prototype; function makeArrayMethod(methodName) { function path(keypath) { var args = [], len = arguments.length - 1; while ( len-- > 0 ) args[ len ] = arguments[ len + 1 ]; return model(this.viewmodel.joinAll(splitKeypath(keypath)), args); } function model(mdl, args) { var array = mdl.get(); if (!isArray(array)) { if (isUndefined(array)) { array = []; var result$1 = arrayProto[methodName].apply(array, args); var promise$1 = runloop.start().then(function () { return result$1; }); mdl.set(array); runloop.end(); return promise$1; } else { throw new Error( ("shuffle array method " + methodName + " called on non-array at " + (mdl.getKeypath())) ); } } var newIndices = getNewIndices(array.length, methodName, args); var result = arrayProto[methodName].apply(array, args); var promise = runloop.start().then(function () { return result; }); promise.result = result; if (newIndices) { if (mdl.shuffle) { mdl.shuffle(newIndices); } else { // it's a computation, which don't have a shuffle, so just invalidate mdl.mark(); } } else { mdl.set(result); } runloop.end(); return promise; } return { path: path, model: model }; } function update$1(ractive, model, options) { // if the parent is wrapped, the adaptor will need to be updated before // updating on this keypath if (model.parent && model.parent.wrapper) { model.parent.adapt(); } var promise = runloop.start(); model.mark(options && options.force); // notify upstream of changes model.notifyUpstream(); runloop.end(); hooks.update.fire(ractive, model); return promise; } function Ractive$update(keypath, options) { var opts, path; if (isString(keypath)) { path = splitKeypath(keypath); opts = options; } else { opts = keypath; } return update$1(this, path ? this.viewmodel.joinAll(path) : this.viewmodel, opts); } var modelPush = makeArrayMethod('push').model; var modelPop = makeArrayMethod('pop').model; var modelShift = makeArrayMethod('shift').model; var modelUnshift = makeArrayMethod('unshift').model; var modelSort = makeArrayMethod('sort').model; var modelSplice = makeArrayMethod('splice').model; var modelReverse = makeArrayMethod('reverse').model; var ContextData = (function (Model) { function ContextData(options) { Model.call(this, null, null); this.isRoot = true; this.root = this; this.value = {}; this.ractive = options.ractive; this.adaptors = []; this.context = options.context; } if ( Model ) ContextData.__proto__ = Model; var ContextData__proto__ = ContextData.prototype = Object.create( Model && Model.prototype ); ContextData__proto__.constructor = ContextData; ContextData__proto__.getKeypath = function getKeypath () { return '@context.data'; }; ContextData__proto__.rebound = function rebound () {}; return ContextData; }(Model)); var Context = function Context(fragment, element) { this.fragment = fragment; this.element = element || findElement(fragment); this.node = this.element && this.element.node; this.ractive = fragment.ractive; this.root = this; }; var Context__proto__ = Context.prototype; var prototypeAccessors = { decorators: {},_data: {} }; prototypeAccessors.decorators.get = function () { var items = {}; if (!this.element) { return items; } this.element.decorators.forEach(function (d) { return (items[d.name] = d.handle); }); return items; }; prototypeAccessors._data.get = function () { return ( this.model || (this.root.model = new ContextData({ ractive: this.ractive, context: this.root })) ); }; // the usual mutation suspects Context__proto__.add = function add (keypath, d, options) { var num = isNumber(d) ? +d : 1; var opts = isObjectType(d) ? d : options; return set( build$1(this, keypath, num).map(function (pair) { var model = pair[0]; var val = pair[1]; var value = model.get(); if (!isNumeric(val) || !isNumeric(value)) { throw new Error('Cannot add non-numeric value'); } return [model, value + val]; }), opts ); }; Context__proto__.animate = function animate$1 (keypath, value, options) { var model = findModel(this, keypath).model; return animate(this.ractive, model, value, options); }; Context__proto__.find = function find (selector) { return this.fragment.find(selector); }; Context__proto__.findAll = function findAll (selector) { var result = []; this.fragment.findAll(selector, { result: result }); return result; }; Context__proto__.findAllComponents = function findAllComponents (selector) { var result = []; this.fragment.findAllComponents(selector, { result: result }); return result; }; Context__proto__.findComponent = function findComponent (selector) { return this.fragment.findComponent(selector); }; // get relative keypaths and values Context__proto__.get = function get (keypath) { if (!keypath) { return this.fragment.findContext().get(true); } var ref = findModel(this, keypath); var model = ref.model; return model ? model.get(true) : undefined; }; Context__proto__.getParent = function getParent (component) { var fragment = this.fragment; if (!fragment.parent && component) { fragment = fragment.componentParent; } else { if (fragment.context) { fragment = findParentWithContext(fragment.parent); } else { fragment = findParentWithContext(fragment.parent); if (fragment) { if (!fragment.parent && component) { fragment = fragment.componentParent; } else { fragment = findParentWithContext(fragment.parent); } } } } if (!fragment || fragment === this.fragment) { return; } else { return fragment.getContext(); } }; Context__proto__.hasListener = function hasListener (name, bubble) { // if the owner is a component, start there because the nearest element // may exist outside of the immediate context (yield) var el = this.fragment.owner.component ? this.fragment.owner : this.element || this.fragment.owner; var base; do { base = el.component || el; if (base.template.t === ELEMENT) { if (findEvent(base, name)) { return true; } } el = el.up && el.up.owner; if (el && el.component) { el = el.component; } } while (el && bubble); }; Context__proto__.link = function link (source, dest) { var there = findModel(this, source).model; var here = findModel(this, dest).model; var promise = runloop.start(); here.link(there, source); runloop.end(); return promise; }; Context__proto__.listen = function listen (event, handler) { var el = this.element; el.on(event, handler); return { cancel: function cancel() { el.off(event, handler); } }; }; Context__proto__.observe = function observe (keypath, callback, options) { if ( options === void 0 ) options = {}; if (isObject(keypath)) { options = callback || {}; } options.fragment = this.fragment; return this.ractive.observe(keypath, callback, options); }; Context__proto__.observeOnce = function observeOnce (keypath, callback, options) { if ( options === void 0 ) options = {}; if (isObject(keypath)) { options = callback || {}; } options.fragment = this.fragment; return this.ractive.observeOnce(keypath, callback, options); }; Context__proto__.pop = function pop (keypath) { return modelPop(findModel(this, keypath).model, []); }; Context__proto__.push = function push (keypath) { var values = [], len = arguments.length - 1; while ( len-- > 0 ) values[ len ] = arguments[ len + 1 ]; return modelPush(findModel(this, keypath).model, values); }; Context__proto__.raise = function raise (name, event) { var args = [], len = arguments.length - 2; while ( len-- > 0 ) args[ len ] = arguments[ len + 2 ]; var el = this.element; var ev; while (el) { if (el.component) { el = el.component; } ev = findEvent(el, name); if (ev) { return ev.fire( ev.element.getContext( event || {}, event && !('original' in event) ? { original: {} } : {} ), args ); } el = el.up && el.up.owner; } }; Context__proto__.readLink = function readLink (keypath, options) { return this.ractive.readLink(this.resolve(keypath), options); }; Context__proto__.resolve = function resolve (path, ractive) { var ref = findModel(this, path); var model = ref.model; var instance = ref.instance; return model ? model.getKeypath(ractive || instance) : path; }; Context__proto__.reverse = function reverse (keypath) { return modelReverse(findModel(this, keypath).model, []); }; Context__proto__.set = function set$2 (keypath, value, options) { return set(build$1(this, keypath, value), options); }; Context__proto__.shift = function shift (keypath) { return modelShift(findModel(this, keypath).model, []); }; Context__proto__.splice = function splice (keypath, index, drop) { var add = [], len = arguments.length - 3; while ( len-- > 0 ) add[ len ] = arguments[ len + 3 ]; add.unshift(index, drop); return modelSplice(findModel(this, keypath).model, add); }; Context__proto__.sort = function sort (keypath) { return modelSort(findModel(this, keypath).model, []); }; Context__proto__.subtract = function subtract (keypath, d, options) { var num = isNumber(d) ? d : 1; var opts = isObjectType(d) ? d : options; return set( build$1(this, keypath, num).map(function (pair) { var model = pair[0]; var val = pair[1]; var value = model.get(); if (!isNumeric(val) || !isNumeric(value)) { throw new Error('Cannot add non-numeric value'); } return [model, value - val]; }), opts ); }; Context__proto__.toggle = function toggle (keypath, options) { var ref = findModel(this, keypath); var model = ref.model; return set([[model, !model.get()]], options); }; Context__proto__.unlink = function unlink (dest) { var here = findModel(this, dest).model; var promise = runloop.start(); if (here.owner && here.owner._link) { here.owner.unlink(); } runloop.end(); return promise; }; Context__proto__.unlisten = function unlisten (event, handler) { this.element.off(event, handler); }; Context__proto__.unshift = function unshift (keypath) { var add = [], len = arguments.length - 1; while ( len-- > 0 ) add[ len ] = arguments[ len + 1 ]; return modelUnshift(findModel(this, keypath).model, add); }; Context__proto__.update = function update (keypath, options) { return update$1(this.ractive, findModel(this, keypath).model, options); }; Context__proto__.updateModel = function updateModel (keypath, cascade) { var ref = findModel(this, keypath); var model = ref.model; var promise = runloop.start(); model.updateFromBindings(cascade); runloop.end(); return promise; }; // two-way binding related helpers Context__proto__.isBound = function isBound () { var ref = this.getBindingModel(this); var model = ref.model; return !!model; }; Context__proto__.getBindingPath = function getBindingPath (ractive) { var ref = this.getBindingModel(this); var model = ref.model; var instance = ref.instance; if (model) { return model.getKeypath(ractive || instance); } }; Context__proto__.getBinding = function getBinding () { var ref = this.getBindingModel(this); var model = ref.model; if (model) { return model.get(true); } }; Context__proto__.getBindingModel = function getBindingModel (ctx) { var el = ctx.element; return { model: el.binding && el.binding.model, instance: el.up.ractive }; }; Context__proto__.setBinding = function setBinding (value) { var ref = this.getBindingModel(this); var model = ref.model; return set([[model, value]]); }; Object.defineProperties( Context__proto__, prototypeAccessors ); Context.forRactive = getRactiveContext; // circular deps are fun extern.Context = Context; // TODO: at some point perhaps this could support relative * keypaths? function build$1(ctx, keypath, value) { var sets = []; // set multiple keypaths in one go if (isObject(keypath)) { for (var k in keypath) { if (hasOwn(keypath, k)) { sets.push([findModel(ctx, k).model, keypath[k]]); } } } else { // set a single keypath sets.push([findModel(ctx, keypath).model, value]); } return sets; } function findModel(ctx, path) { var frag = ctx.fragment; if (!isString(path)) { return { model: frag.findContext(), instance: path }; } return { model: resolveReference(frag, path), instance: frag.ractive }; } function findEvent(el, name) { return el.events && el.events.find && el.events.find(function (e) { return ~e.template.n.indexOf(name); }); } function Ractive$fire(eventName) { var args = [], len = arguments.length - 1; while ( len-- > 0 ) args[ len ] = arguments[ len + 1 ]; var ctx; // watch for reproxy if (args[0] instanceof Context) { var proto = args.shift(); ctx = create(proto); assign(ctx, proto); } else if (isObjectType(args[0]) && (args[0] === null || args[0].constructor === Object)) { ctx = Context.forRactive(this, args.shift()); } else { ctx = Context.forRactive(this); } return fireEvent(this, eventName, ctx, args); } function Ractive$get(keypath, opts) { if (!isString(keypath)) { return this.viewmodel.get(true, keypath); } var keys = splitKeypath(keypath); var key = keys[0]; var model; if (!this.viewmodel.has(key)) { // if this is an inline component, we may need to create // an implicit mapping if (this.component && !this.isolated) { model = resolveReference(this.fragment || new FakeFragment(this), key); } } model = this.viewmodel.joinAll(keys); return model.get(true, opts); } var query = doc && doc.querySelector; function getContext$1(node) { if (isString(node) && query) { node = query.call(document, node); } var instances; if (node) { if (node._ractive) { return node._ractive.proxy.getContext(); } else if ((instances = node.__ractive_instances__)) { if (instances.length === 1) { return getRactiveContext(instances[0]); } } else { return getContext$1(node.parentNode); } } } function getContext$2(node, options) { if (!node) { return getRactiveContext(this); } if (isString(node)) { node = this.find(node, options); } return getContext$1(node); } var html = 'http://www.w3.org/1999/xhtml'; var mathml = 'http://www.w3.org/1998/Math/MathML'; var svg$1 = 'http://www.w3.org/2000/svg'; var xlink = 'http://www.w3.org/1999/xlink'; var xml = 'http://www.w3.org/XML/1998/namespace'; var xmlns = 'http://www.w3.org/2000/xmlns'; var namespaces = { html: html, mathml: mathml, svg: svg$1, xlink: xlink, xml: xml, xmlns: xmlns }; var createElement; var matches; var div; var methodNames; var unprefixed; var prefixed; var i; var j; var makeFunction; // Test for SVG support if (!svg) { /* istanbul ignore next */ createElement = function (type, ns, extend) { if (ns && ns !== html) { throw "This browser does not support namespaces other than http://www.w3.org/1999/xhtml. The most likely cause of this error is that you're trying to render SVG in an older browser. See http://ractive.js.org/support/#svgs for more information"; } return extend ? doc.createElement(type, extend) : doc.createElement(type); }; } else { createElement = function (type, ns, extend) { if (!ns || ns === html) { return extend ? doc.createElement(type, extend) : doc.createElement(type); } return extend ? doc.createElementNS(ns, type, extend) : doc.createElementNS(ns, type); }; } function createDocumentFragment() { return doc.createDocumentFragment(); } function getElement(input) { var output; if (!input || typeof input === 'boolean') { return; } /* istanbul ignore next */ if (!win || !doc || !input) { return null; } // We already have a DOM node - no work to do. (Duck typing alert!) if (input.nodeType) { return input; } // Get node from string if (isString(input)) { // try ID first output = doc.getElementById(input); // then as selector, if possible if (!output && doc.querySelector) { try { output = doc.querySelector(input); } catch (e) { /* this space intentionally left blank */ } } // did it work? if (output && output.nodeType) { return output; } } // If we've been given a collection (jQuery, Zepto etc), extract the first item if (input[0] && input[0].nodeType) { return input[0]; } return null; } if (!isClient) { matches = null; } else { div = createElement('div'); methodNames = ['matches', 'matchesSelector']; makeFunction = function(methodName) { return function(node, selector) { return node[methodName](selector); }; }; i = methodNames.length; while (i-- && !matches) { unprefixed = methodNames[i]; if (div[unprefixed]) { matches = makeFunction(unprefixed); } else { j = vendors.length; while (j--) { prefixed = vendors[i] + unprefixed.substr(0, 1).toUpperCase() + unprefixed.substring(1); if (div[prefixed]) { matches = makeFunction(prefixed); break; } } } } // IE8... and apparently phantom some? /* istanbul ignore next */ if (!matches) { matches = function(node, selector) { var parentNode, i; parentNode = node.parentNode; if (!parentNode) { // empty dummy <div> div.innerHTML = ''; parentNode = div; node = node.cloneNode(); div.appendChild(node); } var nodes = parentNode.querySelectorAll(selector); i = nodes.length; while (i--) { if (nodes[i] === node) { return true; } } return false; }; } } function detachNode(node) { // stupid ie // eslint-disable-next-line valid-typeof if (node && typeof node.parentNode !== 'unknown' && node.parentNode) { node.parentNode.removeChild(node); } return node; } function safeToStringValue(value) { return value == null || (isNumber(value) && isNaN(value)) || !value.toString ? '' : '' + value; } function safeAttributeString(string) { return safeToStringValue(string) .replace(/&/g, '&amp;') .replace(/"/g, '&quot;') .replace(/'/g, '&#39;'); } function Ractive$insert(target, anchor) { if (!this.fragment.rendered) { // TODO create, and link to, documentation explaining this throw new Error( 'The API has changed - you must call `ractive.render(target[, anchor])` to render your Ractive instance. Once rendered you can use `ractive.insert()`.' ); } target = getElement(target); anchor = getElement(anchor) || null; if (!target) { throw new Error('You must specify a valid target to insert into'); } target.insertBefore(this.detach(), anchor); this.el = target; (target.__ractive_instances__ || (target.__ractive_instances__ = [])).push(this); this.isDetached = false; fireInsertHook(this); } function fireInsertHook(ractive) { hooks.insert.fire(ractive); ractive.findAllComponents('*').forEach(function (child) { fireInsertHook(child.instance); }); } function link(there, here, options) { var model; var target = (options && (options.ractive || options.instance)) || this; // may need to allow a mapping to resolve implicitly var sourcePath = splitKeypath(there); if (!target.viewmodel.has(sourcePath[0]) && target.component) { model = resolveReference(target.component.up, sourcePath[0]); model = model.joinAll(sourcePath.slice(1)); } var src = model || target.viewmodel.joinAll(sourcePath); var dest = this.viewmodel.joinAll(splitKeypath(here), { lastLink: false }); if (isUpstream(src, dest) || isUpstream(dest, src)) { throw new Error('A keypath cannot be linked to itself.'); } var promise = runloop.start(); dest.link(src, (options && options.keypath) || there); runloop.end(); return promise; } function isUpstream(check, start) { var model = start; while (model) { if (model === check || model.owner === check) { return true; } model = model.target || model.parent; } } var Observer = function Observer(ractive, model, callback, options) { this.context = options.context || ractive; this.callback = callback; this.ractive = ractive; this.keypath = options.keypath; this.options = options; if (model) { this.resolved(model); } if (isFunction(options.old)) { this.oldContext = create(ractive); this.oldFn = options.old; } if (options.init !== false) { this.dirty = true; this.dispatch(); } else { updateOld(this); } this.dirty = false; }; var Observer__proto__ = Observer.prototype; Observer__proto__.cancel = function cancel () { this.cancelled = true; if (this.model) { this.model.unregister(this); } else { this.resolver.unbind(); } removeFromArray(this.ractive._observers, this); }; Observer__proto__.dispatch = function dispatch () { if (!this.cancelled) { this.callback.call(this.context, this.newValue, this.oldValue, this.keypath); updateOld(this, true); this.dirty = false; } }; Observer__proto__.handleChange = function handleChange () { var this$1 = this; if (!this.dirty) { var newValue = this.model.get(); if (isEqual(newValue, this.oldValue)) { return; } this.newValue = newValue; if (this.options.strict && this.newValue === this.oldValue) { return; } runloop.addObserver(this, this.options.defer); this.dirty = true; if (this.options.once) { runloop.scheduleTask(function () { return this$1.cancel(); }); } } else { // make sure the newValue stays updated in case this observer gets touched multiple times in one loop this.newValue = this.model.get(); } }; Observer__proto__.rebind = function rebind (next, previous) { var this$1 = this; next = rebindMatch(this.keypath, next, previous); if (next === this.model) { return false; } if (this.model) { this.model.unregister(this); } if (next) { next.addShuffleTask(function () { return this$1.resolved(next); }); } }; Observer__proto__.resolved = function resolved (model) { this.model = model; this.oldValue = undefined; this.newValue = model.get(); model.register(this); }; function updateOld(observer, fresh) { var next = fresh ? observer.model ? observer.model.get() : observer.newValue : observer.newValue; observer.oldValue = observer.oldFn ? observer.oldFn.call(observer.oldContext, undefined, next, observer.keypath) : next; } var star$1 = /\*+/g; var PatternObserver = function PatternObserver(ractive, baseModel, keys$$1, callback, options) { var this$1 = this; this.context = options.context || ractive; this.ractive = ractive; this.baseModel = baseModel; this.keys = keys$$1; this.callback = callback; var pattern = keys$$1.join('\\.').replace(star$1, '(.+)'); var baseKeypath = (this.baseKeypath = baseModel.getKeypath(ractive)); this.pattern = new RegExp(("^" + (baseKeypath ? baseKeypath + '\\.' : '') + pattern + "$")); this.recursive = keys$$1.length === 1 && keys$$1[0] === '**'; if (this.recursive) { this.keys = ['*']; } if (options.old) { this.oldContext = create(ractive); this.oldFn = options.old; } this.oldValues = {}; this.newValues = {}; this.defer = options.defer; this.once = options.once; this.strict = options.strict; this.dirty = false; this.changed = []; this.partial = false; this.links = options.links; var models = baseModel.findMatches(this.keys); models.forEach(function (model) { this$1.newValues[model.getKeypath(this$1.ractive)] = model.get(); }); if (options.init !== false) { this.dispatch(); } else { updateOld$1(this, this.newValues); } baseModel.registerPatternObserver(this); }; var PatternObserver__proto__ = PatternObserver.prototype; PatternObserver__proto__.cancel = function cancel () { this.baseModel.unregisterPatternObserver(this); removeFromArray(this.ractive._observers, this); }; PatternObserver__proto__.dispatch = function dispatch () { var this$1 = this; var newValues = this.newValues; this.newValues = {}; keys(newValues).forEach(function (keypath) { var newValue = newValues[keypath]; var oldValue = this$1.oldValues[keypath]; if (this$1.strict && newValue === oldValue) { return; } if (isEqual(newValue, oldValue)) { return; } var args = [newValue, oldValue, keypath]; if (keypath) { var wildcards = this$1.pattern.exec(keypath); if (wildcards) { args = args.concat(wildcards.slice(1)); } } this$1.callback.apply(this$1.context, args); }); updateOld$1(this, newValues, this.partial); this.dirty = false; }; PatternObserver__proto__.notify = function notify (key) { this.changed.push(key); }; PatternObserver__proto__.shuffle = function shuffle (newIndices) { var this$1 = this; if (!isArray(this.baseModel.value)) { return; } var max = this.baseModel.value.length; for (var i = 0; i < newIndices.length; i++) { if (newIndices[i] === -1 || newIndices[i] === i) { continue; } this$1.changed.push([i]); } for (var i$1 = newIndices.touchedFrom; i$1 < max; i$1++) { this$1.changed.push([i$1]); } }; PatternObserver__proto__.handleChange = function handleChange () { var this$1 = this; if (!this.dirty || this.changed.length) { if (!this.dirty) { this.newValues = {}; } if (!this.changed.length) { this.baseModel.findMatches(this.keys).forEach(function (model) { var keypath = model.getKeypath(this$1.ractive); this$1.newValues[keypath] = model.get(); }); this.partial = false; } else { var count = 0; if (this.recursive) { this.changed.forEach(function (keys$$1) { var model = this$1.baseModel.joinAll(keys$$1); if (model.isLink && !this$1.links) { return; } count++; this$1.newValues[model.getKeypath(this$1.ractive)] = model.get(); }); } else { var ok = this.baseModel.isRoot ? this.changed.map(function (keys$$1) { return keys$$1.map(escapeKey).join('.'); }) : this.changed.map(function (keys$$1) { return this$1.baseKeypath + '.' + keys$$1.map(escapeKey).join('.'); }); this.baseModel.findMatches(this.keys).forEach(function (model) { var keypath = model.getKeypath(this$1.ractive); var check = function (k) { return ( (k.indexOf(keypath) === 0 && (k.length === keypath.length || k[keypath.length] === '.')) || (keypath.indexOf(k) === 0 && (k.length === keypath.length || keypath[k.length] === '.')) ); }; // is this model on a changed keypath? if (ok.filter(check).length) { count++; this$1.newValues[keypath] = model.get(); } }); } // no valid change triggered, so bail to avoid breakage if (!count) { return; } this.partial = true; } runloop.addObserver(this, this.defer); this.dirty = true; this.changed.length = 0; if (this.once) { this.cancel(); } } }; function updateOld$1(observer, vals, partial) { var olds = observer.oldValues; if (observer.oldFn) { if (!partial) { observer.oldValues = {}; } keys(vals).forEach(function (k) { var args = [olds[k], vals[k], k]; var parts = observer.pattern.exec(k); if (parts) { args.push.apply(args, parts.slice(1)); } observer.oldValues[k] = observer.oldFn.apply(observer.oldContext, args); }); } else { if (partial) { keys(vals).forEach(function (k) { return (olds[k] = vals[k]); }); } else { observer.oldValues = vals; } } } function negativeOne() { return -1; } var ArrayObserver = function ArrayObserver(ractive, model, callback, options) { this.ractive = ractive; this.model = model; this.keypath = model.getKeypath(); this.callback = callback; this.options = options; this.pending = null; model.register(this); if (options.init !== false) { this.sliced = []; this.shuffle([]); this.dispatch(); } else { this.sliced = this.slice(); } }; var ArrayObserver__proto__ = ArrayObserver.prototype; ArrayObserver__proto__.cancel = function cancel () { this.model.unregister(this); removeFromArray(this.ractive._observers, this); }; ArrayObserver__proto__.dispatch = function dispatch () { this.callback(this.pending); this.pending = null; if (this.options.once) { this.cancel(); } }; ArrayObserver__proto__.handleChange = function handleChange (path) { if (this.pending) { // post-shuffle runloop.addObserver(this, this.options.defer); } else if (!path) { // entire array changed this.shuffle(this.sliced.map(negativeOne)); this.handleChange(); } }; ArrayObserver__proto__.shuffle = function shuffle (newIndices) { var this$1 = this; var newValue = this.slice(); var inserted = []; var deleted = []; var start; var hadIndex = {}; newIndices.forEach(function (newIndex, oldIndex) { hadIndex[newIndex] = true; if (newIndex !== oldIndex && isUndefined(start)) { start = oldIndex; } if (newIndex === -1) { deleted.push(this$1.sliced[oldIndex]); } }); if (isUndefined(start)) { start = newIndices.length; } var len = newValue.length; for (var i = 0; i < len; i += 1) { if (!hadIndex[i]) { inserted.push(newValue[i]); } } this.pending = { inserted: inserted, deleted: deleted, start: start }; this.sliced = newValue; }; ArrayObserver__proto__.slice = function slice () { var value = this.model.get(); return isArray(value) ? value.slice() : []; }; function observe(keypath, callback, options) { var this$1 = this; var observers = []; var map; var opts; if (isObject(keypath)) { map = keypath; opts = callback || {}; } else { if (isFunction(keypath)) { map = { '': keypath }; opts = callback || {}; } else { map = {}; map[keypath] = callback; opts = options || {}; } } var silent = false; keys(map).forEach(function (keypath) { var callback = map[keypath]; var caller = function() { var args = [], len = arguments.length; while ( len-- ) args[ len ] = arguments[ len ]; if (silent) { return; } return callback.apply(this, args); }; var keypaths = keypath.split(' '); if (keypaths.length > 1) { keypaths = keypaths.filter(function (k) { return k; }); } keypaths.forEach(function (keypath) { opts.keypath = keypath; var observer = createObserver(this$1, keypath, caller, opts); if (observer) { observers.push(observer); } }); }); // add observers to the Ractive instance, so they can be // cancelled on ractive.teardown() this._observers.push.apply(this._observers, observers); return { cancel: function () { return observers.forEach(function (o) { return o.cancel(); }); }, isSilenced: function () { return silent; }, silence: function () { return (silent = true); }, resume: function () { return (silent = false); } }; } function createObserver(ractive, keypath, callback, options) { var keys$$1 = splitKeypath(keypath); var wildcardIndex = keys$$1.indexOf('*'); if (!~wildcardIndex) { wildcardIndex = keys$$1.indexOf('**'); } options.fragment = options.fragment || ractive.fragment; var model; if (!options.fragment) { model = ractive.viewmodel.joinKey(keys$$1[0]); } else { // .*.whatever relative wildcard is a special case because splitkeypath doesn't handle the leading . if (~keys$$1[0].indexOf('.*')) { model = options.fragment.findContext(); wildcardIndex = 0; keys$$1[0] = keys$$1[0].slice(1); } else { model = wildcardIndex === 0 ? options.fragment.findContext() : resolveReference(options.fragment, keys$$1[0]); } } // the model may not exist key if (!model) { model = ractive.viewmodel.joinKey(keys$$1[0]); } if (!~wildcardIndex) { model = model.joinAll(keys$$1.slice(1)); if (options.array) { return new ArrayObserver(ractive, model, callback, options); } else { return new Observer(ractive, model, callback, options); } } else { var double = keys$$1.indexOf('**'); if (~double) { if (double + 1 !== keys$$1.length || ~keys$$1.indexOf('*')) { warnOnceIfDebug( "Recursive observers may only specify a single '**' at the end of the path." ); return; } } model = model.joinAll(keys$$1.slice(1, wildcardIndex)); return new PatternObserver(ractive, model, keys$$1.slice(wildcardIndex), callback, options); } } var onceOptions = { init: false, once: true }; function observeOnce(keypath, callback, options) { if (isObject(keypath) || isFunction(keypath)) { options = assign(callback || {}, onceOptions); return this.observe(keypath, options); } options = assign(options || {}, onceOptions); return this.observe(keypath, callback, options); } var trim = function (str) { return str.trim(); }; var notEmptyString = function (str) { return str !== ''; }; function Ractive$off(eventName, callback) { var this$1 = this; // if no event is specified, remove _all_ event listeners if (!eventName) { this._subs = {}; } else { // Handle multiple space-separated event names var eventNames = eventName .split(' ') .map(trim) .filter(notEmptyString); eventNames.forEach(function (event) { var subs = this$1._subs[event]; // if given a specific callback to remove, remove only it if (subs && callback) { var entry = subs.find(function (s) { return s.callback === callback; }); if (entry) { removeFromArray(subs, entry); entry.off = true; if (event.indexOf('.')) { this$1._nsSubs--; } } } else if (subs) { // otherwise, remove all listeners for this event if (event.indexOf('.')) { this$1._nsSubs -= subs.length; } subs.length = 0; } }); } return this; } function Ractive$on(eventName, callback) { var this$1 = this; // eventName may already be a map var map = isObjectType(eventName) ? eventName : {}; // or it may be a string along with a callback if (isString(eventName)) { map[eventName] = callback; } var silent = false; var events = []; var loop = function ( k ) { var callback$1 = map[k]; var caller = function() { var args = [], len = arguments.length; while ( len-- ) args[ len ] = arguments[ len ]; if (!silent) { return callback$1.apply(this, args); } }; var entry = { callback: callback$1, handler: caller }; if (hasOwn(map, k)) { var names = k .split(' ') .map(trim) .filter(notEmptyString); names.forEach(function (n) { (this$1._subs[n] || (this$1._subs[n] = [])).push(entry); if (n.indexOf('.')) { this$1._nsSubs++; } events.push([n, entry]); }); } }; for (var k in map) loop( k ); return { cancel: function () { return events.forEach(function (e) { return this$1.off(e[0], e[1].callback); }); }, isSilenced: function () { return silent; }, silence: function () { return (silent = true); }, resume: function () { return (silent = false); } }; } function Ractive$once(eventName, handler) { var listener = this.on(eventName, function() { handler.apply(this, arguments); listener.cancel(); }); // so we can still do listener.cancel() manually return listener; } var pop = makeArrayMethod('pop').path; var push = makeArrayMethod('push').path; function readLink(keypath, options) { if ( options === void 0 ) options = {}; var path = splitKeypath(keypath); if (this.viewmodel.has(path[0])) { var model = this.viewmodel.joinAll(path); if (!model.isLink) { return; } while ((model = model.target) && options.canonical !== false) { if (!model.isLink) { break; } } if (model) { return { ractive: model.root.ractive, keypath: model.getKeypath() }; } } } var PREFIX = '/* Ractive.js component styles */'; // Holds current definitions of styles. var styleDefinitions = []; // Flag to tell if we need to update the CSS var isDirty = false; // These only make sense on the browser. See additional setup below. var styleElement = null; var useCssText = null; function addCSS(styleDefinition) { styleDefinitions.push(styleDefinition); isDirty = true; } function applyCSS(force) { var styleElement = style(); // Apply only seems to make sense when we're in the DOM. Server-side renders // can call toCSS to get the updated CSS. if (!styleElement || (!force && !isDirty)) { return; } if (useCssText) { styleElement.styleSheet.cssText = getCSS(null); } else { styleElement.innerHTML = getCSS(null); } isDirty = false; } function getCSS(cssIds) { var filteredStyleDefinitions = cssIds ? styleDefinitions.filter(function (style) { return ~cssIds.indexOf(style.id); }) : styleDefinitions; filteredStyleDefinitions.forEach(function (d) { return (d.applied = true); }); return filteredStyleDefinitions.reduce( function (styles, style) { return ("" + (styles ? (styles + "\n\n/* {" + (style.id) + "} */\n" + (style.styles)) : '')); }, PREFIX ); } function style() { // If we're on the browser, additional setup needed. if (doc && !styleElement) { styleElement = doc.createElement('style'); styleElement.type = 'text/css'; styleElement.setAttribute('data-ractive-css', ''); doc.getElementsByTagName('head')[0].appendChild(styleElement); useCssText = !!styleElement.styleSheet; } return styleElement; } var adaptConfigurator = { extend: function (Parent, proto, options) { proto.adapt = combine(proto.adapt, ensureArray(options.adapt)); }, init: function init() {} }; var remove = /\/\*(?:[\s\S]*?)\*\//g; var escape = /url\(\s*(['"])(?:\\[\s\S]|(?!\1).)*\1\s*\)|url\((?:\\[\s\S]|[^)])*\)|(['"])(?:\\[\s\S]|(?!\2).)*\2/gi; var value = /\0(\d+)/g; // Removes comments and strings from the given CSS to make it easier to parse. // Callback receives the cleaned CSS and a function which can be used to put // the removed strings back in place after parsing is done. function cleanCss(css, callback, additionalReplaceRules) { if ( additionalReplaceRules === void 0 ) additionalReplaceRules = []; var values = []; var reconstruct = function (css) { return css.replace(value, function (match, n) { return values[n]; }); }; css = css.replace(escape, function (match) { return ("\u0000" + (values.push(match) - 1)); }).replace(remove, ''); additionalReplaceRules.forEach(function (pattern) { css = css.replace(pattern, function (match) { return ("\u0000" + (values.push(match) - 1)); }); }); return callback(css, reconstruct); } var selectorsPattern = /(?:^|\}|\{|\x01)\s*([^\{\}\0\x01]+)\s*(?=\{)/g; var importPattern = /@import\s*\([^)]*\)\s*;?/gi; var importEndPattern = /\x01/g; var keyframesDeclarationPattern = /@keyframes\s+[^\{\}]+\s*\{(?:[^{}]+|\{[^{}]+})*}/gi; var selectorUnitPattern = /((?:(?:\[[^\]]+\])|(?:[^\s\+\>~:]))+)((?:::?[^\s\+\>\~\(:]+(?:\([^\)]+\))?)*\s*[\s\+\>\~]?)\s*/g; var excludePattern = /^(?:@|\d+%)/; var dataRvcGuidPattern = /\[data-ractive-css~="\{[a-z0-9-]+\}"]/g; function trim$1(str) { return str.trim(); } function extractString(unit) { return unit.str; } function transformSelector(selector, parent) { var selectorUnits = []; var match; while ((match = selectorUnitPattern.exec(selector))) { selectorUnits.push({ str: match[0], base: match[1], modifiers: match[2] }); } // For each simple selector within the selector, we need to create a version // that a) combines with the id, and b) is inside the id var base = selectorUnits.map(extractString); var transformed = []; var i = selectorUnits.length; while (i--) { var appended = base.slice(); // Pseudo-selectors should go after the attribute selector var unit = selectorUnits[i]; appended[i] = unit.base + parent + unit.modifiers || ''; var prepended = base.slice(); prepended[i] = parent + ' ' + prepended[i]; transformed.push(appended.join(' '), prepended.join(' ')); } return transformed.join(', '); } function transformCss(css, id) { var dataAttr = "[data-ractive-css~=\"{" + id + "}\"]"; var transformed; if (dataRvcGuidPattern.test(css)) { transformed = css.replace(dataRvcGuidPattern, dataAttr); } else { transformed = cleanCss( css, function (css, reconstruct) { css = css .replace(importPattern, '$&\x01') .replace(selectorsPattern, function (match, $1) { // don't transform at-rules and keyframe declarations if (excludePattern.test($1)) { return match; } var selectors = $1.split(',').map(trim$1); var transformed = selectors.map(function (selector) { return transformSelector(selector, dataAttr); }).join(', ') + ' '; return match.replace($1, transformed); }) .replace(importEndPattern, ''); return reconstruct(css); }, [keyframesDeclarationPattern] ); } return transformed; } function s4() { return Math.floor((1 + Math.random()) * 0x10000) .toString(16) .substring(1); } function uuid() { return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4(); } function setCSSData(keypath, value, options) { var opts = isObjectType(keypath) ? value : options; var model = this._cssModel; model.locked = true; var promise = set(build({ viewmodel: model }, keypath, value, true), opts); model.locked = false; var cascade = runloop.start(); this.extensions.forEach(function (e) { var model = e._cssModel; model.mark(); model.downstreamChanged('', 1); }); runloop.end(); applyChanges(this, !opts || opts.apply !== false); return promise.then(function () { return cascade; }); } function applyChanges(component, apply) { var local = recomputeCSS(component); var child = component.extensions .map(function (e) { return applyChanges(e, false); }) .reduce(function (a, c) { return c || a; }, false); if (apply && (local || child)) { var def = component._cssDef; if (!def || (def && def.applied)) { applyCSS(true); } } return local || child; } function recomputeCSS(component) { var css = component.css; if (!isFunction(css)) { return; } var def = component._cssDef; var result = evalCSS(component, css); var styles = def.transform ? transformCss(result, def.id) : result; if (def.styles === styles) { return; } def.styles = styles; return true; } var CSSModel = (function (SharedModel) { function CSSModel(component) { SharedModel.call(this, component.cssData, '@style'); this.component = component; } if ( SharedModel ) CSSModel.__proto__ = SharedModel; var CSSModel__proto__ = CSSModel.prototype = Object.create( SharedModel && SharedModel.prototype ); CSSModel__proto__.constructor = CSSModel; CSSModel__proto__.downstreamChanged = function downstreamChanged (path, depth) { if (this.locked) { return; } var component = this.component; component.extensions.forEach(function (e) { var model = e._cssModel; model.mark(); model.downstreamChanged(path, depth || 1); }); if (!depth) { applyChanges(component, true); } }; return CSSModel; }(SharedModel)); var hasCurly = /\{/; var cssConfigurator = { name: 'css', // Called when creating a new component definition extend: function (Parent, proto, options, Child) { Child._cssIds = gatherIds(Parent); defineProperty(Child, 'cssData', { configurable: true, value: assign(create(Parent.cssData), options.cssData || {}) }); defineProperty(Child, '_cssModel', { configurable: true, value: new CSSModel(Child) }); if (options.css) { initCSS(options, Child, proto); } }, // Called when creating a new component instance init: function (Parent, target, options) { if (!options.css) { return; } warnIfDebug("\nThe css option is currently not supported on a per-instance basis and will be discarded. Instead, we recommend instantiating from a component definition with a css option.\n\nconst Component = Ractive.extend({\n\t...\n\tcss: '/* your css */',\n\t...\n});\n\nconst componentInstance = new Component({ ... })\n\t\t"); } }; function gatherIds(start) { var cmp = start; var ids = []; while (cmp) { if (cmp.prototype.cssId) { ids.push(cmp.prototype.cssId); } cmp = cmp.Parent; } return ids; } function evalCSS(component, css) { if (isString(css)) { return css; } var cssData = component.cssData; var model = component._cssModel; var data = function data(path) { return model.joinAll(splitKeypath(path)).get(); }; data.__proto__ = cssData; var result = css.call(component, data); return isString(result) ? result : ''; } function initCSS(options, target, proto) { var css = options.css === true ? '' : isString(options.css) && !hasCurly.test(options.css) ? getElement(options.css) || options.css : options.css; var cssProp = css; var id = options.cssId || uuid(); if (isObjectType(css)) { css = 'textContent' in css ? css.textContent : css.innerHTML; cssProp = css; } else if (isFunction(css)) { cssProp = css; css = evalCSS(target, css); } var def = { transform: 'noCSSTransform' in options ? !options.noCSSTransform : !options.noCssTransform }; defineProperty(target, '_cssDef', { configurable: true, value: def }); defineProperty(target, 'css', { get: function get() { return cssProp; }, set: function set(next) { cssProp = next; var css = evalCSS(target, cssProp); var styles = def.styles; def.styles = def.transform ? transformCss(css, id) : css; if (def.applied && styles !== def.styles) { applyCSS(true); } } }); def.styles = def.transform ? transformCss(css, id) : css; def.id = proto.cssId = id; target._cssIds.push(id); addCSS(target._cssDef); } function validate(data) { // Warn if userOptions.data is a non-POJO if (data && data.constructor !== Object) { if (isFunction(data)) { // TODO do we need to support this in the new Ractive() case? } else if (!isObjectType(data)) { fatal(("data option must be an object or a function, `" + data + "` is not valid")); } else { warnIfDebug( 'If supplied, options.data should be a plain JavaScript object - using a non-POJO as the root object may work, but is discouraged' ); } } } var dataConfigurator = { name: 'data', extend: function (Parent, proto, options) { var key; var value; // check for non-primitives, which could cause mutation-related bugs if (options.data && isObject(options.data)) { for (key in options.data) { value = options.data[key]; if (value && isObjectType(value)) { if (isObject(value) || isArray(value)) { warnIfDebug("Passing a `data` option with object and array properties to Ractive.extend() is discouraged, as mutating them is likely to cause bugs. Consider using a data function instead:\n\n // this...\n data: function () {\n return {\n myObject: {}\n };\n })\n\n // instead of this:\n data: {\n myObject: {}\n }"); } } } } proto.data = combine$1(proto.data, options.data); }, init: function (Parent, ractive, options) { var result = combine$1(Parent.prototype.data, options.data); if (isFunction(result)) { result = result.call(ractive); } // bind functions to the ractive instance at the top level, // unless it's a non-POJO (in which case alarm bells should ring) if (result && result.constructor === Object) { for (var prop in result) { if (isFunction(result[prop])) { var value = result[prop]; result[prop] = bind(value, ractive); result[prop]._r_unbound = value; } } } return result || {}; }, reset: function reset(ractive) { var result = this.init(ractive.constructor, ractive, ractive.viewmodel); ractive.viewmodel.root.set(result); return true; } }; function emptyData() { return {}; } function combine$1(parentValue, childValue) { validate(childValue); var parentIsFn = isFunction(parentValue); // Very important, otherwise child instance can become // the default data object on Ractive or a component. // then ractive.set() ends up setting on the prototype! if (!childValue && !parentIsFn) { // this needs to be a function so that it can still inherit parent defaults childValue = emptyData; } var childIsFn = isFunction(childValue); // Fast path, where we just need to copy properties from // parent to child if (!parentIsFn && !childIsFn) { return fromProperties(childValue, parentValue); } return function() { var child = childIsFn ? callDataFunction(childValue, this) : childValue; var parent = parentIsFn ? callDataFunction(parentValue, this) : parentValue; return fromProperties(child, parent); }; } function callDataFunction(fn, context) { var data = fn.call(context); if (!data) { return; } if (!isObjectType(data)) { fatal('Data function must return an object'); } if (data.constructor !== Object) { warnOnceIfDebug( 'Data function returned something other than a plain JavaScript object. This might work, but is strongly discouraged' ); } return data; } function fromProperties(primary, secondary) { if (primary && secondary) { for (var key in secondary) { if (!(key in primary)) { primary[key] = secondary[key]; } } return primary; } return primary || secondary; } var templateConfigurator = { name: 'template', extend: function extend(Parent, proto, options) { // only assign if exists if ('template' in options) { var template = options.template; if (isFunction(template)) { proto.template = template; } else { proto.template = parseTemplate(template, proto); } } }, init: function init(Parent, ractive, options) { // TODO because of prototypal inheritance, we might just be able to use // ractive.template, and not bother passing through the Parent object. // At present that breaks the test mocks' expectations var template = 'template' in options ? options.template : Parent.prototype.template; template = template || { v: TEMPLATE_VERSION, t: [] }; if (isFunction(template)) { var fn = template; template = getDynamicTemplate(ractive, fn); ractive._config.template = { fn: fn, result: template }; } template = parseTemplate(template, ractive); // TODO the naming of this is confusing - ractive.template refers to [...], // but Component.prototype.template refers to {v:1,t:[],p:[]}... // it's unnecessary, because the developer never needs to access // ractive.template ractive.template = template.t; if (template.p) { extendPartials(ractive.partials, template.p); } }, reset: function reset(ractive) { var result = resetValue(ractive); if (result) { var parsed = parseTemplate(result, ractive); ractive.template = parsed.t; extendPartials(ractive.partials, parsed.p, true); return true; } } }; function resetValue(ractive) { var initial = ractive._config.template; // If this isn't a dynamic template, there's nothing to do if (!initial || !initial.fn) { return; } var result = getDynamicTemplate(ractive, initial.fn); // TODO deep equality check to prevent unnecessary re-rendering // in the case of already-parsed templates if (result !== initial.result) { initial.result = result; return result; } } function getDynamicTemplate(ractive, fn) { return fn.call(ractive, { fromId: parser.fromId, isParsed: parser.isParsed, parse: function parse(template, options) { if ( options === void 0 ) options = parser.getParseOptions(ractive); return parser.parse(template, options); } }); } function parseTemplate(template, ractive) { if (isString(template)) { // parse will validate and add expression functions template = parseAsString(template, ractive); } else { // need to validate and add exp for already parsed template validate$1(template); addFunctions(template); } return template; } function parseAsString(template, ractive) { // ID of an element containing the template? if (template[0] === '#') { template = parser.fromId(template); } return parser.parseFor(template, ractive); } function validate$1(template) { // Check that the template even exists if (template == undefined) { throw new Error(("The template cannot be " + template + ".")); } else if (!isNumber(template.v)) { // Check the parsed template has a version at all throw new Error( "The template parser was passed a non-string template, but the template doesn't have a version. Make sure you're passing in the template you think you are." ); } else if (template.v !== TEMPLATE_VERSION) { // Check we're using the correct version throw new Error( ("Mismatched template version (expected " + TEMPLATE_VERSION + ", got " + (template.v) + ") Please ensure you are using the latest version of Ractive.js in your build process as well as in your app") ); } } function extendPartials(existingPartials, newPartials, overwrite) { if (!newPartials) { return; } // TODO there's an ambiguity here - we need to overwrite in the `reset()` // case, but not initially... for (var key in newPartials) { if (overwrite || !hasOwn(existingPartials, key)) { existingPartials[key] = newPartials[key]; } } } var registryNames = [ 'adaptors', 'components', 'computed', 'decorators', 'easing', 'events', 'helpers', 'interpolators', 'partials', 'transitions' ]; var registriesOnDefaults = ['computed', 'helpers']; var Registry = function Registry(name, useDefaults) { this.name = name; this.useDefaults = useDefaults; }; var Registry__proto__ = Registry.prototype; Registry__proto__.extend = function extend (Parent, proto, options) { var parent = this.useDefaults ? Parent.defaults : Parent; var target = this.useDefaults ? proto : proto.constructor; this.configure(parent, target, options); }; Registry__proto__.init = function init () { // noop }; Registry__proto__.configure = function configure (Parent, target, options) { var name = this.name; var option = options[name]; var registry = create(Parent[name]); assign(registry, option); target[name] = registry; if (name === 'partials' && target[name]) { keys(target[name]).forEach(function (key) { addFunctions(target[name][key]); }); } }; Registry__proto__.reset = function reset (ractive) { var registry = ractive[this.name]; var changed = false; keys(registry).forEach(function (key) { var item = registry[key]; if (item._fn) { if (item._fn.isOwner) { registry[key] = item._fn; } else { delete registry[key]; } changed = true; } }); return changed; }; var registries = registryNames.map(function (name) { var putInDefaults = registriesOnDefaults.indexOf(name) > -1; return new Registry(name, putInDefaults); }); function wrap(parent, name, method) { if (!/_super/.test(method)) { return method; } function wrapper() { var superMethod = getSuperMethod(wrapper._parent, name); var hasSuper = '_super' in this; var oldSuper = this._super; this._super = superMethod; var result = method.apply(this, arguments); if (hasSuper) { this._super = oldSuper; } else { delete this._super; } return result; } wrapper._parent = parent; wrapper._method = method; return wrapper; } function getSuperMethod(parent, name) { if (name in parent) { var value = parent[name]; return isFunction(value) ? value : function () { return value; }; } return noop; } function getMessage(deprecated, correct, isError) { return ( "options." + deprecated + " has been deprecated in favour of options." + correct + "." + (isError ? (" You cannot specify both options, please use options." + correct + ".") : '') ); } function deprecateOption(options, deprecatedOption, correct) { if (deprecatedOption in options) { if (!(correct in options)) { warnIfDebug(getMessage(deprecatedOption, correct)); options[correct] = options[deprecatedOption]; } else { throw new Error(getMessage(deprecatedOption, correct, true)); } } } function deprecate(options) { deprecateOption(options, 'beforeInit', 'onconstruct'); deprecateOption(options, 'init', 'onrender'); deprecateOption(options, 'complete', 'oncomplete'); deprecateOption(options, 'eventDefinitions', 'events'); // Using extend with Component instead of options, // like Human.extend( Spider ) means adaptors as a registry // gets copied to options. So we have to check if actually an array if (isArray(options.adaptors)) { deprecateOption(options, 'adaptors', 'adapt'); } } var config = { extend: function (Parent, proto, options, Child) { return configure('extend', Parent, proto, options, Child); }, init: function (Parent, ractive, options) { return configure('init', Parent, ractive, options); }, reset: function (ractive) { return order.filter(function (c) { return c.reset && c.reset(ractive); }).map(function (c) { return c.name; }); } }; var custom = { adapt: adaptConfigurator, computed: config, css: cssConfigurator, data: dataConfigurator, helpers: config, template: templateConfigurator }; var defaultKeys = keys(defaults); var isStandardKey = makeObj(defaultKeys.filter(function (key) { return !custom[key]; })); // blacklisted keys that we don't double extend var isBlacklisted = makeObj( defaultKeys.concat(registries.map(function (r) { return r.name; }), ['on', 'observe', 'attributes', 'cssData', 'use']) ); var order = [].concat( defaultKeys.filter(function (key) { return !registries[key] && !custom[key]; }), registries, //custom.data, custom.template, custom.css ); function configure(method, Parent, target, options, Child) { deprecate(options); for (var key in options) { if (hasOwn(isStandardKey, key)) { var value = options[key]; // warn the developer if they passed a function and ignore its value // NOTE: we allow some functions on "el" because we duck type element lists // and some libraries or ef'ed-up virtual browsers (phantomJS) return a // function object as the result of querySelector methods if (key !== 'el' && isFunction(value)) { warnIfDebug( (key + " is a Ractive option that does not expect a function and will be ignored"), method === 'init' ? target : null ); } else { target[key] = value; } } } // disallow combination of `append` and `enhance` if (target.append && target.enhance) { throw new Error('Cannot use append and enhance at the same time'); } registries.forEach(function (registry) { registry[method](Parent, target, options, Child); }); adaptConfigurator[method](Parent, target, options, Child); templateConfigurator[method](Parent, target, options, Child); cssConfigurator[method](Parent, target, options, Child); extendOtherMethods(Parent.prototype, target, options); } var _super = /\b_super\b/; function extendOtherMethods(parent, target, options) { for (var key in options) { if (!isBlacklisted[key] && hasOwn(options, key)) { var member = options[key]; // if this is a method that overwrites a method, wrap it: if (isFunction(member)) { if ( (key in proto$9 || (key.slice(0, 2) === 'on' && key.slice(2) in hooks && key in target)) && !_super.test(member.toString()) ) { warnIfDebug( ("Overriding Ractive prototype function '" + key + "' without calling the '" + _super + "' method can be very dangerous.") ); } member = wrap(parent, key, member); } target[key] = member; } } } function makeObj(array) { var obj = {}; array.forEach(function (x) { return (obj[x] = true); }); return obj; } var Item = function Item(options) { this.up = options.up; this.ractive = options.up.ractive; this.template = options.template; this.index = options.index; this.type = options.template.t; this.dirty = false; }; var Item__proto__ = Item.prototype; Item__proto__.bubble = function bubble () { if (!this.dirty) { this.dirty = true; this.up.bubble(); } }; Item__proto__.destroyed = function destroyed () { if (this.fragment) { this.fragment.destroyed(); } }; Item__proto__.find = function find () { return null; }; Item__proto__.findComponent = function findComponent () { return null; }; Item__proto__.findNextNode = function findNextNode () { return this.up.findNextNode(this); }; Item__proto__.rebound = function rebound (update) { if (this.fragment) { this.fragment.rebound(update); } }; Item__proto__.shuffled = function shuffled () { if (this.fragment) { this.fragment.shuffled(); } }; Item__proto__.valueOf = function valueOf () { return this.toString(); }; Item.prototype.findAll = noop; Item.prototype.findAllComponents = noop; var ContainerItem = (function (Item) { function ContainerItem(options) { Item.call(this, options); } if ( Item ) ContainerItem.__proto__ = Item; var ContainerItem__proto__ = ContainerItem.prototype = Object.create( Item && Item.prototype ); ContainerItem__proto__.constructor = ContainerItem; ContainerItem__proto__.detach = function detach () { return this.fragment ? this.fragment.detach() : createDocumentFragment(); }; ContainerItem__proto__.find = function find (selector) { if (this.fragment) { return this.fragment.find(selector); } }; ContainerItem__proto__.findAll = function findAll (selector, options) { if (this.fragment) { this.fragment.findAll(selector, options); } }; ContainerItem__proto__.findComponent = function findComponent (name) { if (this.fragment) { return this.fragment.findComponent(name); } }; ContainerItem__proto__.findAllComponents = function findAllComponents (name, options) { if (this.fragment) { this.fragment.findAllComponents(name, options); } }; ContainerItem__proto__.firstNode = function firstNode (skipParent) { return this.fragment && this.fragment.firstNode(skipParent); }; ContainerItem__proto__.toString = function toString (escape) { return this.fragment ? this.fragment.toString(escape) : ''; }; return ContainerItem; }(Item)); var space = /\s+/; function readStyle(css) { if (!isString(css)) { return {}; } return cleanCss(css, function (css, reconstruct) { return css .split(';') .filter(function (rule) { return !!rule.trim(); }) .map(reconstruct) .reduce(function (rules, rule) { var i = rule.indexOf(':'); var name = rule.substr(0, i).trim(); rules[name] = rule.substr(i + 1).trim(); return rules; }, {}); }); } function readClass(str) { var list = str.split(space); // remove any empty entries var i = list.length; while (i--) { if (!list[i]) { list.splice(i, 1); } } return list; } var textTypes = [ undefined, 'text', 'search', 'url', 'email', 'hidden', 'password', 'search', 'reset', 'submit' ]; function getUpdateDelegate(attribute) { var element = attribute.element; var name = attribute.name; if (name === 'value') { if (attribute.interpolator) { attribute.interpolator.bound = true; } // special case - selects if (element.name === 'select' && name === 'value') { return element.getAttribute('multiple') ? updateMultipleSelectValue : updateSelectValue; } if (element.name === 'textarea') { return updateStringValue; } // special case - contenteditable if (element.getAttribute('contenteditable') != null) { return updateContentEditableValue; } // special case - <input> if (element.name === 'input') { var type = element.getAttribute('type'); // type='file' value='{{fileList}}'> if (type === 'file') { return noop; } // read-only // type='radio' name='{{twoway}}' if (type === 'radio' && element.binding && element.binding.attribute.name === 'name') { return updateRadioValue; } if (~textTypes.indexOf(type)) { return updateStringValue; } } return updateValue; } var node = element.node; // special case - <input type='radio' name='{{twoway}}' value='foo'> if (attribute.isTwoway && name === 'name') { if (node.type === 'radio') { return updateRadioName; } if (node.type === 'checkbox') { return updateCheckboxName; } } if (name === 'style') { return updateStyleAttribute; } if (name.indexOf('style-') === 0) { return updateInlineStyle; } // special case - class names. IE fucks things up, again if (name === 'class' && (!node.namespaceURI || node.namespaceURI === html)) { return updateClassName; } if (name.indexOf('class-') === 0) { return updateInlineClass; } if (attribute.isBoolean) { var type$1 = element.getAttribute('type'); if (attribute.interpolator && name === 'checked' && (type$1 === 'checkbox' || type$1 === 'radio')) { attribute.interpolator.bound = true; } return updateBoolean; } if (attribute.namespace && attribute.namespace !== attribute.node.namespaceURI) { return updateNamespacedAttribute; } return updateAttribute; } function updateMultipleSelectValue(reset) { var value = this.getValue(); if (!isArray(value)) { value = [value]; } var options = this.node.options; var i = options.length; if (reset) { while (i--) { options[i].selected = false; } } else { while (i--) { var option = options[i]; var optionValue = option._ractive ? option._ractive.value : option.value; // options inserted via a triple don't have _ractive option.selected = arrayContains(value, optionValue); } } } function updateSelectValue(reset) { var value = this.getValue(); if (!this.locked) { // TODO is locked still a thing? this.node._ractive.value = value; var options = this.node.options; var i = options.length; var wasSelected = false; if (reset) { while (i--) { options[i].selected = false; } } else { while (i--) { var option = options[i]; var optionValue = option._ractive ? option._ractive.value : option.value; // options inserted via a triple don't have _ractive if (option.disabled && option.selected) { wasSelected = true; } if (optionValue == value) { // double equals as we may be comparing numbers with strings option.selected = true; return; } } } if (!wasSelected) { this.node.selectedIndex = -1; } } } function updateContentEditableValue(reset) { var value = this.getValue(); if (!this.locked) { if (reset) { this.node.innerHTML = ''; } else { this.node.innerHTML = isUndefined(value) ? '' : value; } } } function updateRadioValue(reset) { var node = this.node; var wasChecked = node.checked; var value = this.getValue(); if (reset) { return (node.checked = false); } //node.value = this.element.getAttribute( 'value' ); node.value = this.node._ractive.value = value; node.checked = this.element.compare(value, this.element.getAttribute('name')); // This is a special case - if the input was checked, and the value // changed so that it's no longer checked, the twoway binding is // most likely out of date. To fix it we have to jump through some // hoops... this is a little kludgy but it works if (wasChecked && !node.checked && this.element.binding && this.element.binding.rendered) { this.element.binding.group.model.set(this.element.binding.group.getValue()); } } function updateValue(reset) { if (!this.locked) { if (reset) { this.node.removeAttribute('value'); this.node.value = this.node._ractive.value = null; } else { var value = this.getValue(); this.node.value = this.node._ractive.value = value; this.node.setAttribute('value', safeToStringValue(value)); } } } function updateStringValue(reset) { if (!this.locked) { if (reset) { this.node._ractive.value = ''; this.node.removeAttribute('value'); } else { var value = this.getValue(); this.node._ractive.value = value; var safeValue = safeToStringValue(value); // fixes #3281 – Safari moves caret position when setting an input value to the same value if (this.node.value !== safeValue) { this.node.value = safeValue; } this.node.setAttribute('value', safeValue); } } } function updateRadioName(reset) { if (reset) { this.node.checked = false; } else { this.node.checked = this.element.compare(this.getValue(), this.element.binding.getValue()); } } function updateCheckboxName(reset) { var ref = this; var element = ref.element; var node = ref.node; var binding = element.binding; var value = this.getValue(); var valueAttribute = element.getAttribute('value'); if (!isArray(value)) { binding.isChecked = node.checked = element.compare(value, valueAttribute); } else { var i = value.length; while (i--) { if (element.compare(valueAttribute, value[i])) { binding.isChecked = node.checked = true; return; } } binding.isChecked = node.checked = false; } } function updateStyleAttribute(reset) { var props = reset ? {} : readStyle(this.getValue() || ''); var style = this.node.style; var keys$$1 = keys(props); var prev = this.previous || []; var i = 0; while (i < keys$$1.length) { if (keys$$1[i] in style) { var safe = props[keys$$1[i]].replace('!important', ''); style.setProperty(keys$$1[i], safe, safe.length !== props[keys$$1[i]].length ? 'important' : ''); } i++; } // remove now-missing attrs i = prev.length; while (i--) { if (!~keys$$1.indexOf(prev[i]) && prev[i] in style) { style.setProperty(prev[i], '', ''); } } this.previous = keys$$1; } function updateInlineStyle(reset) { if (!this.style) { this.style = hyphenateCamel(this.name.substr(6)); } if (reset && this.node.style.getPropertyValue(this.style) !== this.last) { return; } var value = reset ? '' : safeToStringValue(this.getValue()); var safe = value.replace('!important', ''); this.node.style.setProperty(this.style, safe, safe.length !== value.length ? 'important' : ''); this.last = this.node.style.getPropertyValue(this.style); } function updateClassName(reset) { var value = reset ? [] : readClass(safeToStringValue(this.getValue())); // watch out for werdo svg elements var cls = this.node.className; cls = cls.baseVal !== undefined ? cls.baseVal : cls; var attr = readClass(cls); var prev = this.previous || []; var className = value.concat(attr.filter(function (c) { return !~prev.indexOf(c); })).join(' '); if (className !== cls) { if (!isString(this.node.className)) { this.node.className.baseVal = className; } else { this.node.className = className; } } this.previous = value; } function updateInlineClass(reset) { var name = this.name.substr(6); // watch out for werdo svg elements var cls = this.node.className; cls = cls.baseVal !== undefined ? cls.baseVal : cls; var attr = readClass(cls); var value = reset ? false : this.getValue(); if (!this.inlineClass) { this.inlineClass = name; } if (value && !~attr.indexOf(name)) { attr.push(name); } else if (!value && ~attr.indexOf(name)) { attr.splice(attr.indexOf(name), 1); } if (!isString(this.node.className)) { this.node.className.baseVal = attr.join(' '); } else { this.node.className = attr.join(' '); } } function updateBoolean(reset) { // with two-way binding, only update if the change wasn't initiated by the user // otherwise the cursor will often be sent to the wrong place if (!this.locked) { if (reset) { if (this.useProperty) { this.node[this.propertyName] = false; } this.node.removeAttribute(this.propertyName); } else { if (this.useProperty) { this.node[this.propertyName] = this.getValue(); } else { var val = this.getValue(); if (val) { this.node.setAttribute(this.propertyName, isString(val) ? val : ''); } else { this.node.removeAttribute(this.propertyName); } } } } } function updateAttribute(reset) { if (reset) { if (this.node.getAttribute(this.name) === this.value) { this.node.removeAttribute(this.name); } } else { this.value = safeToStringValue(this.getString()); this.node.setAttribute(this.name, this.value); } } function updateNamespacedAttribute(reset) { if (reset) { if ( this.value === this.node.getAttributeNS(this.namespace, this.name.slice(this.name.indexOf(':') + 1)) ) { this.node.removeAttributeNS(this.namespace, this.name.slice(this.name.indexOf(':') + 1)); } } else { this.value = safeToStringValue(this.getString()); this.node.setAttributeNS( this.namespace, this.name.slice(this.name.indexOf(':') + 1), this.value ); } } var propertyNames = { 'accept-charset': 'acceptCharset', accesskey: 'accessKey', bgcolor: 'bgColor', class: 'className', codebase: 'codeBase', colspan: 'colSpan', contenteditable: 'contentEditable', datetime: 'dateTime', dirname: 'dirName', for: 'htmlFor', 'http-equiv': 'httpEquiv', ismap: 'isMap', maxlength: 'maxLength', novalidate: 'noValidate', pubdate: 'pubDate', readonly: 'readOnly', rowspan: 'rowSpan', tabindex: 'tabIndex', usemap: 'useMap' }; var div$1 = doc ? createElement('div') : null; var attributes = false; function inAttributes() { return attributes; } var ConditionalAttribute = (function (Item) { function ConditionalAttribute(options) { Item.call(this, options); this.attributes = []; this.owner = options.owner; this.fragment = new Fragment({ ractive: this.ractive, owner: this, template: this.template }); // this fragment can't participate in node-y things this.fragment.findNextNode = noop; this.dirty = false; } if ( Item ) ConditionalAttribute.__proto__ = Item; var ConditionalAttribute__proto__ = ConditionalAttribute.prototype = Object.create( Item && Item.prototype ); ConditionalAttribute__proto__.constructor = ConditionalAttribute; ConditionalAttribute__proto__.bind = function bind () { this.fragment.bind(); }; ConditionalAttribute__proto__.bubble = function bubble () { if (!this.dirty) { this.dirty = true; this.owner.bubble(); } }; ConditionalAttribute__proto__.destroyed = function destroyed () { this.unrender(); }; ConditionalAttribute__proto__.render = function render () { this.node = this.owner.node; if (this.node) { this.isSvg = this.node.namespaceURI === svg$1; } attributes = true; if (!this.rendered) { this.fragment.render(); } this.rendered = true; this.dirty = true; // TODO this seems hacky, but necessary for tests to pass in browser AND node.js this.update(); attributes = false; }; ConditionalAttribute__proto__.toString = function toString () { return this.fragment.toString(); }; ConditionalAttribute__proto__.unbind = function unbind (view) { this.fragment.unbind(view); }; ConditionalAttribute__proto__.unrender = function unrender () { this.rendered = false; this.fragment.unrender(); }; ConditionalAttribute__proto__.update = function update () { var this$1 = this; var str; var attrs; if (this.dirty) { this.dirty = false; var current = attributes; attributes = true; this.fragment.update(); if (this.rendered && this.node) { str = this.fragment.toString(); attrs = parseAttributes(str, this.isSvg); // any attributes that previously existed but no longer do // must be removed this.attributes .filter(function (a) { return notIn(attrs, a); }) .forEach(function (a) { this$1.node.removeAttribute(a.name); }); attrs.forEach(function (a) { this$1.node.setAttribute(a.name, a.value); }); this.attributes = attrs; } attributes = current || false; } }; return ConditionalAttribute; }(Item)); var onlyWhitespace = /^\s*$/; function parseAttributes(str, isSvg) { if (onlyWhitespace.test(str)) { return []; } var tagName = isSvg ? 'svg' : 'div'; return str ? (div$1.innerHTML = "<" + tagName + " " + str + "></" + tagName + ">") && toArray(div$1.childNodes[0].attributes) : []; } function notIn(haystack, needle) { var i = haystack.length; while (i--) { if (haystack[i].name === needle.name) { return false; } } return true; } function lookupNamespace(node, prefix) { var qualified = "xmlns:" + prefix; while (node) { if (node.hasAttribute && node.hasAttribute(qualified)) { return node.getAttribute(qualified); } node = node.parentNode; } return namespaces[prefix]; } var attribute = false; function inAttribute() { return attribute; } var Attribute = (function (Item) { function Attribute(options) { Item.call(this, options); this.name = options.template.n; this.namespace = null; this.owner = options.owner || options.up.owner || options.element || findElement(options.up); this.element = options.element || (this.owner.attributeByName ? this.owner : findElement(options.up)); this.up = options.up; // shared this.ractive = this.up.ractive; this.rendered = false; this.updateDelegate = null; this.fragment = null; this.element.attributeByName[this.name] = this; if (!isArray(options.template.f)) { this.value = options.template.f; if (this.value === 0) { this.value = ''; } else if (isUndefined(this.value)) { this.value = true; } return; } else { this.fragment = new Fragment({ owner: this, template: options.template.f }); } this.interpolator = this.fragment && this.fragment.items.length === 1 && this.fragment.items[0].type === INTERPOLATOR && this.fragment.items[0]; if (this.interpolator) { this.interpolator.owner = this; } } if ( Item ) Attribute.__proto__ = Item; var Attribute__proto__ = Attribute.prototype = Object.create( Item && Item.prototype ); Attribute__proto__.constructor = Attribute; Attribute__proto__.bind = function bind () { if (this.fragment) { this.fragment.bind(); } }; Attribute__proto__.bubble = function bubble () { if (!this.dirty) { this.up.bubble(); this.element.bubble(); this.dirty = true; } }; Attribute__proto__.firstNode = function firstNode () {}; Attribute__proto__.getString = function getString () { attribute = true; var value = this.fragment ? this.fragment.toString() : this.value != null ? '' + this.value : ''; attribute = false; return value; }; // TODO could getValue ever be called for a static attribute, // or can we assume that this.fragment exists? Attribute__proto__.getValue = function getValue () { attribute = true; var value = this.fragment ? this.fragment.valueOf() : booleanAttributes[this.name.toLowerCase()] ? true : this.value; attribute = false; return value; }; Attribute__proto__.render = function render () { var node = this.element.node; this.node = node; // should we use direct property access, or setAttribute? if (!node.namespaceURI || node.namespaceURI === namespaces.html) { this.propertyName = propertyNames[this.name] || this.name; if (node[this.propertyName] !== undefined) { this.useProperty = true; } // is attribute a boolean attribute or 'value'? If so we're better off doing e.g. // node.selected = true rather than node.setAttribute( 'selected', '' ) if (booleanAttributes[this.name.toLowerCase()] || this.isTwoway) { this.isBoolean = true; } if (this.propertyName === 'value') { node._ractive.value = this.value; } } if (node.namespaceURI) { var index = this.name.indexOf(':'); if (index !== -1) { this.namespace = lookupNamespace(node, this.name.slice(0, index)); } else { this.namespace = node.namespaceURI; } } this.rendered = true; this.updateDelegate = getUpdateDelegate(this); this.updateDelegate(); }; Attribute__proto__.toString = function toString () { if (inAttributes()) { return ''; } attribute = true; var value = this.getValue(); // Special case - select and textarea values (should not be stringified) if ( this.name === 'value' && (this.element.getAttribute('contenteditable') !== undefined || (this.element.name === 'select' || this.element.name === 'textarea')) ) { return; } // Special case – bound radio `name` attributes if ( this.name === 'name' && this.element.name === 'input' && this.interpolator && this.element.getAttribute('type') === 'radio' ) { return ("name=\"{{" + (this.interpolator.model.getKeypath()) + "}}\""); } // Special case - style and class attributes and directives if ( this.owner === this.element && (this.name === 'style' || this.name === 'class' || this.style || this.inlineClass) ) { return; } if ( !this.rendered && this.owner === this.element && (!this.name.indexOf('style-') || !this.name.indexOf('class-')) ) { if (!this.name.indexOf('style-')) { this.style = hyphenateCamel(this.name.substr(6)); } else { this.inlineClass = this.name.substr(6); } return; } if (booleanAttributes[this.name.toLowerCase()]) { return value ? isString(value) ? ((this.name) + "=\"" + (safeAttributeString(value)) + "\"") : this.name : ''; } if (value == null) { return ''; } var str = safeAttributeString(this.getString()); attribute = false; return str ? ((this.name) + "=\"" + str + "\"") : this.name; }; Attribute__proto__.unbind = function unbind (view) { if (this.fragment) { this.fragment.unbind(view); } }; Attribute__proto__.unrender = function unrender () { this.updateDelegate(true); this.rendered = false; }; Attribute__proto__.update = function update () { if (this.dirty) { var binding; this.dirty = false; if (this.fragment) { this.fragment.update(); } if (this.rendered) { this.updateDelegate(); } if (this.isTwoway && !this.locked) { this.interpolator.twowayBinding.lastVal(true, this.interpolator.model.get()); } else if (this.name === 'value' && (binding = this.element.binding)) { // special case: name bound element with dynamic value var attr = binding.attribute; if (attr && !attr.dirty && attr.rendered) { this.element.binding.attribute.updateDelegate(); } } } }; return Attribute; }(Item)); var BindingFlag = (function (Item) { function BindingFlag(options) { Item.call(this, options); this.owner = options.owner || options.up.owner || findElement(options.up); this.element = this.owner.attributeByName ? this.owner : findElement(options.up); this.flag = options.template.v === 'l' ? 'lazy' : 'twoway'; this.bubbler = this.owner === this.element ? this.element : this.up; if (this.element.type === ELEMENT) { if (isArray(options.template.f)) { this.fragment = new Fragment({ owner: this, template: options.template.f }); } this.interpolator = this.fragment && this.fragment.items.length === 1 && this.fragment.items[0].type === INTERPOLATOR && this.fragment.items[0]; } } if ( Item ) BindingFlag.__proto__ = Item; var BindingFlag__proto__ = BindingFlag.prototype = Object.create( Item && Item.prototype ); BindingFlag__proto__.constructor = BindingFlag; BindingFlag__proto__.bind = function bind () { if (this.fragment) { this.fragment.bind(); } set$1(this, this.getValue(), true); }; BindingFlag__proto__.bubble = function bubble () { if (!this.dirty) { this.bubbler.bubble(); this.dirty = true; } }; BindingFlag__proto__.getValue = function getValue () { if (this.fragment) { return this.fragment.valueOf(); } else if ('value' in this) { return this.value; } else if ('f' in this.template) { return this.template.f; } else { return true; } }; BindingFlag__proto__.render = function render () { set$1(this, this.getValue(), true); }; BindingFlag__proto__.toString = function toString () { return ''; }; BindingFlag__proto__.unbind = function unbind (view) { if (this.fragment) { this.fragment.unbind(view); } delete this.element[this.flag]; }; BindingFlag__proto__.unrender = function unrender () { if (this.element.rendered) { this.element.recreateTwowayBinding(); } }; BindingFlag__proto__.update = function update () { if (this.dirty) { this.dirty = false; if (this.fragment) { this.fragment.update(); } set$1(this, this.getValue(), true); } }; return BindingFlag; }(Item)); function set$1(flag, value, update) { if (value === 0) { flag.value = true; } else if (value === 'true') { flag.value = true; } else if (value === 'false' || value === '0') { flag.value = false; } else { flag.value = value; } var current = flag.element[flag.flag]; flag.element[flag.flag] = flag.value; if (update && !flag.element.attributes.binding && current !== flag.value) { flag.element.recreateTwowayBinding(); } return flag.value; } function Comment(options) { Item.call(this, options); } var proto$1 = create(Item.prototype); assign(proto$1, { bind: noop, unbind: noop, update: noop, detach: function detach() { return detachNode(this.node); }, firstNode: function firstNode() { return this.node; }, render: function render(target) { this.rendered = true; this.node = doc.createComment(this.template.c); target.appendChild(this.node); }, toString: function toString() { return ("<!-- " + (this.template.c) + " -->"); }, unrender: function unrender(shouldDestroy) { if (this.rendered && shouldDestroy) { this.detach(); } this.rendered = false; } }); Comment.prototype = proto$1; // Teardown. This goes through the root fragment and all its children, removing observers // and generally cleaning up after itself function Ractive$teardown() { var this$1 = this; if (this.torndown) { warnIfDebug('ractive.teardown() was called on a Ractive instance that was already torn down'); return Promise.resolve(); } this.shouldDestroy = true; return teardown$1(this, function () { return (this$1.fragment.rendered ? this$1.unrender() : Promise.resolve()); }); } function teardown$1(instance, getPromise) { instance.torndown = true; instance.fragment.unbind(); instance._observers.slice().forEach(cancel); if (instance.el && instance.el.__ractive_instances__) { removeFromArray(instance.el.__ractive_instances__, instance); } var promise = getPromise(); hooks.teardown.fire(instance); promise.then(function () { hooks.destruct.fire(instance); instance.viewmodel.teardown(); }); return promise; } var RactiveModel = (function (SharedModel) { function RactiveModel(ractive) { SharedModel.call(this, ractive, '@this'); this.ractive = ractive; } if ( SharedModel ) RactiveModel.__proto__ = SharedModel; var RactiveModel__proto__ = RactiveModel.prototype = Object.create( SharedModel && SharedModel.prototype ); RactiveModel__proto__.constructor = RactiveModel; RactiveModel__proto__.joinKey = function joinKey (key) { var model = SharedModel.prototype.joinKey.call(this, key); if ((key === 'root' || key === 'parent') && !model.isLink) { return initLink(model, key); } else if (key === 'data') { return this.ractive.viewmodel; } else if (key === 'cssData') { return this.ractive.constructor._cssModel; } return model; }; return RactiveModel; }(SharedModel)); function initLink(model, key) { model.applyValue = function(value) { this.parent.value[key] = value; if (value && value.viewmodel) { this.link(value.viewmodel.getRactiveModel(), key); this._link.markedAll(); } else { this.link(create(Missing), key); this._link.markedAll(); } }; if (key === 'root') { var mark = model.mark; model.mark = function(force) { if (this._marking) { return; } this._marking = true; mark.apply(this, force); this._marking = false; }; } model.applyValue(model.parent.ractive[key], key); model._link.set = function (v) { return model.applyValue(v); }; model._link.applyValue = function (v) { return model.applyValue(v); }; return model._link; } var specialModels = { '@this': function _this(root) { return root.getRactiveModel(); }, '@global': function _global() { return GlobalModel; }, '@shared': function _shared() { return SharedModel$1; }, '@style': function _style(root) { return root.getRactiveModel().joinKey('cssData'); }, '@helpers': function _helpers(root) { return root.getHelpers(); } }; specialModels['@'] = specialModels['@this']; var RootModel = (function (Model) { function RootModel(options) { Model.call(this, null, null); this.isRoot = true; this.root = this; this.ractive = options.ractive; // TODO sever this link this.value = options.data; this.adaptors = options.adapt; this.adapt(); } if ( Model ) RootModel.__proto__ = Model; var RootModel__proto__ = RootModel.prototype = Object.create( Model && Model.prototype ); RootModel__proto__.constructor = RootModel; RootModel__proto__.attached = function attached (fragment) { attachImplicits(this, fragment); }; RootModel__proto__.createLink = function createLink (keypath, target, targetPath, options) { var keys = splitKeypath(keypath); var model = this; while (keys.length) { var key = keys.shift(); model = model.childByKey[key] || model.joinKey(key); } return model.link(target, targetPath, options); }; RootModel__proto__.detached = function detached () { detachImplicits(this); }; RootModel__proto__.get = function get (shouldCapture, options) { if (shouldCapture) { capture(this); } if (!options || options.virtual !== false) { return this.getVirtual(); } else { return this.value; } }; RootModel__proto__.getHelpers = function getHelpers () { if (!this.helpers) { this.helpers = new SharedModel(this.ractive.helpers, 'helpers', this.ractive); } return this.helpers; }; RootModel__proto__.getKeypath = function getKeypath () { return ''; }; RootModel__proto__.getRactiveModel = function getRactiveModel () { return this.ractiveModel || (this.ractiveModel = new RactiveModel(this.ractive)); }; RootModel__proto__.getValueChildren = function getValueChildren () { var children = Model.prototype.getValueChildren.call(this, this.value); this.children.forEach(function (child) { if (child._link) { var idx = children.indexOf(child); if (~idx) { children.splice(idx, 1, child._link); } else { children.push(child._link); } } }); return children; }; RootModel__proto__.has = function has (key) { if (key[0] === '~' && key[1] === '/') { key = key.slice(2); } if (specialModels[key] || key === '') { return true; } if (Model.prototype.has.call(this, key)) { return true; } else { var unescapedKey = unescapeKey(key); // mappings/links and computations if (this.childByKey[unescapedKey] && this.childByKey[unescapedKey]._link) { return true; } } }; RootModel__proto__.joinKey = function joinKey (key, opts) { if (key[0] === '~' && key[1] === '/') { key = key.slice(2); } if (key[0] === '@') { var fn = specialModels[key]; if (fn) { return fn(this); } } else { return Model.prototype.joinKey.call(this, key, opts); } }; RootModel__proto__.set = function set (value) { // TODO wrapping root node is a baaaad idea. We should prevent this var wrapper = this.wrapper; if (wrapper) { var shouldTeardown = !wrapper.reset || wrapper.reset(value) === false; if (shouldTeardown) { wrapper.teardown(); this.wrapper = null; this.value = value; this.adapt(); } } else { this.value = value; this.adapt(); } this.deps.forEach(handleChange); this.children.forEach(mark); }; RootModel__proto__.retrieve = function retrieve () { return this.wrapper ? this.wrapper.get() : this.value; }; RootModel__proto__.teardown = function teardown () { Model.prototype.teardown.call(this); this.ractiveModel && this.ractiveModel.teardown(); }; return RootModel; }(Model)); RootModel.prototype.update = noop; function attachImplicits(model, fragment) { if (model._link && model._link.implicit && model._link.isDetached()) { model.attach(fragment); } // look for virtual children to relink and cascade for (var k in model.childByKey) { if (model.value) { if (k in model.value) { attachImplicits(model.childByKey[k], fragment); } else if (!model.childByKey[k]._link || model.childByKey[k]._link.isDetached()) { var mdl = resolveReference(fragment, k); if (mdl) { model.childByKey[k].link(mdl, k, { implicit: true }); } } } } } function detachImplicits(model) { if (model._link && model._link.implicit) { model.unlink(); } for (var k in model.childByKey) { detachImplicits(model.childByKey[k]); } } function subscribe(instance, options, type) { var subs = (instance.constructor[("_" + type)] || []).concat(toPairs(options[type] || [])); var single = type === 'on' ? 'once' : (type + "Once"); subs.forEach(function (ref) { var target = ref[0]; var config = ref[1]; if (isFunction(config)) { instance[type](target, config); } else if (isObjectType(config) && isFunction(config.handler)) { instance[config.once ? single : type](target, config.handler, create(config)); } }); } var registryNames$1 = [ 'adaptors', 'components', 'decorators', 'easing', 'events', 'interpolators', 'partials', 'transitions' ]; var protoRegistries = ['computed', 'helpers']; var uid = 0; function construct(ractive, options) { if (Ractive.DEBUG) { welcome(); } initialiseProperties(ractive); handleAttributes(ractive); // set up event subscribers subscribe(ractive, options, 'on'); // if there's not a delegation setting, inherit from parent if it's not default if ( !hasOwn(options, 'delegate') && ractive.parent && ractive.parent.delegate !== ractive.delegate ) { ractive.delegate = false; } // plugins that need to run at construct if (isArray(options.use)) { ractive.use.apply(ractive, options.use.filter(function (p) { return p.construct; })); } hooks.construct.fire(ractive, options); if (options.onconstruct) { options.onconstruct.call(ractive, getRactiveContext(ractive), options); } // Add registries var i = registryNames$1.length; while (i--) { var name = registryNames$1[i]; ractive[name] = assign(create(ractive.constructor[name] || null), options[name]); } i = protoRegistries.length; while (i--) { var name$1 = protoRegistries[i]; ractive[name$1] = assign(create(ractive.constructor.prototype[name$1]), options[name$1]); } if (ractive._attributePartial) { ractive.partials['extra-attributes'] = ractive._attributePartial; delete ractive._attributePartial; } // Create a viewmodel var viewmodel = new RootModel({ adapt: getAdaptors(ractive, ractive.adapt, options), data: dataConfigurator.init(ractive.constructor, ractive, options), ractive: ractive }); // once resolved, share the adaptors array between the root model and instance ractive.adapt = viewmodel.adaptors; ractive.viewmodel = viewmodel; for (var k in ractive.computed) { compute.call(ractive, k, ractive.computed[k]); } } function getAdaptors(ractive, protoAdapt, options) { protoAdapt = protoAdapt.map(lookup); var adapt = ensureArray(options.adapt).map(lookup); var srcs = [protoAdapt, adapt]; if (ractive.parent && !ractive.isolated) { srcs.push(ractive.parent.viewmodel.adaptors); } return combine.apply(null, srcs); function lookup(adaptor) { if (isString(adaptor)) { adaptor = findInViewHierarchy('adaptors', ractive, adaptor); if (!adaptor) { fatal(missingPlugin(adaptor, 'adaptor')); } } return adaptor; } } function initialiseProperties(ractive) { // Generate a unique identifier, for places where you'd use a weak map if it // existed ractive._guid = 'r-' + uid++; // events ractive._subs = create(null); ractive._nsSubs = 0; // storage for item configuration from instantiation to reset, // like dynamic functions or original values ractive._config = {}; // events ractive.event = null; ractive._eventQueue = []; // observers ractive._observers = []; // external children ractive._children = []; ractive._children.byName = {}; ractive.children = ractive._children; if (!ractive.component) { ractive.root = ractive; ractive.parent = ractive.container = null; // TODO container still applicable? } } function handleAttributes(ractive) { var component = ractive.component; var attributes = ractive.constructor.attributes; if (attributes && component) { var tpl = component.template; var attrs = tpl.m ? tpl.m.slice() : []; // grab all of the passed attribute names var props = attrs.filter(function (a) { return a.t === ATTRIBUTE; }).map(function (a) { return a.n; }); // warn about missing requireds attributes.required.forEach(function (p) { if (!~props.indexOf(p)) { warnIfDebug(("Component '" + (component.name) + "' requires attribute '" + p + "' to be provided")); } }); // set up a partial containing non-property attributes var all = attributes.optional.concat(attributes.required); var partial = []; var i = attrs.length; while (i--) { var a = attrs[i]; if (a.t === ATTRIBUTE && !~all.indexOf(a.n)) { if (attributes.mapAll) { // map the attribute if requested and make the extra attribute in the partial refer to the mapping partial.unshift({ t: ATTRIBUTE, n: a.n, f: [{ t: INTERPOLATOR, r: ("~/" + (a.n)) }] }); } else { // transfer the attribute to the extra attributes partal partial.unshift(attrs.splice(i, 1)[0]); } } else if ( !attributes.mapAll && (a.t === DECORATOR || a.t === TRANSITION || a.t === BINDING_FLAG) ) { partial.unshift(attrs.splice(i, 1)[0]); } } if (partial.length) { component.template = { t: tpl.t, e: tpl.e, f: tpl.f, m: attrs, p: tpl.p }; } ractive._attributePartial = partial; } } var Component = (function (Item) { function Component(options, ComponentConstructor) { var this$1 = this; Item.call(this, options); var template = options.template; this.isAnchor = template.t === ANCHOR; this.type = this.isAnchor ? ANCHOR : COMPONENT; // override ELEMENT from super var attrs = template.m; var partials = template.p || {}; if (!('content' in partials)) { partials.content = template.f || []; } this._partials = partials; // TEMP if (this.isAnchor) { this.name = template.n; this.addChild = addChild; this.removeChild = removeChild; } else { var instance = create(ComponentConstructor.prototype); this.instance = instance; this.name = template.e; if (instance.el || instance.target) { warnIfDebug( ("The <" + (this.name) + "> component has a default '" + (instance.el ? 'el' : 'target') + "' property; it has been disregarded") ); instance.el = instance.target = null; } // find container var fragment = options.up; var container; while (fragment) { if (fragment.owner.type === YIELDER) { container = fragment.owner.container; break; } fragment = fragment.parent; } // add component-instance-specific properties instance.parent = this.up.ractive; instance.container = container || null; instance.root = instance.parent.root; instance.component = this; construct(this.instance, { partials: partials }); // these can be modified during construction template = this.template; attrs = template.m; // allow components that are so inclined to add programmatic mappings if (isArray(this.mappings)) { attrs = (attrs || []).concat(this.mappings); } else if (isString(this.mappings)) { attrs = (attrs || []).concat(parser.parse(this.mappings, { attributes: true }).t); } // for hackability, this could be an open option // for any ractive instance, but for now, just // for components and just for ractive... instance._inlinePartials = partials; } this.attributeByName = {}; this.attributes = []; if (attrs) { var leftovers = []; attrs.forEach(function (template) { switch (template.t) { case ATTRIBUTE: case EVENT: this$1.attributes.push( createItem({ owner: this$1, up: this$1.up, template: template }) ); break; case TRANSITION: case BINDING_FLAG: case DECORATOR: break; default: leftovers.push(template); break; } }); if (leftovers.length) { this.attributes.push( new ConditionalAttribute({ owner: this, up: this.up, template: leftovers }) ); } } this.eventHandlers = []; } if ( Item ) Component.__proto__ = Item; var Component__proto__ = Component.prototype = Object.create( Item && Item.prototype ); Component__proto__.constructor = Component; Component__proto__.bind = function bind () { if (!this.isAnchor) { this.attributes.forEach(bind$1); this.eventHandlers.forEach(bind$1); initialise( this.instance, { partials: this._partials }, { cssIds: this.up.cssIds } ); if (this.instance.target || this.instance.el) { this.extern = true; } this.bound = true; } }; Component__proto__.bubble = function bubble () { if (!this.dirty) { this.dirty = true; this.up.bubble(); } }; Component__proto__.destroyed = function destroyed () { if (!this.isAnchor && this.instance.fragment) { this.instance.fragment.destroyed(); } }; Component__proto__.detach = function detach () { if (this.isAnchor) { if (this.instance) { return this.instance.fragment.detach(); } return createDocumentFragment(); } return this.instance.fragment.detach(); }; Component__proto__.find = function find (selector, options) { if (this.instance) { return this.instance.fragment.find(selector, options); } }; Component__proto__.findAll = function findAll (selector, options) { if (this.instance) { this.instance.fragment.findAll(selector, options); } }; Component__proto__.findComponent = function findComponent (name, options) { if (!name || this.name === name) { return this.instance; } if (this.instance.fragment) { return this.instance.fragment.findComponent(name, options); } }; Component__proto__.findAllComponents = function findAllComponents (name, options) { var result = options.result; if (this.instance && (!name || this.name === name)) { result.push(this.instance); } if (this.instance) { this.instance.findAllComponents(name, options); } }; Component__proto__.firstNode = function firstNode (skipParent) { if (this.instance) { return this.instance.fragment.firstNode(skipParent); } }; Component__proto__.getContext = function getContext () { var assigns = [], len = arguments.length; while ( len-- ) assigns[ len ] = arguments[ len ]; assigns.unshift(this.instance); return getRactiveContext.apply(null, assigns); }; Component__proto__.rebound = function rebound (update$$1) { this.attributes.forEach(function (x) { return x.rebound(update$$1); }); }; Component__proto__.render = function render$2 (target, occupants) { if (this.isAnchor) { this.rendered = true; this.target = target; if (!checking.length) { checking.push(this.ractive); if (occupants) { this.occupants = occupants; checkAnchors(); this.occupants = null; } else { runloop.scheduleTask(checkAnchors, true); } } } else { this.attributes.forEach(render); this.eventHandlers.forEach(render); if (this.extern) { this.instance.delegate = false; this.instance.render(); } else { render$1(this.instance, target, null, occupants); } this.rendered = true; } }; Component__proto__.shuffled = function shuffled () { Item.prototype.shuffled.call(this); this.instance && !this.instance.isolated && this.instance.fragment && this.instance.fragment.shuffled(); }; Component__proto__.toString = function toString () { if (this.instance) { return this.instance.toHTML(); } }; Component__proto__.unbind = function unbind$1 (view) { if (!this.isAnchor) { this.bound = false; this.attributes.forEach(unbind); if (view) { this.instance.fragment.unbind(); } else { teardown$1(this.instance, function () { return runloop.promise(); }); } } }; Component__proto__.unrender = function unrender$1 (shouldDestroy) { this.shouldDestroy = shouldDestroy; if (this.isAnchor) { if (this.item) { unrenderItem(this, this.item); } this.target = null; if (!checking.length) { checking.push(this.ractive); runloop.scheduleTask(checkAnchors, true); } } else { this.instance.unrender(); this.instance.el = this.instance.target = null; this.attributes.forEach(unrender); this.eventHandlers.forEach(unrender); } this.rendered = false; }; Component__proto__.update = function update$2 () { this.dirty = false; if (this.instance) { this.instance.fragment.update(); this.attributes.forEach(update); this.eventHandlers.forEach(update); } }; return Component; }(Item)); function addChild(meta) { if (this.item) { this.removeChild(this.item); } var child = meta.instance; meta.anchor = this; meta.up = this.up; meta.name = meta.nameOption || this.name; this.name = meta.name; if (!child.isolated) { child.viewmodel.attached(this.up); } // render as necessary if (this.rendered) { renderItem(this, meta); } } function removeChild(meta) { // unrender as necessary if (this.item === meta) { unrenderItem(this, meta); this.name = this.template.n; } } function renderItem(anchor, meta) { if (!anchor.rendered) { return; } meta.shouldDestroy = false; meta.up = anchor.up; anchor.item = meta; anchor.instance = meta.instance; var nextNode = anchor.up.findNextNode(anchor); if (meta.instance.fragment.rendered) { meta.instance.unrender(); } meta.partials = meta.instance.partials; meta.instance.partials = assign(create(meta.partials), meta.partials, anchor._partials); meta.instance.fragment.unbind(true); meta.instance.fragment.componentParent = anchor.up; meta.instance.fragment.bind(meta.instance.viewmodel); anchor.attributes.forEach(bind$1); anchor.eventHandlers.forEach(bind$1); anchor.attributes.forEach(render); anchor.eventHandlers.forEach(render); var target = anchor.up.findParentNode(); render$1(meta.instance, target, target.contains(nextNode) ? nextNode : null, anchor.occupants); if (meta.lastBound !== anchor) { meta.lastBound = anchor; } } function unrenderItem(anchor, meta) { if (!anchor.rendered) { return; } meta.shouldDestroy = true; meta.instance.unrender(); anchor.eventHandlers.forEach(unrender); anchor.attributes.forEach(unrender); anchor.eventHandlers.forEach(unbind); anchor.attributes.forEach(unbind); meta.instance.el = meta.instance.anchor = null; meta.instance.fragment.componentParent = null; meta.up = null; meta.anchor = null; anchor.item = null; anchor.instance = null; } var checking = []; function checkAnchors() { var list = checking; checking = []; list.forEach(updateAnchors); } function setupArgsFn(item, template, fragment, opts) { if ( opts === void 0 ) opts = {}; if (template && template.f && template.f.s) { item.fn = getFunction(template.f.s, template.f.r.length); if (opts.register === true) { item.models = resolveArgs(item, template, fragment, opts); } } } function resolveArgs(item, template, fragment, opts) { if ( opts === void 0 ) opts = {}; return template.f.r.map(function (ref, i) { var model; if (opts.specialRef && (model = opts.specialRef(ref, i))) { return model; } model = resolveReference(fragment, ref); if (opts.register === true) { model.register(item); } return model; }); } function teardownArgsFn(item, template) { if (template && template.f && template.f.s) { if (item.models) { item.models.forEach(function (m) { if (m && m.unregister) { m.unregister(item); } }); } item.models = null; } } var missingDecorator = { update: noop, teardown: noop }; var Decorator = function Decorator(options) { this.owner = options.owner || options.up.owner || findElement(options.up); this.element = this.owner.attributeByName ? this.owner : findElement(options.up); this.up = options.up || this.owner.up; this.ractive = this.owner.ractive; var template = (this.template = options.template); this.name = template.n; this.node = null; this.handle = null; this.element.decorators.push(this); }; var Decorator__proto__ = Decorator.prototype; Decorator__proto__.bind = function bind () { // if the owner is the elment, make sure the context includes the element var frag = this.element === this.owner ? new Fragment({ owner: this.owner }) : this.up; setupArgsFn(this, this.template, frag, { register: true }); }; Decorator__proto__.bubble = function bubble () { if (!this.dirty) { this.dirty = true; // decorators may be owned directly by an element or by a fragment if conditional this.owner.bubble(); this.up.bubble(); } }; Decorator__proto__.destroyed = function destroyed () { if (this.handle) { this.handle.teardown(); this.handle = null; } this.shouldDestroy = true; }; Decorator__proto__.handleChange = function handleChange () { this.bubble(); }; Decorator__proto__.rebind = function rebind (next, previous, safe) { var idx = this.models.indexOf(previous); if (!~idx) { return; } next = rebindMatch(this.template.f.r[idx], next, previous); if (next === previous) { return; } previous.unregister(this); this.models.splice(idx, 1, next); if (next) { next.addShuffleRegister(this, 'mark'); } if (!safe) { this.bubble(); } }; Decorator__proto__.rebound = function rebound (update) { teardownArgsFn(this, this.template); setupArgsFn(this, this.template, this.up, { register: true }); if (update) { this.bubble(); } }; Decorator__proto__.render = function render () { var this$1 = this; this.shouldDestroy = false; if (this.handle) { this.unrender(); } runloop.scheduleTask(function () { // bail if the host element has managed to become unrendered if (!this$1.element.rendered) { return; } var fn = findInViewHierarchy('decorators', this$1.ractive, this$1.name); if (!fn) { warnOnce(missingPlugin(this$1.name, 'decorator')); this$1.handle = missingDecorator; return; } this$1.node = this$1.element.node; var args; if (this$1.fn) { args = this$1.models.map(function (model) { if (!model) { return undefined; } return model.get(); }); args = this$1.fn.apply(this$1.ractive, args); } this$1.handle = fn.apply(this$1.ractive, [this$1.node].concat(args)); if (!this$1.handle || !this$1.handle.teardown) { throw new Error( ("The '" + (this$1.name) + "' decorator must return an object with a teardown method") ); } // watch out for decorators that cause their host element to be unrendered if (this$1.shouldDestroy) { this$1.destroyed(); } }, true); }; Decorator__proto__.toString = function toString () { return ''; }; Decorator__proto__.unbind = function unbind () { teardownArgsFn(this, this.template); }; Decorator__proto__.unrender = function unrender (shouldDestroy) { if ((!shouldDestroy || this.element.rendered) && this.handle) { this.handle.teardown(); this.handle = null; } }; Decorator__proto__.update = function update () { var instance = this.handle; if (!this.dirty) { if (instance && instance.invalidate) { runloop.scheduleTask(function () { return instance.invalidate(); }, true); } return; } this.dirty = false; if (instance) { if (!instance.update) { this.unrender(); this.render(); } else { var args = this.models.map(function (model) { return model && model.get(); }); instance.update.apply(this.ractive, this.fn.apply(this.ractive, args)); } } }; Decorator.prototype.firstNode = noop; var Doctype = (function (Item) { function Doctype () { Item.apply(this, arguments); } if ( Item ) Doctype.__proto__ = Item; var Doctype__proto__ = Doctype.prototype = Object.create( Item && Item.prototype ); Doctype__proto__.constructor = Doctype; Doctype__proto__.toString = function toString () { return '<!DOCTYPE' + this.template.a + '>'; }; return Doctype; }(Item)); var proto$2 = Doctype.prototype; proto$2.bind = proto$2.render = proto$2.teardown = proto$2.unbind = proto$2.unrender = proto$2.update = noop; var Binding = function Binding(element, name) { if ( name === void 0 ) name = 'value'; this.element = element; this.ractive = element.ractive; this.attribute = element.attributeByName[name]; var interpolator = this.attribute.interpolator; interpolator.twowayBinding = this; var model = interpolator.model; if (model.isReadonly && !model.setRoot) { var keypath = model.getKeypath().replace(/^@/, ''); warnOnceIfDebug( ("Cannot use two-way binding on <" + (element.name) + "> element: " + keypath + " is read-only. To suppress this warning use <" + (element.name) + " twoway='false'...>"), { ractive: this.ractive } ); return false; } this.attribute.isTwoway = true; this.model = model; // initialise value, if it's undefined var value = model.get(); this.wasUndefined = isUndefined(value); if (isUndefined(value) && this.getInitialValue) { value = this.getInitialValue(); model.set(value); } this.lastVal(true, value); var parentForm = findElement(this.element, false, 'form'); if (parentForm) { this.resetValue = value; parentForm.formBindings.push(this); } }; var Binding__proto__ = Binding.prototype; Binding__proto__.bind = function bind () { this.model.registerTwowayBinding(this); }; Binding__proto__.handleChange = function handleChange () { var this$1 = this; var value = this.getValue(); if (this.lastVal() === value) { return; } runloop.start(); this.attribute.locked = true; this.model.set(value); this.lastVal(true, value); // if the value changes before observers fire, unlock to be updatable cause something weird and potentially freezy is up if (this.model.get() !== value) { this.attribute.locked = false; } else { runloop.scheduleTask(function () { return (this$1.attribute.locked = false); }); } runloop.end(); }; Binding__proto__.lastVal = function lastVal (setting, value) { if (setting) { this.lastValue = value; } else { return this.lastValue; } }; Binding__proto__.rebind = function rebind (next, previous) { var this$1 = this; if (this.model && this.model === previous) { previous.unregisterTwowayBinding(this); } if (next) { this.model = next; runloop.scheduleTask(function () { return next.registerTwowayBinding(this$1); }); } }; Binding__proto__.rebound = function rebound () { if (this.model) { this.model.unregisterTwowayBinding(this); } this.model = this.attribute.interpolator.model; this.model && this.model.registerTwowayBinding(this); }; Binding__proto__.render = function render () { this.node = this.element.node; this.node._ractive.binding = this; this.rendered = true; // TODO is this used anywhere? }; Binding__proto__.setFromNode = function setFromNode (node) { this.model.set(node.value); }; Binding__proto__.unbind = function unbind () { this.model && this.model.unregisterTwowayBinding(this); }; Binding.prototype.unrender = noop; // This is the handler for DOM events that would lead to a change in the model // (i.e. change, sometimes, input, and occasionally click and keyup) function handleDomEvent() { this._ractive.binding.handleChange(); } var CheckboxBinding = (function (Binding) { function CheckboxBinding(element) { Binding.call(this, element, 'checked'); } if ( Binding ) CheckboxBinding.__proto__ = Binding; var CheckboxBinding__proto__ = CheckboxBinding.prototype = Object.create( Binding && Binding.prototype ); CheckboxBinding__proto__.constructor = CheckboxBinding; CheckboxBinding__proto__.render = function render () { Binding.prototype.render.call(this); this.element.on('change', handleDomEvent); if (this.node.attachEvent) { this.element.on('click', handleDomEvent); } }; CheckboxBinding__proto__.unrender = function unrender () { this.element.off('change', handleDomEvent); this.element.off('click', handleDomEvent); }; CheckboxBinding__proto__.getInitialValue = function getInitialValue () { return !!this.element.getAttribute('checked'); }; CheckboxBinding__proto__.getValue = function getValue () { return this.node.checked; }; CheckboxBinding__proto__.setFromNode = function setFromNode (node) { this.model.set(node.checked); }; return CheckboxBinding; }(Binding)); function getBindingGroup(group, model, getValue) { var hash = group + "-bindingGroup"; return model[hash] || (model[hash] = new BindingGroup(hash, model, getValue)); } var BindingGroup = function BindingGroup(hash, model, getValue) { var this$1 = this; this.model = model; this.hash = hash; this.getValue = function () { this$1.value = getValue.call(this$1); return this$1.value; }; this.bindings = []; }; var BindingGroup__proto__ = BindingGroup.prototype; BindingGroup__proto__.add = function add (binding) { this.bindings.push(binding); }; BindingGroup__proto__.bind = function bind () { this.value = this.model.get(); this.model.registerTwowayBinding(this); this.bound = true; }; BindingGroup__proto__.remove = function remove (binding) { removeFromArray(this.bindings, binding); if (!this.bindings.length) { this.unbind(); } }; BindingGroup__proto__.unbind = function unbind () { this.model.unregisterTwowayBinding(this); this.bound = false; delete this.model[this.hash]; }; BindingGroup.prototype.rebind = Binding.prototype.rebind; var push$1 = [].push; function getValue() { var this$1 = this; var all = this.bindings .filter(function (b) { return b.node && b.node.checked; }) .map(function (b) { return b.element.getAttribute('value'); }); var res = []; all.forEach(function (v) { if (!this$1.bindings[0].arrayContains(res, v)) { res.push(v); } }); return res; } var CheckboxNameBinding = (function (Binding) { function CheckboxNameBinding(element) { Binding.call(this, element, 'name'); this.checkboxName = true; // so that ractive.updateModel() knows what to do with this // Each input has a reference to an array containing it and its // group, as two-way binding depends on being able to ascertain // the status of all inputs within the group this.group = getBindingGroup('checkboxes', this.model, getValue); this.group.add(this); if (this.noInitialValue) { this.group.noInitialValue = true; } // If no initial value was set, and this input is checked, we // update the model if (this.group.noInitialValue && this.element.getAttribute('checked')) { var existingValue = this.model.get(); var bindingValue = this.element.getAttribute('value'); if (!this.arrayContains(existingValue, bindingValue)) { push$1.call(existingValue, bindingValue); // to avoid triggering runloop with array adaptor } } } if ( Binding ) CheckboxNameBinding.__proto__ = Binding; var CheckboxNameBinding__proto__ = CheckboxNameBinding.prototype = Object.create( Binding && Binding.prototype ); CheckboxNameBinding__proto__.constructor = CheckboxNameBinding; CheckboxNameBinding__proto__.bind = function bind () { if (!this.group.bound) { this.group.bind(); } }; CheckboxNameBinding__proto__.getInitialValue = function getInitialValue () { // This only gets called once per group (of inputs that // share a name), because it only gets called if there // isn't an initial value. By the same token, we can make // a note of that fact that there was no initial value, // and populate it using any `checked` attributes that // exist (which users should avoid, but which we should // support anyway to avoid breaking expectations) this.noInitialValue = true; // TODO are noInitialValue and wasUndefined the same thing? return []; }; CheckboxNameBinding__proto__.getValue = function getValue () { return this.group.value; }; CheckboxNameBinding__proto__.handleChange = function handleChange () { this.isChecked = this.element.node.checked; this.group.value = this.model.get().slice(); var value = this.element.getAttribute('value'); if (this.isChecked && !this.arrayContains(this.group.value, value)) { this.group.value.push(value); } else if (!this.isChecked && this.arrayContains(this.group.value, value)) { this.removeFromArray(this.group.value, value); } // make sure super knows there's a change this.lastValue = null; Binding.prototype.handleChange.call(this); }; CheckboxNameBinding__proto__.render = function render () { Binding.prototype.render.call(this); var node = this.node; var existingValue = this.model.get(); var bindingValue = this.element.getAttribute('value'); if (isArray(existingValue)) { this.isChecked = this.arrayContains(existingValue, bindingValue); } else { this.isChecked = this.element.compare(existingValue, bindingValue); } node.name = '{{' + this.model.getKeypath() + '}}'; node.checked = this.isChecked; this.element.on('change', handleDomEvent); // in case of IE emergency, bind to click event as well if (this.node.attachEvent) { this.element.on('click', handleDomEvent); } }; CheckboxNameBinding__proto__.setFromNode = function setFromNode (node) { this.group.bindings.forEach(function (binding) { return (binding.wasUndefined = true); }); if (node.checked) { var valueSoFar = this.group.getValue(); valueSoFar.push(this.element.getAttribute('value')); this.group.model.set(valueSoFar); } }; CheckboxNameBinding__proto__.unbind = function unbind () { this.group.remove(this); }; CheckboxNameBinding__proto__.unrender = function unrender () { var el = this.element; el.off('change', handleDomEvent); el.off('click', handleDomEvent); }; CheckboxNameBinding__proto__.arrayContains = function arrayContains (selectValue, optionValue) { var this$1 = this; var i = selectValue.length; while (i--) { if (this$1.element.compare(optionValue, selectValue[i])) { return true; } } return false; }; CheckboxNameBinding__proto__.removeFromArray = function removeFromArray (array, item) { var this$1 = this; if (!array) { return; } var i = array.length; while (i--) { if (this$1.element.compare(item, array[i])) { array.splice(i, 1); } } }; return CheckboxNameBinding; }(Binding)); var ContentEditableBinding = (function (Binding) { function ContentEditableBinding () { Binding.apply(this, arguments); } if ( Binding ) ContentEditableBinding.__proto__ = Binding; var ContentEditableBinding__proto__ = ContentEditableBinding.prototype = Object.create( Binding && Binding.prototype ); ContentEditableBinding__proto__.constructor = ContentEditableBinding; ContentEditableBinding__proto__.getInitialValue = function getInitialValue () { return this.element.fragment ? this.element.fragment.toString() : ''; }; ContentEditableBinding__proto__.getValue = function getValue () { return this.element.node.innerHTML; }; ContentEditableBinding__proto__.render = function render () { Binding.prototype.render.call(this); var el = this.element; el.on('change', handleDomEvent); el.on('blur', handleDomEvent); if (!this.ractive.lazy) { el.on('input', handleDomEvent); if (this.node.attachEvent) { el.on('keyup', handleDomEvent); } } }; ContentEditableBinding__proto__.setFromNode = function setFromNode (node) { this.model.set(node.innerHTML); }; ContentEditableBinding__proto__.unrender = function unrender () { var el = this.element; el.off('blur', handleDomEvent); el.off('change', handleDomEvent); el.off('input', handleDomEvent); el.off('keyup', handleDomEvent); }; return ContentEditableBinding; }(Binding)); function handleBlur() { handleDomEvent.call(this); var value = this._ractive.binding.model.get(); this.value = value == undefined ? '' : value; } function handleDelay(delay) { var timeout; return function() { var this$1 = this; if (timeout) { clearTimeout(timeout); } timeout = setTimeout(function () { var binding = this$1._ractive.binding; if (binding.rendered) { handleDomEvent.call(this$1); } timeout = null; }, delay); }; } var GenericBinding = (function (Binding) { function GenericBinding () { Binding.apply(this, arguments); } if ( Binding ) GenericBinding.__proto__ = Binding; var GenericBinding__proto__ = GenericBinding.prototype = Object.create( Binding && Binding.prototype ); GenericBinding__proto__.constructor = GenericBinding; GenericBinding__proto__.getInitialValue = function getInitialValue () { return ''; }; GenericBinding__proto__.getValue = function getValue () { return this.node.value; }; GenericBinding__proto__.render = function render () { Binding.prototype.render.call(this); // any lazy setting for this element overrides the root // if the value is a number, it's a timeout var lazy = this.ractive.lazy; var timeout = false; var el = this.element; if ('lazy' in this.element) { lazy = this.element.lazy; } if (isNumeric(lazy)) { timeout = +lazy; lazy = false; } this.handler = timeout ? handleDelay(timeout) : handleDomEvent; var node = this.node; el.on('change', handleDomEvent); if (node.type !== 'file') { if (!lazy) { el.on('input', this.handler); // IE is a special snowflake if (node.attachEvent) { el.on('keyup', this.handler); } } el.on('blur', handleBlur); } }; GenericBinding__proto__.unrender = function unrender () { var el = this.element; this.rendered = false; el.off('change', handleDomEvent); el.off('input', this.handler); el.off('keyup', this.handler); el.off('blur', handleBlur); }; return GenericBinding; }(Binding)); var FileBinding = (function (GenericBinding) { function FileBinding () { GenericBinding.apply(this, arguments); } if ( GenericBinding ) FileBinding.__proto__ = GenericBinding; var FileBinding__proto__ = FileBinding.prototype = Object.create( GenericBinding && GenericBinding.prototype ); FileBinding__proto__.constructor = FileBinding; FileBinding__proto__.getInitialValue = function getInitialValue () { /* istanbul ignore next */ return undefined; }; FileBinding__proto__.getValue = function getValue () { /* istanbul ignore next */ return this.node.files; }; FileBinding__proto__.render = function render () { /* istanbul ignore next */ this.element.lazy = false; /* istanbul ignore next */ GenericBinding.prototype.render.call(this); }; FileBinding__proto__.setFromNode = function setFromNode (node) { /* istanbul ignore next */ this.model.set(node.files); }; return FileBinding; }(GenericBinding)); function getSelectedOptions(select) { /* istanbul ignore next */ return select.selectedOptions ? toArray(select.selectedOptions) : select.options ? toArray(select.options).filter(function (option) { return option.selected; }) : []; } var MultipleSelectBinding = (function (Binding) { function MultipleSelectBinding () { Binding.apply(this, arguments); } if ( Binding ) MultipleSelectBinding.__proto__ = Binding; var MultipleSelectBinding__proto__ = MultipleSelectBinding.prototype = Object.create( Binding && Binding.prototype ); MultipleSelectBinding__proto__.constructor = MultipleSelectBinding; MultipleSelectBinding__proto__.getInitialValue = function getInitialValue () { return this.element.options .filter(function (option) { return option.getAttribute('selected'); }) .map(function (option) { return option.getAttribute('value'); }); }; MultipleSelectBinding__proto__.getValue = function getValue () { var options = this.element.node.options; var len = options.length; var selectedValues = []; for (var i = 0; i < len; i += 1) { var option = options[i]; if (option.selected) { var optionValue = option._ractive ? option._ractive.value : option.value; selectedValues.push(optionValue); } } return selectedValues; }; MultipleSelectBinding__proto__.handleChange = function handleChange () { var attribute = this.attribute; var previousValue = attribute.getValue(); var value = this.getValue(); if (isUndefined(previousValue) || !arrayContentsMatch(value, previousValue)) { Binding.prototype.handleChange.call(this); } return this; }; MultipleSelectBinding__proto__.render = function render () { Binding.prototype.render.call(this); this.element.on('change', handleDomEvent); if (isUndefined(this.model.get())) { // get value from DOM, if possible this.handleChange(); } }; MultipleSelectBinding__proto__.setFromNode = function setFromNode (node) { var selectedOptions = getSelectedOptions(node); var i = selectedOptions.length; var result = new Array(i); while (i--) { var option = selectedOptions[i]; result[i] = option._ractive ? option._ractive.value : option.value; } this.model.set(result); }; MultipleSelectBinding__proto__.unrender = function unrender () { this.element.off('change', handleDomEvent); }; return MultipleSelectBinding; }(Binding)); var NumericBinding = (function (GenericBinding) { function NumericBinding () { GenericBinding.apply(this, arguments); } if ( GenericBinding ) NumericBinding.__proto__ = GenericBinding; var NumericBinding__proto__ = NumericBinding.prototype = Object.create( GenericBinding && GenericBinding.prototype ); NumericBinding__proto__.constructor = NumericBinding; NumericBinding__proto__.getInitialValue = function getInitialValue () { return undefined; }; NumericBinding__proto__.getValue = function getValue () { var value = parseFloat(this.node.value); return isNaN(value) ? undefined : value; }; NumericBinding__proto__.setFromNode = function setFromNode (node) { var value = parseFloat(node.value); if (!isNaN(value)) { this.model.set(value); } }; return NumericBinding; }(GenericBinding)); var siblings = {}; function getSiblings(hash) { return siblings[hash] || (siblings[hash] = []); } var RadioBinding = (function (Binding) { function RadioBinding(element) { Binding.call(this, element, 'checked'); this.siblings = getSiblings(this.ractive._guid + this.element.getAttribute('name')); this.siblings.push(this); } if ( Binding ) RadioBinding.__proto__ = Binding; var RadioBinding__proto__ = RadioBinding.prototype = Object.create( Binding && Binding.prototype ); RadioBinding__proto__.constructor = RadioBinding; RadioBinding__proto__.getValue = function getValue () { return this.node.checked; }; RadioBinding__proto__.handleChange = function handleChange () { runloop.start(); this.siblings.forEach(function (binding) { binding.model.set(binding.getValue()); }); runloop.end(); }; RadioBinding__proto__.render = function render () { Binding.prototype.render.call(this); this.element.on('change', handleDomEvent); if (this.node.attachEvent) { this.element.on('click', handleDomEvent); } }; RadioBinding__proto__.setFromNode = function setFromNode (node) { this.model.set(node.checked); }; RadioBinding__proto__.unbind = function unbind () { removeFromArray(this.siblings, this); }; RadioBinding__proto__.unrender = function unrender () { this.element.off('change', handleDomEvent); this.element.off('click', handleDomEvent); }; return RadioBinding; }(Binding)); function getValue$1() { var checked = this.bindings.filter(function (b) { return b.node.checked; }); if (checked.length > 0) { return checked[0].element.getAttribute('value'); } } var RadioNameBinding = (function (Binding) { function RadioNameBinding(element) { var this$1 = this; Binding.call(this, element, 'name'); this.group = getBindingGroup('radioname', this.model, getValue$1); this.group.add(this); if (element.checked) { this.group.value = this.getValue(); } this.attribute.interpolator.pathChanged = function () { return this$1.updateName(); }; } if ( Binding ) RadioNameBinding.__proto__ = Binding; var RadioNameBinding__proto__ = RadioNameBinding.prototype = Object.create( Binding && Binding.prototype ); RadioNameBinding__proto__.constructor = RadioNameBinding; RadioNameBinding__proto__.bind = function bind () { if (!this.group.bound) { this.group.bind(); } }; RadioNameBinding__proto__.getInitialValue = function getInitialValue () { if (this.element.getAttribute('checked')) { return this.element.getAttribute('value'); } }; RadioNameBinding__proto__.getValue = function getValue () { return this.element.getAttribute('value'); }; RadioNameBinding__proto__.handleChange = function handleChange () { // If this <input> is the one that's checked, then the value of its // `name` model gets set to its value if (this.node.checked) { this.group.value = this.getValue(); Binding.prototype.handleChange.call(this); } this.updateName(); }; RadioNameBinding__proto__.lastVal = function lastVal (setting, value) { if (!this.group) { return; } if (setting) { this.group.lastValue = value; } else { return this.group.lastValue; } }; RadioNameBinding__proto__.rebind = function rebind (next, previous) { Binding.prototype.rebind.call(this, next, previous); this.updateName(); }; RadioNameBinding__proto__.rebound = function rebound (update) { Binding.prototype.rebound.call(this, update); this.updateName(); }; RadioNameBinding__proto__.render = function render () { Binding.prototype.render.call(this); var node = this.node; this.updateName(); node.checked = this.element.compare(this.model.get(), this.element.getAttribute('value')); this.element.on('change', handleDomEvent); if (node.attachEvent) { this.element.on('click', handleDomEvent); } }; RadioNameBinding__proto__.setFromNode = function setFromNode (node) { if (node.checked) { this.group.model.set(this.element.getAttribute('value')); } }; RadioNameBinding__proto__.unbind = function unbind () { this.group.remove(this); }; RadioNameBinding__proto__.unrender = function unrender () { var el = this.element; el.off('change', handleDomEvent); el.off('click', handleDomEvent); }; RadioNameBinding__proto__.updateName = function updateName () { if (this.node) { this.node.name = "{{" + (this.model.getKeypath()) + "}}"; } }; return RadioNameBinding; }(Binding)); var SingleSelectBinding = (function (Binding) { function SingleSelectBinding () { Binding.apply(this, arguments); } if ( Binding ) SingleSelectBinding.__proto__ = Binding; var SingleSelectBinding__proto__ = SingleSelectBinding.prototype = Object.create( Binding && Binding.prototype ); SingleSelectBinding__proto__.constructor = SingleSelectBinding; SingleSelectBinding__proto__.forceUpdate = function forceUpdate () { var this$1 = this; var value = this.getValue(); if (value !== undefined) { this.attribute.locked = true; runloop.scheduleTask(function () { return (this$1.attribute.locked = false); }); this.model.set(value); } }; SingleSelectBinding__proto__.getInitialValue = function getInitialValue () { if (this.element.getAttribute('value') !== undefined) { return; } var options = this.element.options; var len = options.length; if (!len) { return; } var value; var optionWasSelected; var i = len; // take the final selected option... while (i--) { var option = options[i]; if (option.getAttribute('selected')) { if (!option.getAttribute('disabled')) { value = option.getAttribute('value'); } optionWasSelected = true; break; } } // or the first non-disabled option, if none are selected if (!optionWasSelected) { while (++i < len) { if (!options[i].getAttribute('disabled')) { value = options[i].getAttribute('value'); break; } } } // This is an optimisation (aka hack) that allows us to forgo some // other more expensive work // TODO does it still work? seems at odds with new architecture if (value !== undefined) { this.element.attributeByName.value.value = value; } return value; }; SingleSelectBinding__proto__.getValue = function getValue () { var options = this.node.options; var len = options.length; var i; for (i = 0; i < len; i += 1) { var option = options[i]; if (options[i].selected && !options[i].disabled) { return option._ractive ? option._ractive.value : option.value; } } }; SingleSelectBinding__proto__.render = function render () { Binding.prototype.render.call(this); this.element.on('change', handleDomEvent); }; SingleSelectBinding__proto__.setFromNode = function setFromNode (node) { var option = getSelectedOptions(node)[0]; this.model.set(option._ractive ? option._ractive.value : option.value); }; SingleSelectBinding__proto__.unrender = function unrender () { this.element.off('change', handleDomEvent); }; return SingleSelectBinding; }(Binding)); function isBindable(attribute) { // The fragment must be a single non-string fragment if ( !attribute || !attribute.template.f || attribute.template.f.length !== 1 || attribute.template.f[0].s ) { return false; } // A binding is an interpolator `{{ }}`, yey. if (attribute.template.f[0].t === INTERPOLATOR) { return true; } // The above is probably the only true case. For the rest, show an appropriate // warning before returning false. // You can't bind a triple curly. HTML values on an attribute makes no sense. if (attribute.template.f[0].t === TRIPLE) { warnIfDebug('It is not possible create a binding using a triple mustache.'); } return false; } function selectBinding(element) { var name = element.name; var attributes = element.attributeByName; if (name !== 'input' && name !== 'textarea' && name !== 'select' && !attributes.contenteditable) { return; } var isBindableByValue = isBindable(attributes.value); var isBindableByContentEditable = isBindable(attributes.contenteditable); var isContentEditable = element.getAttribute('contenteditable'); // contenteditable // Bind if the contenteditable is true or a binding that may become true. if ((isContentEditable || isBindableByContentEditable) && isBindableByValue) { return ContentEditableBinding; } // <input> if (name === 'input') { var type = element.getAttribute('type'); if (type === 'radio') { var isBindableByName = isBindable(attributes.name); var isBindableByChecked = isBindable(attributes.checked); // For radios we can either bind the name or checked, but not both. // Name binding is handed instead. if (isBindableByName && isBindableByChecked) { warnIfDebug( 'A radio input can have two-way binding on its name attribute, or its checked attribute - not both', { ractive: element.root } ); return RadioNameBinding; } if (isBindableByName) { return RadioNameBinding; } if (isBindableByChecked) { return RadioBinding; } // Dead end. Unknown binding on radio input. return null; } if (type === 'checkbox') { var isBindableByName$1 = isBindable(attributes.name); var isBindableByChecked$1 = isBindable(attributes.checked); // A checkbox with bindings for both name and checked. Checked treated as // the checkbox value, name is treated as a regular binding. // // See https://github.com/ractivejs/ractive/issues/1749 if (isBindableByName$1 && isBindableByChecked$1) { return CheckboxBinding; } if (isBindableByName$1) { return CheckboxNameBinding; } if (isBindableByChecked$1) { return CheckboxBinding; } // Dead end. Unknown binding on checkbox input. return null; } if (type === 'file' && isBindableByValue) { return FileBinding; } if (type === 'number' && isBindableByValue) { return NumericBinding; } if (type === 'range' && isBindableByValue) { return NumericBinding; } // Some input of unknown type (browser usually falls back to text). if (isBindableByValue) { return GenericBinding; } // Dead end. Some unknown input and an unbindable. return null; } // <select> if (name === 'select' && isBindableByValue) { return element.getAttribute('multiple') ? MultipleSelectBinding : SingleSelectBinding; } // <textarea> if (name === 'textarea' && isBindableByValue) { return GenericBinding; } // Dead end. Some unbindable element. return null; } var endsWithSemi = /;\s*$/; var Element = (function (ContainerItem) { function Element(options) { var this$1 = this; ContainerItem.call(this, options); this.name = options.template.e.toLowerCase(); // find parent element this.parent = findElement(this.up, false); if (this.parent && this.parent.name === 'option') { throw new Error( ("An <option> element cannot contain other elements (encountered <" + (this.name) + ">)") ); } this.decorators = []; // create attributes this.attributeByName = {}; var attrs; var n, attr, val, cls, name, template, leftovers; var m = this.template.m; var len = (m && m.length) || 0; for (var i = 0; i < len; i++) { template = m[i]; if (template.g) { (this$1.statics || (this$1.statics = {}))[template.n] = isString(template.f) ? template.f : template.n; } else { switch (template.t) { case ATTRIBUTE: case BINDING_FLAG: case DECORATOR: case EVENT: case TRANSITION: attr = createItem({ owner: this$1, up: this$1.up, template: template }); n = template.n; attrs = attrs || (attrs = this$1.attributes = []); if (n === 'value') { val = attr; } else if (n === 'name') { name = attr; } else if (n === 'class') { cls = attr; } else { attrs.push(attr); } break; case DELEGATE_FLAG: this$1.delegate = false; break; default: (leftovers || (leftovers = [])).push(template); break; } } } if (val) { attrs.push(val); } if (name) { attrs.push(name); } if (cls) { attrs.unshift(cls); } if (leftovers) { (attrs || (this.attributes = [])).push( new ConditionalAttribute({ owner: this, up: this.up, template: leftovers }) ); // empty leftovers array leftovers = []; } // create children if (options.template.f && !options.deferContent) { this.fragment = new Fragment({ template: options.template.f, owner: this, cssIds: null }); } this.binding = null; // filled in later } if ( ContainerItem ) Element.__proto__ = ContainerItem; var Element__proto__ = Element.prototype = Object.create( ContainerItem && ContainerItem.prototype ); Element__proto__.constructor = Element; Element__proto__.bind = function bind () { var attrs = this.attributes; if (attrs) { attrs.binding = true; var len = attrs.length; for (var i = 0; i < len; i++) { attrs[i].bind(); } attrs.binding = false; } if (this.fragment) { this.fragment.bind(); } // create two-way binding if necessary if (!this.binding) { this.recreateTwowayBinding(); } else { this.binding.bind(); } }; Element__proto__.createTwowayBinding = function createTwowayBinding () { if ('twoway' in this ? this.twoway : this.ractive.twoway) { var Binding = selectBinding(this); if (Binding) { var binding = new Binding(this); if (binding && binding.model) { return binding; } } } }; Element__proto__.destroyed = function destroyed$1 () { if (this.attributes) { this.attributes.forEach(destroyed); } if (this.fragment) { this.fragment.destroyed(); } }; Element__proto__.detach = function detach () { // if this element is no longer rendered, the transitions are complete and the attributes can be torn down if (!this.rendered) { this.destroyed(); } return detachNode(this.node); }; Element__proto__.find = function find (selector, options) { if (this.node && matches(this.node, selector)) { return this.node; } if (this.fragment) { return this.fragment.find(selector, options); } }; Element__proto__.findAll = function findAll (selector, options) { var result = options.result; if (matches(this.node, selector)) { result.push(this.node); } if (this.fragment) { this.fragment.findAll(selector, options); } }; Element__proto__.findNextNode = function findNextNode () { return null; }; Element__proto__.firstNode = function firstNode () { return this.node; }; Element__proto__.getAttribute = function getAttribute (name) { if (this.statics && name in this.statics) { return this.statics[name]; } var attribute = this.attributeByName[name]; return attribute ? attribute.getValue() : undefined; }; Element__proto__.getContext = function getContext () { var assigns = [], len = arguments.length; while ( len-- ) assigns[ len ] = arguments[ len ]; if (this.fragment) { return (ref = this.fragment).getContext.apply(ref, assigns); } if (!this.ctx) { this.ctx = new Context(this.up, this); } assigns.unshift(create(this.ctx)); return assign.apply(null, assigns); var ref; }; Element__proto__.off = function off (event, callback, capture) { if ( capture === void 0 ) capture = false; var delegate = this.up.delegate; var ref = this.listeners && this.listeners[event]; if (!ref) { return; } removeFromArray(ref, callback); if (delegate) { var listeners = (delegate.listeners || (delegate.listeners = [])) && (delegate.listeners[event] || (delegate.listeners[event] = [])); if (listeners.refs && !--listeners.refs) { delegate.off(event, delegateHandler, true); } } else if (this.rendered) { var n = this.node; var add = n.addEventListener; var rem = n.removeEventListener; if (!ref.length) { rem.call(n, event, handler, capture); } else if (ref.length && !ref.refs && capture) { rem.call(n, event, handler, true); add.call(n, event, handler, false); } } }; Element__proto__.on = function on (event, callback, capture) { if ( capture === void 0 ) capture = false; var delegate = this.up.delegate; var ref = (this.listeners || (this.listeners = {}))[event] || (this.listeners[event] = []); if (delegate) { var listeners = ((delegate.listeners || (delegate.listeners = [])) && delegate.listeners[event]) || (delegate.listeners[event] = []); if (!listeners.refs) { listeners.refs = 0; delegate.on(event, delegateHandler, true); listeners.refs++; } else { listeners.refs++; } } else if (this.rendered) { var n = this.node; var add = n.addEventListener; var rem = n.removeEventListener; if (!ref.length) { add.call(n, event, handler, capture); } else if (ref.length && !ref.refs && capture) { rem.call(n, event, handler, false); add.call(n, event, handler, true); } } addToArray(this.listeners[event], callback); }; Element__proto__.recreateTwowayBinding = function recreateTwowayBinding () { if (this.binding) { this.binding.unbind(); this.binding.unrender(); } if ((this.binding = this.createTwowayBinding())) { this.binding.bind(); if (this.rendered) { this.binding.render(); } } }; Element__proto__.rebound = function rebound (update$$1) { ContainerItem.prototype.rebound.call(this, update$$1); if (this.attributes) { this.attributes.forEach(function (x) { return x.rebound(update$$1); }); } if (this.binding) { this.binding.rebound(update$$1); } }; Element__proto__.render = function render (target, occupants) { var this$1 = this; // TODO determine correct namespace this.namespace = getNamespace(this); var node; var existing = false; if (occupants) { var n; while ((n = occupants.shift())) { if ( n.nodeName.toUpperCase() === this$1.template.e.toUpperCase() && n.namespaceURI === this$1.namespace ) { this$1.node = node = n; existing = true; break; } else { detachNode(n); } } } if (!existing && this.node) { node = this.node; target.appendChild(node); existing = true; } if (!node) { var name = this.template.e; node = createElement( this.namespace === html ? name.toLowerCase() : name, this.namespace, this.getAttribute('is') ); this.node = node; } // tie the node to this vdom element defineProperty(node, '_ractive', { value: { proxy: this }, configurable: true }); if (this.statics) { keys(this.statics).forEach(function (k) { node.setAttribute(k, this$1.statics[k]); }); } if (existing && this.foundNode) { this.foundNode(node); } // register intro before rendering content so children can find the intro var intro = this.intro; if (intro && intro.shouldFire('intro')) { intro.isIntro = true; intro.isOutro = false; runloop.registerTransition(intro); } if (this.fragment) { var children = existing ? toArray(node.childNodes) : undefined; this.fragment.render(node, children); // clean up leftover children if (children) { children.forEach(detachNode); } } if (existing) { // store initial values for two-way binding if (this.binding && this.binding.wasUndefined) { this.binding.setFromNode(node); } // remove unused attributes var i = node.attributes.length; while (i--) { var name$1 = node.attributes[i].name; if (!(name$1 in this$1.attributeByName) && (!this$1.statics || !(name$1 in this$1.statics))) { node.removeAttribute(name$1); } } } // Is this a top-level node of a component? If so, we may need to add // a data-ractive-css attribute, for CSS encapsulation if (this.up.cssIds) { node.setAttribute('data-ractive-css', this.up.cssIds.map(function (x) { return ("{" + x + "}"); }).join(' ')); } if (this.attributes) { var len = this.attributes.length; for (var i$1 = 0; i$1 < len; i$1++) { this$1.attributes[i$1].render(); } } if (this.binding) { this.binding.render(); } if (!this.up.delegate && this.listeners) { var ls = this.listeners; for (var k in ls) { if (ls[k] && ls[k].length) { this$1.node.addEventListener(k, handler, !!ls[k].refs); } } } if (!existing) { target.appendChild(node); } this.rendered = true; }; Element__proto__.toString = function toString () { var this$1 = this; var tagName = this.template.e; var attrs = (this.attributes && this.attributes.map(stringifyAttribute).join('')) || ''; if (this.statics) { keys(this.statics).forEach( function (k) { return k !== 'class' && k !== 'style' && (attrs = " " + k + "=\"" + (this$1.statics[k]) + "\"" + attrs); } ); } // Special case - selected options if (this.name === 'option' && this.isSelected()) { attrs += ' selected'; } // Special case - two-way radio name bindings if (this.name === 'input' && inputIsCheckedRadio(this)) { attrs += ' checked'; } // Special case style and class attributes and directives var style = this.statics ? this.statics.style : undefined; var cls = this.statics ? this.statics.class : undefined; this.attributes && this.attributes.forEach(function (attr) { if (attr.name === 'class') { cls = (cls || '') + (cls ? ' ' : '') + safeAttributeString(attr.getString()); } else if (attr.name === 'style') { style = (style || '') + (style ? ' ' : '') + safeAttributeString(attr.getString()); if (style && !endsWithSemi.test(style)) { style += ';'; } } else if (attr.style) { style = (style || '') + (style ? ' ' : '') + (attr.style) + ": " + (safeAttributeString(attr.getString())) + ";"; } else if (attr.inlineClass && attr.getValue()) { cls = (cls || '') + (cls ? ' ' : '') + attr.inlineClass; } }); // put classes first, then inline style if (style !== undefined) { attrs = ' style' + (style ? ("=\"" + style + "\"") : '') + attrs; } if (cls !== undefined) { attrs = ' class' + (cls ? ("=\"" + cls + "\"") : '') + attrs; } if (this.up.cssIds) { attrs += " data-ractive-css=\"" + (this.up.cssIds.map(function (x) { return ("{" + x + "}"); }).join(' ')) + "\""; } var str = "<" + tagName + attrs + ">"; if (voidElements[this.name.toLowerCase()]) { return str; } // Special case - textarea if (this.name === 'textarea' && this.getAttribute('value') !== undefined) { str += escapeHtml(this.getAttribute('value')); } else if (this.getAttribute('contenteditable') !== undefined) { // Special case - contenteditable str += this.getAttribute('value') || ''; } if (this.fragment) { str += this.fragment.toString(!/^(?:script|style)$/i.test(this.template.e)); // escape text unless script/style } str += "</" + tagName + ">"; return str; }; Element__proto__.unbind = function unbind (view) { var attrs = this.attributes; if (attrs) { attrs.unbinding = true; var len = attrs.length; for (var i = 0; i < len; i++) { attrs[i].unbind(view); } attrs.unbinding = false; } if (this.binding) { this.binding.unbind(view); } if (this.fragment) { this.fragment.unbind(view); } }; Element__proto__.unrender = function unrender (shouldDestroy) { if (!this.rendered) { return; } this.rendered = false; // unrendering before intro completed? complete it now // TODO should be an API for aborting transitions var transition = this.intro; if (transition && transition.complete) { transition.complete(); } // Detach as soon as we can if (this.name === 'option') { // <option> elements detach immediately, so that // their parent <select> element syncs correctly, and // since option elements can't have transitions anyway this.detach(); } else if (shouldDestroy) { runloop.detachWhenReady(this); } // outro transition var outro = this.outro; if (outro && outro.shouldFire('outro')) { outro.isIntro = false; outro.isOutro = true; runloop.registerTransition(outro); } if (this.fragment) { this.fragment.unrender(); } if (this.binding) { this.binding.unrender(); } }; Element__proto__.update = function update () { if (this.dirty) { this.dirty = false; var attrs = this.attributes; if (attrs) { var len = attrs.length; for (var i = 0; i < len; i++) { attrs[i].update(); } } if (this.fragment) { this.fragment.update(); } } }; return Element; }(ContainerItem)); function inputIsCheckedRadio(element) { var nameAttr = element.attributeByName.name; return ( element.getAttribute('type') === 'radio' && (nameAttr || {}).interpolator && element.getAttribute('value') === nameAttr.interpolator.model.get() ); } function stringifyAttribute(attribute) { var str = attribute.toString(); return str ? ' ' + str : ''; } function getNamespace(element) { // Use specified namespace... var xmlns$$1 = element.getAttribute('xmlns'); if (xmlns$$1) { return xmlns$$1; } // ...or SVG namespace, if this is an <svg> element if (element.name === 'svg') { return svg$1; } var parent = element.parent; if (parent) { // ...or HTML, if the parent is a <foreignObject> if (parent.name === 'foreignobject') { return html; } // ...or inherit from the parent node return parent.node.namespaceURI; } return element.ractive.el.namespaceURI; } function delegateHandler(ev) { var name = ev.type; var end = ev.currentTarget; var endEl = end._ractive && end._ractive.proxy; var node = ev.target; var bubble = true; var listeners; // starting with the origin node, walk up the DOM looking for ractive nodes with a matching event listener while (bubble && node && node !== end) { var proxy = node._ractive && node._ractive.proxy; if (proxy && proxy.up.delegate === endEl && shouldFire(ev, node, end)) { listeners = proxy.listeners && proxy.listeners[name]; if (listeners) { var len = listeners.length; for (var i = 0; i < len; i++) { bubble = listeners[i].call(node, ev) !== false && bubble; } } } node = node.parentNode || node.correspondingUseElement; // SVG with a <use> element in certain environments } return bubble; } var UIEvent = win !== null ? win.UIEvent : null; function shouldFire(event, start, end) { if (UIEvent && event instanceof UIEvent) { var node = start; while (node && node !== end) { if (node.disabled) { return false; } node = node.parentNode || node.correspondingUseElement; } } return true; } function handler(ev) { var this$1 = this; var el = this._ractive.proxy; var listeners; if (el.listeners && (listeners = el.listeners[ev.type])) { var len = listeners.length; for (var i = 0; i < len; i++) { listeners[i].call(this$1, ev); } } } var Form = (function (Element) { function Form(options) { Element.call(this, options); this.formBindings = []; } if ( Element ) Form.__proto__ = Element; var Form__proto__ = Form.prototype = Object.create( Element && Element.prototype ); Form__proto__.constructor = Form; Form__proto__.render = function render (target, occupants) { Element.prototype.render.call(this, target, occupants); this.on('reset', handleReset); }; Form__proto__.unrender = function unrender (shouldDestroy) { this.off('reset', handleReset); Element.prototype.unrender.call(this, shouldDestroy); }; return Form; }(Element)); function handleReset() { var element = this._ractive.proxy; runloop.start(); element.formBindings.forEach(updateModel); runloop.end(); } function updateModel(binding) { binding.model.set(binding.resetValue); } var DOMEvent = function DOMEvent(name, owner) { if (name.indexOf('*') !== -1) { fatal( ("Only component proxy-events may contain \"*\" wildcards, <" + (owner.name) + " on-" + name + "=\"...\"/> is not valid") ); } this.name = name; this.owner = owner; this.handler = null; }; var DOMEvent__proto__ = DOMEvent.prototype; DOMEvent__proto__.bind = function bind () {}; DOMEvent__proto__.render = function render (directive) { var this$1 = this; var name = this.name; var register = function () { var node = this$1.owner.node; this$1.owner.on( name, (this$1.handler = function (event) { return directive.fire({ node: node, original: event, event: event, name: name }); }) ); }; if (name !== 'load') { // schedule events so that they take place after twoway binding runloop.scheduleTask(register, true); } else { // unless its a load event register(); } }; DOMEvent__proto__.unbind = function unbind () {}; DOMEvent__proto__.unrender = function unrender () { if (this.handler) { this.owner.off(this.name, this.handler); } }; var CustomEvent = function CustomEvent(eventPlugin, owner, name, args) { this.eventPlugin = eventPlugin; this.owner = owner; this.name = name; this.handler = null; this.args = args; }; var CustomEvent__proto__ = CustomEvent.prototype; CustomEvent__proto__.bind = function bind () {}; CustomEvent__proto__.render = function render (directive) { var this$1 = this; runloop.scheduleTask(function () { var node = this$1.owner.node; this$1.handler = this$1.eventPlugin.apply( this$1.owner.ractive, [ node, function (event) { if ( event === void 0 ) event = {}; if (event.original) { event.event = event.original; } else { event.original = event.event; } event.name = this$1.name; event.node = event.node || node; return directive.fire(event); } ].concat(this$1.args || []) ); }); }; CustomEvent__proto__.unbind = function unbind () {}; CustomEvent__proto__.unrender = function unrender () { this.handler.teardown(); }; var RactiveEvent = function RactiveEvent(component, name) { this.component = component; this.name = name; this.handler = null; }; var RactiveEvent__proto__ = RactiveEvent.prototype; RactiveEvent__proto__.bind = function bind (directive) { var ractive = this.component.instance; this.handler = ractive.on(this.name, function () { var args = [], len = arguments.length; while ( len-- ) args[ len ] = arguments[ len ]; // watch for reproxy if (args[0] instanceof Context) { var ctx = args.shift(); ctx.component = ractive; directive.fire(ctx, args); } else { directive.fire({}, args); } // cancel bubbling return false; }); }; RactiveEvent__proto__.render = function render () {}; RactiveEvent__proto__.unbind = function unbind () { this.handler.cancel(); }; RactiveEvent__proto__.unrender = function unrender () {}; var specialPattern = /^(event|arguments|@node|@event|@context)(\..+)?$/; var dollarArgsPattern = /^\$(\d+)(\..+)?$/; var EventDirective = function EventDirective(options) { this.owner = options.owner || options.up.owner || findElement(options.up); this.element = this.owner.attributeByName ? this.owner : findElement(options.up, true); this.template = options.template; this.up = options.up; this.ractive = options.up.ractive; this.events = []; }; var EventDirective__proto__ = EventDirective.prototype; EventDirective__proto__.bind = function bind () { var this$1 = this; // sometimes anchors will cause an unbind without unrender if (this.events.length) { this.events.forEach(function (e) { return e.unrender(); }); this.events = []; } if (this.element.type === COMPONENT || this.element.type === ANCHOR) { this.template.n.forEach(function (n) { this$1.events.push(new RactiveEvent(this$1.element, n)); }); } else { var args; if ((args = this.template.a)) { var rs = args.r.map(function (r) { var model = resolveReference(this$1.up, r); return model ? model.get() : undefined; }); try { args = getFunction(args.s, rs.length).apply(null, rs); } catch (err) { args = null; warnIfDebug( ("Failed to compute args for event on-" + (this.template.n.join('- ')) + ": " + (err.message || err)) ); } } this.template.n.forEach(function (n) { var fn = findInViewHierarchy('events', this$1.ractive, n); if (fn) { this$1.events.push(new CustomEvent(fn, this$1.element, n, args)); } else { this$1.events.push(new DOMEvent(n, this$1.element)); } }); } // method calls this.models = null; addToArray(this.element.events || (this.element.events = []), this); setupArgsFn(this, this.template); if (!this.fn) { this.action = this.template.f; } this.events.forEach(function (e) { return e.bind(this$1); }); }; EventDirective__proto__.destroyed = function destroyed () { this.events.forEach(function (e) { return e.unrender(); }); }; EventDirective__proto__.fire = function fire (event, args) { var this$1 = this; if ( args === void 0 ) args = []; var context = event instanceof Context && event.refire ? event : this.element.getContext(event); if (this.fn) { var values = []; var models = resolveArgs(this, this.template, this.up, { specialRef: function specialRef(ref) { var specialMatch = specialPattern.exec(ref); if (specialMatch) { // on-click="foo(event.node)" return { special: specialMatch[1], keys: specialMatch[2] ? splitKeypath(specialMatch[2].substr(1)) : [] }; } var dollarMatch = dollarArgsPattern.exec(ref); if (dollarMatch) { // on-click="foo($1)" return { special: 'arguments', keys: [dollarMatch[1] - 1].concat( dollarMatch[2] ? splitKeypath(dollarMatch[2].substr(1)) : [] ) }; } } }); if (models) { models.forEach(function (model) { if (!model) { return values.push(undefined); } if (model.special) { var which = model.special; var obj; if (which === '@node') { obj = this$1.element.node; } else if (which === '@event') { obj = event && event.event; } else if (which === 'event') { warnOnceIfDebug( "The event reference available to event directives is deprecated and should be replaced with @context and @event" ); obj = context; } else if (which === '@context') { obj = context; } else { obj = args; } var keys = model.keys.slice(); while (obj && keys.length) { obj = obj[keys.shift()]; } return values.push(obj); } if (model.wrapper) { return values.push(model.wrapperValue); } values.push(model.get()); }); } // make event available as `this.event` var ractive = this.ractive; var oldEvent = ractive.event; ractive.event = context; var returned = this.fn.apply(ractive, values); var result = returned.pop(); // Auto prevent and stop if return is explicitly false if (result === false) { var original = event ? event.original : undefined; if (original) { original.preventDefault && original.preventDefault(); original.stopPropagation && original.stopPropagation(); } else { warnOnceIfDebug( ("handler '" + (this.template.n.join( ' ' )) + "' returned false, but there is no event available to cancel") ); } } else if (!returned.length && isArray(result) && isString(result[0])) { // watch for proxy events result = fireEvent(this.ractive, result.shift(), context, result); } ractive.event = oldEvent; return result; } else { return fireEvent(this.ractive, this.action, context, args); } }; EventDirective__proto__.handleChange = function handleChange () {}; EventDirective__proto__.render = function render () { var this$1 = this; this.events.forEach(function (e) { return e.render(this$1); }); }; EventDirective__proto__.toString = function toString () { return ''; }; EventDirective__proto__.unbind = function unbind (view) { removeFromArray(this.element.events, this); this.events.forEach(function (e) { return e.unbind(view); }); }; EventDirective__proto__.unrender = function unrender () { this.events.forEach(function (e) { return e.unrender(); }); }; var proto$3 = EventDirective.prototype; proto$3.firstNode = proto$3.rebound = proto$3.update = noop; function progressiveText(item, target, occupants, text) { if (occupants) { var n = occupants[0]; if (n && n.nodeType === 3) { var idx = n.nodeValue.indexOf(text); occupants.shift(); if (idx === 0) { if (n.nodeValue.length !== text.length) { occupants.unshift(n.splitText(text.length)); } } else { n.nodeValue = text; } } else { n = item.node = doc.createTextNode(text); if (occupants[0]) { target.insertBefore(n, occupants[0]); } else { target.appendChild(n); } } item.node = n; } else { if (!item.node) { item.node = doc.createTextNode(text); } target.appendChild(item.node); } } var ComputationChild = (function (Model) { function ComputationChild(parent, key) { Model.call(this, parent, key); this.isReadonly = !this.root.ractive.syncComputedChildren; this.dirty = true; this.isComputed = true; } if ( Model ) ComputationChild.__proto__ = Model; var ComputationChild__proto__ = ComputationChild.prototype = Object.create( Model && Model.prototype ); ComputationChild__proto__.constructor = ComputationChild; var prototypeAccessors$1 = { setRoot: {} }; prototypeAccessors$1.setRoot.get = function () { return this.parent.setRoot; }; ComputationChild__proto__.applyValue = function applyValue (value) { Model.prototype.applyValue.call(this, value); if (!this.isReadonly) { var source = this.parent; // computed models don't have a shuffle method while (source && source.shuffle) { source = source.parent; } if (source) { source.dependencies.forEach(mark); } } if (this.setRoot) { this.setRoot.set(this.setRoot.value); } }; ComputationChild__proto__.get = function get (shouldCapture, opts) { if (shouldCapture) { capture(this); } if (this.dirty) { this.dirty = false; var parentValue = this.parent.get(); this.value = parentValue ? parentValue[this.key] : undefined; if (this.wrapper) { this.newWrapperValue = this.value; } this.adapt(); } return (opts && 'unwrap' in opts ? opts.unwrap !== false : shouldCapture) && this.wrapper ? this.wrapperValue : this.value; }; ComputationChild__proto__.handleChange = function handleChange$2 () { if (this.dirty) { return; } this.dirty = true; if (this.boundValue) { this.boundValue = null; } this.links.forEach(marked); this.deps.forEach(handleChange); this.children.forEach(handleChange); }; ComputationChild__proto__.joinKey = function joinKey (key) { if (isUndefined(key) || key === '') { return this; } if (!hasOwn(this.childByKey, key)) { var child = new ComputationChild(this, key); this.children.push(child); this.childByKey[key] = child; } return this.childByKey[key]; }; Object.defineProperties( ComputationChild__proto__, prototypeAccessors$1 ); return ComputationChild; }(Model)); /* global console */ /* eslint no-console:"off" */ var Computation = (function (Model) { function Computation(parent, signature, key) { Model.call(this, parent, key); this.signature = signature; this.isReadonly = !this.signature.setter; this.isComputed = true; this.dependencies = []; this.children = []; this.childByKey = {}; this.deps = []; this.dirty = true; // TODO: is there a less hackish way to do this? this.shuffle = undefined; } if ( Model ) Computation.__proto__ = Model; var Computation__proto__ = Computation.prototype = Object.create( Model && Model.prototype ); Computation__proto__.constructor = Computation; var prototypeAccessors$2 = { setRoot: {} }; prototypeAccessors$2.setRoot.get = function () { if (this.signature.setter) { return this; } }; Computation__proto__.get = function get (shouldCapture, opts) { if (shouldCapture) { capture(this); } if (this.dirty) { this.dirty = false; var old = this.value; this.value = this.getValue(); // this may cause a view somewhere to update, so it must be in a runloop if (!runloop.active()) { runloop.start(); if (!isEqual(old, this.value)) { this.notifyUpstream(); } runloop.end(); } else { if (!isEqual(old, this.value)) { this.notifyUpstream(); } } if (this.wrapper) { this.newWrapperValue = this.value; } this.adapt(); } // if capturing, this value needs to be unwrapped because it's for external use return maybeBind( this, // if unwrap is supplied, it overrides capture this.wrapper && (opts && 'unwrap' in opts ? opts.unwrap !== false : shouldCapture) ? this.wrapperValue : this.value, !opts || opts.shouldBind !== false ); }; Computation__proto__.getContext = function getContext () { return this.parent.isRoot ? this.root.ractive : this.parent.get(false, noVirtual); }; Computation__proto__.getValue = function getValue () { startCapturing(); var result; try { result = this.signature.getter.call(this.root.ractive, this.getContext()); } catch (err) { warnIfDebug(("Failed to compute " + (this.getKeypath()) + ": " + (err.message || err))); // TODO this is all well and good in Chrome, but... // ...also, should encapsulate this stuff better, and only // show it if Ractive.DEBUG if (hasConsole) { if (console.groupCollapsed) { console.groupCollapsed( '%cshow details', 'color: rgb(82, 140, 224); font-weight: normal; text-decoration: underline;' ); } var sig = this.signature; console.error( ((err.name) + ": " + (err.message) + "\n\n" + (sig.getterString) + (sig.getterUseStack ? '\n\n' + err.stack : '')) ); if (console.groupCollapsed) { console.groupEnd(); } } } var dependencies = stopCapturing(); this.setDependencies(dependencies); return result; }; Computation__proto__.mark = function mark () { this.handleChange(); }; Computation__proto__.rebind = function rebind (next, previous) { // computations will grab all of their deps again automagically if (next !== previous) { this.handleChange(); } }; Computation__proto__.set = function set (value) { if (this.isReadonly) { throw new Error(("Cannot set read-only computed value '" + (this.key) + "'")); } this.signature.setter(value); this.mark(); }; Computation__proto__.setDependencies = function setDependencies (dependencies) { var this$1 = this; // unregister any soft dependencies we no longer have var i = this.dependencies.length; while (i--) { var model = this$1.dependencies[i]; if (!~dependencies.indexOf(model)) { model.unregister(this$1); } } // and add any new ones i = dependencies.length; while (i--) { var model$1 = dependencies[i]; if (!~this$1.dependencies.indexOf(model$1)) { model$1.register(this$1); } } this.dependencies = dependencies; }; Computation__proto__.teardown = function teardown () { var this$1 = this; var i = this.dependencies.length; while (i--) { if (this$1.dependencies[i]) { this$1.dependencies[i].unregister(this$1); } } if (this.parent.computed[this.key] === this) { delete this.parent.computed[this.key]; } Model.prototype.teardown.call(this); }; Object.defineProperties( Computation__proto__, prototypeAccessors$2 ); return Computation; }(Model)); var prototype = Computation.prototype; var child = ComputationChild.prototype; prototype.handleChange = child.handleChange; prototype.joinKey = child.joinKey; shared$1.Computation = Computation; var ExpressionProxy = (function (Model) { function ExpressionProxy(fragment, template) { var this$1 = this; Model.call(this, fragment.ractive.viewmodel, null); this.fragment = fragment; this.template = template; this.isReadonly = true; this.isComputed = true; this.dirty = true; this.fn = fragment.ractive.allowExpressions === false ? noop : getFunction(template.s, template.r.length); this.models = this.template.r.map(function (ref) { return resolveReference(this$1.fragment, ref); }); this.dependencies = []; this.shuffle = undefined; this.bubble(); } if ( Model ) ExpressionProxy.__proto__ = Model; var ExpressionProxy__proto__ = ExpressionProxy.prototype = Object.create( Model && Model.prototype ); ExpressionProxy__proto__.constructor = ExpressionProxy; ExpressionProxy__proto__.bubble = function bubble (actuallyChanged) { if ( actuallyChanged === void 0 ) actuallyChanged = true; // refresh the keypath this.keypath = undefined; if (actuallyChanged) { this.handleChange(); } }; ExpressionProxy__proto__.getKeypath = function getKeypath () { var this$1 = this; if (!this.template) { return '@undefined'; } if (!this.keypath) { this.keypath = '@' + this.template.s.replace(/_(\d+)/g, function (match, i) { if (i >= this$1.models.length) { return match; } var model = this$1.models[i]; return model ? model.getKeypath() : '@undefined'; }); } return this.keypath; }; ExpressionProxy__proto__.getValue = function getValue () { var this$1 = this; startCapturing(); var result; try { var params = this.models.map(function (m) { return (m ? m.get(true) : undefined); }); result = this.fn.apply(this.fragment.ractive, params); } catch (err) { warnIfDebug(("Failed to compute " + (this.getKeypath()) + ": " + (err.message || err))); } var dependencies = stopCapturing(); // remove missing deps this.dependencies .filter(function (d) { return !~dependencies.indexOf(d); }) .forEach(function (d) { d.unregister(this$1); removeFromArray(this$1.dependencies, d); }); // register new deps dependencies .filter(function (d) { return !~this$1.dependencies.indexOf(d); }) .forEach(function (d) { d.register(this$1); this$1.dependencies.push(d); }); return result; }; ExpressionProxy__proto__.notifyUpstream = function notifyUpstream () {}; ExpressionProxy__proto__.rebind = function rebind (next, previous, safe) { var idx = this.models.indexOf(previous); if (~idx) { next = rebindMatch(this.template.r[idx], next, previous); if (next !== previous) { previous.unregister(this); this.models.splice(idx, 1, next); if (next) { next.addShuffleRegister(this, 'mark'); } } } this.bubble(!safe); }; ExpressionProxy__proto__.rebound = function rebound (update) { var this$1 = this; this.models = this.template.r.map(function (ref) { return resolveReference(this$1.fragment, ref); }); if (update) { this.bubble(true); } }; ExpressionProxy__proto__.retrieve = function retrieve () { return this.get(); }; ExpressionProxy__proto__.teardown = function teardown () { var this$1 = this; this.fragment = undefined; if (this.dependencies) { this.dependencies.forEach(function (d) { return d.unregister(this$1); }); } Model.prototype.teardown.call(this); }; ExpressionProxy__proto__.unreference = function unreference () { Model.prototype.unreference.call(this); collect(this); }; ExpressionProxy__proto__.unregister = function unregister (dep) { Model.prototype.unregister.call(this, dep); collect(this); }; ExpressionProxy__proto__.unregisterLink = function unregisterLink (link) { Model.prototype.unregisterLink.call(this, link); collect(this); }; return ExpressionProxy; }(Model)); var prototype$1 = ExpressionProxy.prototype; var computation = Computation.prototype; prototype$1.get = computation.get; prototype$1.handleChange = computation.handleChange; prototype$1.joinKey = computation.joinKey; prototype$1.mark = computation.mark; prototype$1.unbind = noop; function collect(model) { if (!model.deps.length && !model.refs && !model.links.length) { model.teardown(); } } var ReferenceExpressionProxy = (function (LinkModel) { function ReferenceExpressionProxy(fragment, template) { LinkModel.call(this, null, null, null, '@undefined'); this.root = fragment.ractive.viewmodel; this.template = template; this.rootLink = true; this.template = template; this.fragment = fragment; this.rebound(); } if ( LinkModel ) ReferenceExpressionProxy.__proto__ = LinkModel; var ReferenceExpressionProxy__proto__ = ReferenceExpressionProxy.prototype = Object.create( LinkModel && LinkModel.prototype ); ReferenceExpressionProxy__proto__.constructor = ReferenceExpressionProxy; ReferenceExpressionProxy__proto__.getKeypath = function getKeypath () { return this.model ? this.model.getKeypath() : '@undefined'; }; ReferenceExpressionProxy__proto__.rebound = function rebound () { var this$1 = this; var fragment = this.fragment; var template = this.template; var base = (this.base = resolve(fragment, template)); var idx; if (this.proxy) { teardown$2(this); } var proxy = (this.proxy = { rebind: function (next, previous) { if (previous === base) { next = rebindMatch(template, next, previous); if (next !== base) { this$1.base = base = next; } } else if (~(idx = members.indexOf(previous))) { next = rebindMatch(template.m[idx].n, next, previous); if (next !== members[idx]) { members.splice(idx, 1, next || Missing); } } if (next !== previous) { previous.unregister(proxy); if (next) { next.addShuffleTask(function () { return next.register(proxy); }); } } }, handleChange: function () { pathChanged(); } }); base.register(proxy); var members = (this.members = template.m.map(function (tpl) { if (isString(tpl)) { return { get: function () { return tpl; } }; } var model; if (tpl.t === REFERENCE) { model = resolveReference(fragment, tpl.n); model.register(proxy); return model; } model = new ExpressionProxy(fragment, tpl); model.register(proxy); return model; })); var pathChanged = function () { var model = base.joinAll( members.reduce(function (list, m) { var k = m.get(); if (isArray(k)) { return list.concat(k); } else { list.push(escapeKey(String(k))); } return list; }, []) ); if (model !== this$1.model) { this$1.model = model; this$1.relinking(model); fireShuffleTasks(); refreshPathDeps(this$1); } }; pathChanged(); }; ReferenceExpressionProxy__proto__.teardown = function teardown () { teardown$2(this); LinkModel.prototype.teardown.call(this); }; ReferenceExpressionProxy__proto__.unreference = function unreference () { LinkModel.prototype.unreference.call(this); if (!this.deps.length && !this.refs) { this.teardown(); } }; ReferenceExpressionProxy__proto__.unregister = function unregister (dep) { LinkModel.prototype.unregister.call(this, dep); if (!this.deps.length && !this.refs) { this.teardown(); } }; return ReferenceExpressionProxy; }(LinkModel)); function teardown$2(proxy) { if (proxy.base) { proxy.base.unregister(proxy.proxy); } if (proxy.models) { proxy.models.forEach(function (m) { if (m.unregister) { m.unregister(proxy); } }); } } function refreshPathDeps(proxy) { var len = proxy.deps.length; var i, v; for (i = 0; i < len; i++) { v = proxy.deps[i]; if (v.pathChanged) { v.pathChanged(); } if (v.fragment && v.fragment.pathModel) { v.fragment.pathModel.applyValue(proxy.getKeypath()); } } len = proxy.children.length; for (i = 0; i < len; i++) { refreshPathDeps(proxy.children[i]); } } var eproto = ExpressionProxy.prototype; var proto$4 = ReferenceExpressionProxy.prototype; proto$4.unreference = eproto.unreference; proto$4.unregister = eproto.unregister; proto$4.unregisterLink = eproto.unregisterLink; function resolve(fragment, template) { if (template.r) { return resolveReference(fragment, template.r); } else if (template.x) { return new ExpressionProxy(fragment, template.x); } else if (template.rx) { return new ReferenceExpressionProxy(fragment, template.rx); } } var Mustache = (function (Item) { function Mustache(options) { Item.call(this, options); if (options.owner) { this.parent = options.owner; } this.isStatic = !!options.template.s; this.model = null; this.dirty = false; } if ( Item ) Mustache.__proto__ = Item; var Mustache__proto__ = Mustache.prototype = Object.create( Item && Item.prototype ); Mustache__proto__.constructor = Mustache; Mustache__proto__.bind = function bind (pre) { // yield mustaches and inner contexts should resolve in container context var start = this.template.y ? this.template.y.containerFragment : this.containerFragment || this.up; // try to find a model for this view var model = pre || resolve(start, this.template); if (model) { var value = model.get(); if (this.isStatic) { this.model = { get: function () { return value; } }; model.unreference(); return; } model.register(this); this.model = model; } }; Mustache__proto__.handleChange = function handleChange () { this.bubble(); }; Mustache__proto__.rebind = function rebind (next, previous, safe) { if (this.isStatic) { return; } next = rebindMatch(this.template, next, previous, this.up); if (next === this.model) { return false; } if (this.model) { this.model.unregister(this); } if (next) { next.addShuffleRegister(this, 'mark'); } this.model = next; if (!safe) { this.handleChange(); } return true; }; Mustache__proto__.rebound = function rebound (update) { if (this.model) { if (this.model.rebound) { this.model.rebound(update); } else { // check to see if the model actually changed... // yield mustaches and inner contexts should resolve in container context var start = this.template.y ? this.template.y.containerFragment : this.containerFragment || this.up; // try to find a model for this view var model = resolve(start, this.template); if (model !== this.model) { this.model.unregister(this); this.bind(model); } } if (update) { this.bubble(); } } if (this.fragment) { this.fragment.rebound(update); } }; Mustache__proto__.unbind = function unbind () { if (!this.isStatic) { this.model && this.model.unregister(this); this.model = undefined; } }; return Mustache; }(Item)); function MustacheContainer(options) { Mustache.call(this, options); } var proto$5 = (MustacheContainer.prototype = Object.create(ContainerItem.prototype)); assign(proto$5, Mustache.prototype, { constructor: MustacheContainer }); var Interpolator = (function (Mustache) { function Interpolator () { Mustache.apply(this, arguments); } if ( Mustache ) Interpolator.__proto__ = Mustache; var Interpolator__proto__ = Interpolator.prototype = Object.create( Mustache && Mustache.prototype ); Interpolator__proto__.constructor = Interpolator; Interpolator__proto__.bubble = function bubble () { if (this.owner) { this.owner.bubble(); } Mustache.prototype.bubble.call(this); }; Interpolator__proto__.detach = function detach () { return detachNode(this.node); }; Interpolator__proto__.firstNode = function firstNode () { return this.node; }; Interpolator__proto__.getString = function getString () { return this.model ? safeToStringValue(this.model.get()) : ''; }; Interpolator__proto__.render = function render (target, occupants) { if (inAttributes()) { return; } var value = (this.value = this.getString()); this.rendered = true; progressiveText(this, target, occupants, value); }; Interpolator__proto__.toString = function toString (escape) { var string = this.getString(); return escape ? escapeHtml(string) : string; }; Interpolator__proto__.unrender = function unrender (shouldDestroy) { if (shouldDestroy) { this.detach(); } this.rendered = false; }; Interpolator__proto__.update = function update () { if (this.dirty) { this.dirty = false; if (this.rendered) { var value = this.getString(); if (value !== this.value) { this.node.data = this.value = value; } } } }; Interpolator__proto__.valueOf = function valueOf () { return this.model ? this.model.get() : undefined; }; return Interpolator; }(Mustache)); var Input = (function (Element) { function Input () { Element.apply(this, arguments); } if ( Element ) Input.__proto__ = Element; var Input__proto__ = Input.prototype = Object.create( Element && Element.prototype ); Input__proto__.constructor = Input; Input__proto__.render = function render (target, occupants) { Element.prototype.render.call(this, target, occupants); this.node.defaultValue = this.node.value; }; Input__proto__.compare = function compare (value, attrValue) { var comparator = this.getAttribute('value-comparator'); if (comparator) { if (isFunction(comparator)) { return comparator(value, attrValue); } if (value && attrValue) { return value[comparator] == attrValue[comparator]; } } return value == attrValue; }; return Input; }(Element)); // simple JSON parser, without the restrictions of JSON parse // (i.e. having to double-quote keys). // // If passed a hash of values as the second argument, ${placeholders} // will be replaced with those values var specials$1 = { true: true, false: false, null: null, undefined: undefined }; var specialsPattern = new RegExp('^(?:' + keys(specials$1).join('|') + ')'); var numberPattern$1 = /^(?:[+-]?)(?:(?:(?:0|[1-9]\d*)?\.\d+)|(?:(?:0|[1-9]\d*)\.)|(?:0|[1-9]\d*))(?:[eE][+-]?\d+)?/; var placeholderPattern = /\$\{([^\}]+)\}/g; var placeholderAtStartPattern = /^\$\{([^\}]+)\}/; var onlyWhitespace$1 = /^\s*$/; var JsonParser = Parser.extend({ init: function init(str, options) { this.values = options.values; this.sp(); }, postProcess: function postProcess(result) { if (result.length !== 1 || !onlyWhitespace$1.test(this.leftover)) { return null; } return { value: result[0].v }; }, converters: [ function getPlaceholder(parser) { if (!parser.values) { return null; } var placeholder = parser.matchPattern(placeholderAtStartPattern); if (placeholder && hasOwn(parser.values, placeholder)) { return { v: parser.values[placeholder] }; } }, function getSpecial(parser) { var special = parser.matchPattern(specialsPattern); if (special) { return { v: specials$1[special] }; } }, function getNumber(parser) { var number = parser.matchPattern(numberPattern$1); if (number) { return { v: +number }; } }, function getString(parser) { var stringLiteral = readStringLiteral(parser); var values = parser.values; if (stringLiteral && values) { return { v: stringLiteral.v.replace(placeholderPattern, function (match, $1) { return $1 in values ? values[$1] : $1; } ) }; } return stringLiteral; }, function getObject(parser) { if (!parser.matchString('{')) { return null; } var result = {}; parser.sp(); if (parser.matchString('}')) { return { v: result }; } var pair; while ((pair = getKeyValuePair(parser))) { result[pair.key] = pair.value; parser.sp(); if (parser.matchString('}')) { return { v: result }; } if (!parser.matchString(',')) { return null; } } return null; }, function getArray(parser) { if (!parser.matchString('[')) { return null; } var result = []; parser.sp(); if (parser.matchString(']')) { return { v: result }; } var valueToken; while ((valueToken = parser.read())) { result.push(valueToken.v); parser.sp(); if (parser.matchString(']')) { return { v: result }; } if (!parser.matchString(',')) { return null; } parser.sp(); } return null; } ] }); function getKeyValuePair(parser) { parser.sp(); var key = readKey(parser); if (!key) { return null; } var pair = { key: key }; parser.sp(); if (!parser.matchString(':')) { return null; } parser.sp(); var valueToken = parser.read(); if (!valueToken) { return null; } pair.value = valueToken.v; return pair; } function parseJSON(str, values) { var parser = new JsonParser(str, { values: values }); return parser.result; } var Mapping = (function (Item) { function Mapping(options) { Item.call(this, options); this.name = options.template.n; this.owner = options.owner || options.up.owner || options.element || findElement(options.up); this.element = options.element || (this.owner.attributeByName ? this.owner : findElement(options.up)); this.up = this.element.up; // shared this.ractive = this.up.ractive; this.element.attributeByName[this.name] = this; this.value = options.template.f; } if ( Item ) Mapping.__proto__ = Item; var Mapping__proto__ = Mapping.prototype = Object.create( Item && Item.prototype ); Mapping__proto__.constructor = Mapping; Mapping__proto__.bind = function bind () { var template = this.template.f; var viewmodel = this.element.instance.viewmodel; if (template === 0) { // empty attributes are `true` viewmodel.joinKey(this.name).set(true); } else if (isString(template)) { var parsed = parseJSON(template); viewmodel.joinKey(this.name).set(parsed ? parsed.value : template); } else if (isArray(template)) { createMapping(this, true); } }; Mapping__proto__.rebound = function rebound (update) { if (this.boundFragment) { this.boundFragment.rebound(update); } if (this.link) { this.model = resolve(this.up, this.template.f[0]); var model = this.element.instance.viewmodel.joinAll(splitKeypath(this.name)); model.link(this.model, this.name, { mapping: true }); } }; Mapping__proto__.render = function render () {}; Mapping__proto__.unbind = function unbind (view) { if (this.model) { this.model.unregister(this); } if (this.boundFragment) { this.boundFragment.unbind(view); } if (this.element.bound) { if (this.link.target === this.model) { this.link.owner.unlink(); } } }; Mapping__proto__.unrender = function unrender () {}; Mapping__proto__.update = function update () { if (this.dirty) { this.dirty = false; if (this.boundFragment) { this.boundFragment.update(); } } }; return Mapping; }(Item)); function createMapping(item) { var template = item.template.f; var viewmodel = item.element.instance.viewmodel; var childData = viewmodel.value; if (template.length === 1 && template[0].t === INTERPOLATOR) { var model = resolve(item.up, template[0]); var val = model.get(false); // if the interpolator is not static if (!template[0].s) { item.model = model; item.link = viewmodel.createLink(item.name, model, template[0].r, { mapping: true }); // initialize parent side of the mapping from child data if (isUndefined(val) && !model.isReadonly && item.name in childData) { model.set(childData[item.name]); } } else if (!isObjectType(val) || template[0].x) { // copy non-object, non-computed vals through viewmodel.joinKey(splitKeypath(item.name)).set(val); } else { // warn about trying to copy an object warnIfDebug(("Cannot copy non-computed object value from static mapping '" + (item.name) + "'")); } // if the item isn't going to manage the model, give it a change to tear down if it's computed if (model !== item.model) { model.unregister(); } } else { item.boundFragment = new Fragment({ owner: item, template: template }).bind(); item.model = viewmodel.joinKey(splitKeypath(item.name)); item.model.set(item.boundFragment.valueOf()); // item is a *bit* of a hack item.boundFragment.bubble = function () { Fragment.prototype.bubble.call(item.boundFragment); // defer this to avoid mucking around model deps if there happens to be an expression involved runloop.scheduleTask(function () { item.boundFragment.update(); item.model.set(item.boundFragment.valueOf()); }); }; } } var Option = (function (Element) { function Option(options) { var template = options.template; if (!template.a) { template.a = {}; } // If the value attribute is missing, use the element's content, // as long as it isn't disabled if (isUndefined(template.a.value) && !('disabled' in template.a)) { template.a.value = template.f || ''; } Element.call(this, options); this.select = findElement(this.parent || this.up, false, 'select'); } if ( Element ) Option.__proto__ = Element; var Option__proto__ = Option.prototype = Object.create( Element && Element.prototype ); Option__proto__.constructor = Option; Option__proto__.bind = function bind () { if (!this.select) { Element.prototype.bind.call(this); return; } // If the select has a value, it overrides the `selected` attribute on // this option - so we delete the attribute var selectedAttribute = this.attributeByName.selected; if (selectedAttribute && this.select.getAttribute('value') !== undefined) { var index = this.attributes.indexOf(selectedAttribute); this.attributes.splice(index, 1); delete this.attributeByName.selected; } Element.prototype.bind.call(this); this.select.options.push(this); }; Option__proto__.bubble = function bubble () { // if we're using content as value, may need to update here var value = this.getAttribute('value'); if (this.node && this.node.value !== value) { this.node._ractive.value = value; } Element.prototype.bubble.call(this); }; Option__proto__.getAttribute = function getAttribute (name) { var attribute = this.attributeByName[name]; return attribute ? attribute.getValue() : name === 'value' && this.fragment ? this.fragment.valueOf() : undefined; }; Option__proto__.isSelected = function isSelected () { var this$1 = this; var optionValue = this.getAttribute('value'); if (isUndefined(optionValue) || !this.select) { return false; } var selectValue = this.select.getAttribute('value'); if (this.select.compare(selectValue, optionValue)) { return true; } if (this.select.getAttribute('multiple') && isArray(selectValue)) { var i = selectValue.length; while (i--) { if (this$1.select.compare(selectValue[i], optionValue)) { return true; } } } }; Option__proto__.render = function render (target, occupants) { Element.prototype.render.call(this, target, occupants); if (!this.attributeByName.value) { this.node._ractive.value = this.getAttribute('value'); } }; Option__proto__.unbind = function unbind (view) { Element.prototype.unbind.call(this, view); if (this.select) { removeFromArray(this.select.options, this); } }; return Option; }(Element)); function getPartialTemplate(ractive, name, up) { // If the partial in instance or view heirarchy instances, great var partial = getPartialFromRegistry(ractive, name, up || {}); if (partial) { return partial; } // Does it exist on the page as a script tag? partial = parser.fromId(name, { noThrow: true }); if (partial) { // parse and register to this ractive instance var parsed = parser.parseFor(partial, ractive); // register extra partials on the ractive instance if they don't already exist if (parsed.p) { fillGaps(ractive.partials, parsed.p); } // register (and return main partial if there are others in the template) return (ractive.partials[name] = parsed.t); } } function getPartialFromRegistry(ractive, name, up) { // if there was an instance up-hierarchy, cool var partial = findParentPartial(name, up.owner); if (partial) { return partial; } // find first instance in the ractive or view hierarchy that has this partial var instance = findInstance('partials', ractive, name); if (!instance) { return; } partial = instance.partials[name]; // partial is a function? var fn; if (isFunction(partial)) { fn = partial; // super partial if (fn.styleSet) { return fn; } fn = partial.bind(instance); fn.isOwner = hasOwn(instance.partials, name); partial = fn.call(ractive, parser); } if (!partial && partial !== '') { warnIfDebug(noRegistryFunctionReturn, name, 'partial', 'partial', { ractive: ractive }); return; } // If this was added manually to the registry, // but hasn't been parsed, parse it now if (!parser.isParsed(partial)) { // use the parseOptions of the ractive instance on which it was found var parsed = parser.parseFor(partial, instance); // Partials cannot contain nested partials! // TODO add a test for this if (parsed.p) { warnIfDebug('Partials ({{>%s}}) cannot contain nested inline partials', name, { ractive: ractive }); } // if fn, use instance to store result, otherwise needs to go // in the correct point in prototype chain on instance or constructor var target = fn ? instance : findOwner(instance, name); // may be a template with partials, which need to be registered and main template extracted target.partials[name] = partial = parsed.t; } // store for reset if (fn) { partial._fn = fn; } return partial.v ? partial.t : partial; } function findOwner(ractive, key) { return hasOwn(ractive.partials, key) ? ractive : findConstructor(ractive.constructor, key); } function findConstructor(constructor, key) { if (!constructor) { return; } return hasOwn(constructor.partials, key) ? constructor : findConstructor(constructor.Parent, key); } function findParentPartial(name, parent) { if (parent) { if ( parent.template && parent.template.p && !isArray(parent.template.p) && hasOwn(parent.template.p, name) ) { return parent.template.p[name]; } else if (parent.up && parent.up.owner) { return findParentPartial(name, parent.up.owner); } } } function Partial(options) { MustacheContainer.call(this, options); var tpl = options.template; // yielder is a special form of partial that will later require special handling if (tpl.t === YIELDER) { this.yielder = 1; } else if (tpl.t === ELEMENT) { // this is a macro partial, complete with macro constructor // leaving this as an element will confuse up-template searches this.type = PARTIAL; this.macro = options.macro; } } var proto$6 = (Partial.prototype = create(MustacheContainer.prototype)); assign(proto$6, { constructor: Partial, bind: function bind() { var template = this.template; if (this.yielder) { // the container is the instance that owns this node this.container = this.up.ractive; this.component = this.container.component; this.containerFragment = this.up; // normal component if (this.component) { // yields skip the owning instance and go straight to the surrounding context this.up = this.component.up; // {{yield}} is equivalent to {{yield content}} if (!template.r && !template.x && !template.rx) { this.refName = 'content'; } } else { // plain-ish instance that may be attached to a parent later this.fragment = new Fragment({ owner: this, template: [] }); this.fragment.bind(); return; } } // this is a macro/super partial if (this.macro) { this.fn = this.macro; } else { // this is a plain partial or yielder if (!this.refName) { this.refName = template.r; } // if the refName exists as a partial, this is a plain old partial reference where no model binding will happen if (this.refName) { partialFromValue(this, this.refName); } // this is a dynamic/inline partial if (!this.partial && !this.fn) { MustacheContainer.prototype.bind.call(this); if (this.model) { partialFromValue(this, this.model.get()); } } } if (!this.partial && !this.fn) { warnOnceIfDebug(("Could not find template for partial '" + (this.name) + "'")); } createFragment(this, this.partial || []); // macro/super partial if (this.fn) { initMacro(this); } this.fragment.bind(); }, bubble: function bubble() { if (!this.dirty) { this.dirty = true; if (this.yielder) { this.containerFragment.bubble(); } else { this.up.bubble(); } } }, findNextNode: function findNextNode() { return (this.containerFragment || this.up).findNextNode(this); }, handleChange: function handleChange() { this.dirtyTemplate = true; this.externalChange = true; this.bubble(); }, rebound: function rebound(update) { var this$1 = this; if (this._attrs) { keys(this._attrs).forEach(function (k) { return this$1._attrs[k].rebound(update); }); } MustacheContainer.prototype.rebound.call(this, update); }, refreshAttrs: function refreshAttrs() { var this$1 = this; keys(this._attrs).forEach(function (k) { this$1.handle.attributes[k] = !this$1._attrs[k].items.length || this$1._attrs[k].valueOf(); }); }, resetTemplate: function resetTemplate() { var this$1 = this; if (this.fn && this.proxy) { if (this.externalChange) { if (isFunction(this.proxy.teardown)) { this.proxy.teardown(); } this.fn = this.proxy = null; } else { this.partial = this.fnTemplate; return true; } } var partial = this.partial; this.partial = null; if (this.refName) { this.partial = getPartialTemplate(this.ractive, this.refName, this.up); } if (!this.partial && this.model) { partialFromValue(this, this.model.get()); } if (!this.fn && partial === this.partial) { return false; } this.unbindAttrs(); if (this.fn) { initMacro(this); if (isFunction(this.proxy.render)) { runloop.scheduleTask(function () { return this$1.proxy.render(); }); } } else if (!this.partial) { warnOnceIfDebug(("Could not find template for partial '" + (this.name) + "'")); } return true; }, render: function render(target, occupants) { if (this.fn && this.fn._cssDef && !this.fn._cssDef.applied) { applyCSS(); } this.fragment.render(target, occupants); if (this.proxy && isFunction(this.proxy.render)) { this.proxy.render(); } }, unbind: function unbind(view) { this.fragment.unbind(view); this.unbindAttrs(view); MustacheContainer.prototype.unbind.call(this, view); }, unbindAttrs: function unbindAttrs(view) { var this$1 = this; if (this._attrs) { keys(this._attrs).forEach(function (k) { this$1._attrs[k].unbind(view); }); } }, unrender: function unrender(shouldDestroy) { if (this.proxy && isFunction(this.proxy.teardown)) { this.proxy.teardown(); } this.fragment.unrender(shouldDestroy); }, update: function update() { var this$1 = this; var proxy = this.proxy; this.updating = 1; if (this.dirtyAttrs) { this.dirtyAttrs = false; keys(this._attrs).forEach(function (k) { return this$1._attrs[k].update(); }); this.refreshAttrs(); if (isFunction(proxy.update)) { proxy.update(this.handle.attributes); } } if (this.dirtyTemplate) { this.dirtyTemplate = false; this.resetTemplate() && this.fragment.resetTemplate(this.partial || []); } if (this.dirty) { this.dirty = false; if (proxy && isFunction(proxy.invalidate)) { proxy.invalidate(); } this.fragment.update(); } this.externalChange = false; this.updating = 0; } }); function createFragment(self, partial) { self.partial = partial; contextifyTemplate(self); var options = { owner: self, template: self.partial }; if (self.yielder) { options.ractive = self.container.parent; } if (self.fn) { options.cssIds = self.fn._cssIds; } self.fragment = new Fragment(options); } function contextifyTemplate(self) { if (self.template.c) { self.partial = [{ t: SECTION, n: SECTION_WITH, f: self.partial, z: self.template.z }]; assign(self.partial[0], self.template.c); if (self.yielder) { self.partial[0].y = self; } } } function partialFromValue(self, value, okToParse) { var tpl = value; if (isArray(tpl)) { self.partial = tpl; } else if (tpl && isObjectType(tpl)) { if (isArray(tpl.t)) { self.partial = tpl.t; } else if (isString(tpl.template)) { self.partial = parsePartial(tpl.template, tpl.template, self.ractive).t; } } else if (isFunction(tpl) && tpl.styleSet) { self.fn = tpl; if (self.fragment) { self.fragment.cssIds = tpl._cssIds; } } else if (tpl != null) { tpl = getPartialTemplate(self.ractive, '' + tpl, self.containerFragment || self.up); if (tpl) { self.name = value; if (tpl.styleSet) { self.fn = tpl; if (self.fragment) { self.fragment.cssIds = tpl._cssIds; } } else { self.partial = tpl; } } else if (okToParse) { self.partial = parsePartial('' + value, '' + value, self.ractive).t; } else { self.name = value; } } return self.partial; } function setTemplate(template) { partialFromValue(this, template, true); if (!this.initing) { this.dirtyTemplate = true; this.fnTemplate = this.partial; if (this.updating) { this.bubble(); runloop.promise(); } else { var promise = runloop.start(); this.bubble(); runloop.end(); return promise; } } } function aliasLocal(ref, name) { var aliases = this.fragment.aliases || (this.fragment.aliases = {}); if (!name) { aliases[ref] = this._data; } else { aliases[name] = this._data.joinAll(splitKeypath(ref)); } } var extras = 'extra-attributes'; function initMacro(self) { var fn = self.fn; var fragment = self.fragment; // defensively copy the template in case it changes var template = (self.template = assign({}, self.template)); var handle = (self.handle = fragment.getContext({ proxy: self, aliasLocal: aliasLocal, name: self.template.e || self.name, attributes: {}, setTemplate: setTemplate.bind(self), template: template, macro: fn })); if (!template.p) { template.p = {}; } template.p = handle.partials = assign({}, template.p); if (!hasOwn(template.p, 'content')) { template.p.content = template.f || []; } if (isArray(fn.attributes)) { self._attrs = {}; var invalidate = function() { this.dirty = true; self.dirtyAttrs = true; self.bubble(); }; if (isArray(template.m)) { var attrs = template.m; template.p[extras] = template.m = attrs.filter(function (a) { return !~fn.attributes.indexOf(a.n); }); attrs .filter(function (a) { return ~fn.attributes.indexOf(a.n); }) .forEach(function (a) { var fragment = new Fragment({ template: a.f, owner: self }); fragment.bubble = invalidate; fragment.findFirstNode = noop; self._attrs[a.n] = fragment; }); } else { template.p[extras] = []; } } else { template.p[extras] = template.m; } if (self._attrs) { keys(self._attrs).forEach(function (k) { self._attrs[k].bind(); }); self.refreshAttrs(); } self.initing = 1; self.proxy = fn.call(self.ractive, handle, handle.attributes) || {}; if (!self.partial) { self.partial = []; } self.fnTemplate = self.partial; self.initing = 0; contextifyTemplate(self); fragment.resetTemplate(self.partial); } function parsePartial(name, partial, ractive) { var parsed; try { parsed = parser.parse(partial, parser.getParseOptions(ractive)); } catch (e) { warnIfDebug(("Could not parse partial from expression '" + name + "'\n" + (e.message))); } return parsed || { t: [] }; } var KeyModel = function KeyModel(value, context, instance) { this.value = this.key = value; this.context = context; this.isReadonly = this.isKey = true; this.deps = []; this.links = []; this.children = []; this.instance = instance; }; var KeyModel__proto__ = KeyModel.prototype; KeyModel__proto__.applyValue = function applyValue (value) { if (value !== this.value) { this.value = this.key = value; this.deps.forEach(handleChange); this.links.forEach(handleChange); this.children.forEach(function (c) { c.applyValue(c.context.getKeypath(c.instance)); }); } }; KeyModel__proto__.destroyed = function destroyed () { if (this.upstream) { this.upstream.unregisterChild(this); } }; KeyModel__proto__.get = function get (shouldCapture) { if (shouldCapture) { capture(this); } return unescapeKey(this.value); }; KeyModel__proto__.getKeypath = function getKeypath () { return unescapeKey(this.value); }; KeyModel__proto__.has = function has () { return false; }; KeyModel__proto__.rebind = function rebind (next, previous) { var this$1 = this; var i = this.deps.length; while (i--) { this$1.deps[i].rebind(next, previous, false); } i = this.links.length; while (i--) { this$1.links[i].relinking(next, false); } }; KeyModel__proto__.register = function register (dependant) { this.deps.push(dependant); }; KeyModel__proto__.registerChild = function registerChild (child) { addToArray(this.children, child); child.upstream = this; }; KeyModel__proto__.registerLink = function registerLink (link) { addToArray(this.links, link); }; KeyModel__proto__.unregister = function unregister (dependant) { removeFromArray(this.deps, dependant); }; KeyModel__proto__.unregisterChild = function unregisterChild (child) { removeFromArray(this.children, child); }; KeyModel__proto__.unregisterLink = function unregisterLink (link) { removeFromArray(this.links, link); }; KeyModel.prototype.reference = noop; KeyModel.prototype.unreference = noop; var keypathString = /^"(\\"|[^"])+"$/; var RepeatedFragment = function RepeatedFragment(options) { this.parent = options.owner.up; // bit of a hack, so reference resolution works without another // layer of indirection this.up = this; this.owner = options.owner; this.ractive = this.parent.ractive; this.delegate = this.ractive.delegate !== false && (this.parent.delegate || findDelegate(this.parent)); // delegation disabled by directive if (this.delegate && this.delegate.delegate === false) { this.delegate = false; } // let the element know it's a delegate handler if (this.delegate) { this.delegate.delegate = this.delegate; } // encapsulated styles should be inherited until they get applied by an element this.cssIds = 'cssIds' in options ? options.cssIds : this.parent ? this.parent.cssIds : null; this.context = null; this.rendered = false; this.iterations = []; this.template = options.template; this.indexRef = options.indexRef; this.keyRef = options.keyRef; this.pendingNewIndices = null; this.previousIterations = null; // track array versus object so updates of type rest this.isArray = false; }; var RepeatedFragment__proto__ = RepeatedFragment.prototype; RepeatedFragment__proto__.bind = function bind (context) { var this$1 = this; this.context = context; this.bound = true; var value = context.get(); var aliases = (this.aliases = this.owner.template.z && this.owner.template.z.slice()); var shuffler = aliases && aliases.find(function (a) { return a.n === 'shuffle'; }); if (shuffler && shuffler.x && shuffler.x.x) { if (shuffler.x.x.s === 'true') { this.shuffler = true; } else if (keypathString.test(shuffler.x.x.s)) { this.shuffler = splitKeypath(shuffler.x.x.s.slice(1, -1)); } } if (this.shuffler) { this.values = shuffleValues(this, this.shuffler); } if (this.source) { this.source.model.unbind(this.source); } var source = context.isComputed && aliases && aliases.find(function (a) { return a.n === 'source'; }); if (source && source.x && source.x.r) { var model = resolve(this, source.x); this.source = { handleChange: function handleChange() {}, rebind: function rebind(next) { this.model.unregister(this); this.model = next; next.register(this); } }; this.source.model = model; model.register(this.source); } // {{#each array}}... if ((this.isArray = isArray(value))) { // we can't use map, because of sparse arrays this.iterations = []; var max = (this.length = value.length); for (var i = 0; i < max; i += 1) { this$1.iterations[i] = this$1.createIteration(i, i); } } else if (isObject(value)) { // {{#each object}}... this.isArray = false; // TODO this is a dreadful hack. There must be a neater way if (this.indexRef) { var refs = this.indexRef.split(','); this.keyRef = refs[0]; this.indexRef = refs[1]; } var ks = keys(value); this.length = ks.length; this.iterations = ks.map(function (key, index) { return this$1.createIteration(key, index); }); } return this; }; RepeatedFragment__proto__.bubble = function bubble (index) { if (!this.bubbled) { this.bubbled = []; } this.bubbled.push(index); if (!this.rebounding) { this.owner.bubble(); } }; RepeatedFragment__proto__.createIteration = function createIteration (key, index) { var fragment = new Fragment({ owner: this, template: this.template }); fragment.isIteration = true; fragment.delegate = this.delegate; if (this.aliases) { fragment.aliases = {}; } swizzleFragment(this, fragment, key, index); return fragment.bind(fragment.context); }; RepeatedFragment__proto__.destroyed = function destroyed () { var this$1 = this; var len = this.iterations.length; for (var i = 0; i < len; i++) { this$1.iterations[i].destroyed(); } if (this.pathModel) { this.pathModel.destroyed(); } if (this.rootModel) { this.rootModel.destroyed(); } }; RepeatedFragment__proto__.detach = function detach () { var docFrag = createDocumentFragment(); this.iterations.forEach(function (fragment) { return docFrag.appendChild(fragment.detach()); }); return docFrag; }; RepeatedFragment__proto__.find = function find (selector, options) { return findMap(this.iterations, function (i) { return i.find(selector, options); }); }; RepeatedFragment__proto__.findAll = function findAll (selector, options) { return this.iterations.forEach(function (i) { return i.findAll(selector, options); }); }; RepeatedFragment__proto__.findAllComponents = function findAllComponents (name, options) { return this.iterations.forEach(function (i) { return i.findAllComponents(name, options); }); }; RepeatedFragment__proto__.findComponent = function findComponent (name, options) { return findMap(this.iterations, function (i) { return i.findComponent(name, options); }); }; RepeatedFragment__proto__.findContext = function findContext () { return this.context; }; RepeatedFragment__proto__.findNextNode = function findNextNode (iteration) { var this$1 = this; if (iteration.index < this.iterations.length - 1) { for (var i = iteration.index + 1; i < this.iterations.length; i++) { var node = this$1.iterations[i].firstNode(true); if (node) { return node; } } } return this.owner.findNextNode(); }; RepeatedFragment__proto__.firstNode = function firstNode (skipParent) { return this.iterations[0] ? this.iterations[0].firstNode(skipParent) : null; }; RepeatedFragment__proto__.getLast = function getLast () { return this.lastModel || (this.lastModel = new KeyModel(this.length - 1)); }; RepeatedFragment__proto__.rebind = function rebind (next) { var this$1 = this; this.context = next; if (this.source) { return; } this.iterations.forEach(function (fragment) { swizzleFragment(this$1, fragment, fragment.key, fragment.index); }); }; RepeatedFragment__proto__.rebound = function rebound (update$$1) { var this$1 = this; this.context = this.owner.model; this.iterations.forEach(function (f, i) { f.context = contextFor(this$1, f, i); f.rebound(update$$1); }); }; RepeatedFragment__proto__.render = function render (target, occupants) { var xs = this.iterations; if (xs) { var len = xs.length; for (var i = 0; i < len; i++) { xs[i].render(target, occupants); } } this.rendered = true; }; RepeatedFragment__proto__.shuffle = function shuffle (newIndices, merge) { var this$1 = this; if (!this.pendingNewIndices) { this.previousIterations = this.iterations.slice(); } if (!this.pendingNewIndices) { this.pendingNewIndices = []; } this.pendingNewIndices.push(newIndices); var iterations = []; newIndices.forEach(function (newIndex, oldIndex) { if (newIndex === -1) { return; } var fragment = this$1.iterations[oldIndex]; iterations[newIndex] = fragment; if (newIndex !== oldIndex && fragment) { fragment.dirty = true; if (merge) { fragment.shouldRebind = 1; } } }); this.iterations = iterations; // if merging, we're in the midst of an update already if (!merge) { this.bubble(); } }; RepeatedFragment__proto__.shuffled = function shuffled$1 () { this.iterations.forEach(shuffled); }; RepeatedFragment__proto__.toString = function toString (escape) { return this.iterations ? this.iterations.map(escape ? toEscapedString : toString$1).join('') : ''; }; RepeatedFragment__proto__.unbind = function unbind (view) { this.bound = false; if (this.source) { this.source.model.unregister(this.source); } var iterations = this.pendingNewIndices ? this.previousIterations : this.iterations; var len = iterations.length; for (var i = 0; i < len; i++) { iterations[i].unbind(view); } return this; }; RepeatedFragment__proto__.unrender = function unrender (shouldDestroy) { var this$1 = this; var len = this.iterations.length; for (var i = 0; i < len; i++) { this$1.iterations[i].unrender(shouldDestroy); } if (this.pendingNewIndices && this.previousIterations) { len = this.previousIterations.length; for (var i$1 = 0; i$1 < len; i$1++) { this$1.previousIterations[i$1].unrender(shouldDestroy); } } this.rendered = false; }; RepeatedFragment__proto__.update = function update$3 () { var this$1 = this; if (this.pendingNewIndices) { this.bubbled.length = 0; this.updatePostShuffle(); return; } if (this.updating) { return; } this.updating = true; if (this.shuffler) { var values = shuffleValues(this, this.shuffler); var newIndices = buildNewIndices(this.values, values); if (!newIndices.same) { this.shuffle(newIndices, true); this.updatePostShuffle(); } else { this.iterations.forEach(update); } } else { var len = this.iterations.length; for (var i = 0; i < len; i++) { var f = this$1.iterations[i]; f && f.idxModel && f.idxModel.applyValue(i); } var value = this.context.get(); var wasArray = this.isArray; var toRemove; var oldKeys; var reset = true; var i$1; if ((this.isArray = isArray(value))) { // if there's a source to map back to, make sure everything stays bound correctly if (this.source) { this.rebounding = 1; var source = this.source.model.get(); this.iterations.forEach(function (f, c) { if (c < value.length && f.lastValue !== value[c] && ~(i$1 = source.indexOf(value[c]))) { swizzleFragment(this$1, f, c, c); f.rebound(true); } }); this.rebounding = 0; } if (wasArray) { reset = false; if (this.iterations.length > value.length) { toRemove = this.iterations.splice(value.length); } } } else if (isObject(value) && !wasArray) { reset = false; toRemove = []; oldKeys = {}; i$1 = this.iterations.length; while (i$1--) { var fragment = this$1.iterations[i$1]; if (fragment.key in value) { oldKeys[fragment.key] = true; } else { this$1.iterations.splice(i$1, 1); toRemove.push(fragment); } } } var newLength = isArray(value) ? value.length : isObject(value) ? keys(value).length : 0; this.length = newLength; this.updateLast(); if (reset) { toRemove = this.iterations; this.iterations = []; } if (toRemove) { len = toRemove.length; for (var i$2 = 0; i$2 < len; i$2++) { toRemove[i$2].unbind().unrender(true); } } // update the remaining ones if (!reset && this.isArray && this.bubbled && this.bubbled.length) { var bubbled = this.bubbled; this.bubbled = []; len = bubbled.length; for (var i$3 = 0; i$3 < len; i$3++) { this$1.iterations[bubbled[i$3]] && this$1.iterations[bubbled[i$3]].update(); } } else { len = this.iterations.length; for (var i$4 = 0; i$4 < len; i$4++) { this$1.iterations[i$4].update(); } } // add new iterations var docFrag; var fragment$1; if (newLength > this.iterations.length) { docFrag = this.rendered ? createDocumentFragment() : null; i$1 = this.iterations.length; if (isArray(value)) { while (i$1 < value.length) { fragment$1 = this$1.createIteration(i$1, i$1); this$1.iterations.push(fragment$1); if (this$1.rendered) { fragment$1.render(docFrag); } i$1 += 1; } } else if (isObject(value)) { // TODO this is a dreadful hack. There must be a neater way if (this.indexRef && !this.keyRef) { var refs = this.indexRef.split(','); this.keyRef = refs[0]; this.indexRef = refs[1]; } keys(value).forEach(function (key) { if (!oldKeys || !(key in oldKeys)) { fragment$1 = this$1.createIteration(key, i$1); this$1.iterations.push(fragment$1); if (this$1.rendered) { fragment$1.render(docFrag); } i$1 += 1; } }); } if (this.rendered) { var parentNode = this.parent.findParentNode(); var anchor = this.parent.findNextNode(this.owner); parentNode.insertBefore(docFrag, anchor); } } } this.updating = false; }; RepeatedFragment__proto__.updateLast = function updateLast () { if (this.lastModel) { this.lastModel.applyValue(this.length - 1); } }; RepeatedFragment__proto__.updatePostShuffle = function updatePostShuffle () { var this$1 = this; var newIndices = this.pendingNewIndices[0]; var parentNode = this.rendered ? this.parent.findParentNode() : null; var nextNode = parentNode && this.owner.findNextNode(); var docFrag = parentNode ? createDocumentFragment() : null; // map first shuffle through this.pendingNewIndices.slice(1).forEach(function (indices) { newIndices.forEach(function (newIndex, oldIndex) { newIndices[oldIndex] = indices[newIndex]; }); }); var len = (this.length = this.context.get().length); var prev = this.previousIterations; var iters = this.iterations; var value = this.context.get(); var stash = {}; var idx, dest, pos, next, anchor, rebound; var map = new Array(newIndices.length); newIndices.forEach(function (e, i) { return (map[e] = i); }); this.updateLast(); idx = pos = 0; while (idx < len) { // if there's not an existing thing to shuffle, handle that if (isUndefined(map[idx])) { next = iters[idx] = this$1.createIteration(idx, idx); if (parentNode) { anchor = prev[pos]; anchor = (anchor && parentNode && anchor.firstNode()) || nextNode; next.render(docFrag); parentNode.insertBefore(docFrag, anchor); } idx++; } else { dest = newIndices[pos]; if (dest === -1) { // if it needs to be dropped, drop it prev[pos] && prev[pos].unbind().unrender(true); prev[pos++] = 0; } else if (dest > idx) { // if it needs to move down, stash it stash[dest] = prev[pos]; prev[pos++] = null; } else { // get the fragment that goes for this idx iters[idx] = next = iters[idx] || stash[idx] || this$1.createIteration(idx, idx); // if it's an existing fragment, swizzle if (stash[idx] || pos !== idx) { rebound = this$1.source && next.lastValue !== value[idx]; swizzleFragment(this$1, next, idx, idx); } // does next need to be moved? if (parentNode && (stash[idx] || !prev[pos])) { anchor = prev[pos + 1]; anchor = (anchor && parentNode && anchor.firstNode()) || nextNode; if (stash[idx]) { parentNode.insertBefore(next.detach(), anchor); } else { next.render(docFrag); parentNode.insertBefore(docFrag, anchor); } } prev[pos++] = 0; idx++; } if (next && isObjectType(next)) { if (next.shouldRebind || rebound) { next.rebound(rebound); next.shouldRebind = 0; } next.update(); next.shuffled(); } } } // clean up any stragglers var plen = prev.length; for (var i = 0; i < plen; i++) { prev[i] && prev[i].unbind().unrender(true); } if (this.shuffler) { this.values = shuffleValues(this, this.shuffler); } this.pendingNewIndices = null; this.previousIterations = null; }; RepeatedFragment.prototype.getContext = getContext; RepeatedFragment.prototype.getKeypath = getKeypath; // find the topmost delegate function findDelegate(start) { var frag = start; var delegate, el; out: while (frag) { // find next element el = 0; while (!el && frag) { if (frag.owner.type === ELEMENT) { el = frag.owner; } if (frag.owner.ractive && frag.owner.ractive.delegate === false) { break out; } frag = frag.parent || frag.componentParent; } if (el.delegate === false) { break out; } delegate = el.delegate || el; // find next repeated fragment while (frag) { if (frag.iterations) { break; } if (frag.owner.ractive && frag.owner.ractive.delegate === false) { break out; } frag = frag.parent || frag.componentParent; } } return delegate; } function swizzleFragment(section, fragment, key, idx) { var model = section.context ? contextFor(section, fragment, key) : undefined; fragment.key = key; fragment.index = idx; fragment.context = model; if (section.source) { fragment.lastValue = model && model.get(); } if (fragment.idxModel) { fragment.idxModel.applyValue(idx); } if (fragment.keyModel) { fragment.keyModel.applyValue(key); } if (fragment.pathModel) { fragment.pathModel.context = model; fragment.pathModel.applyValue(model.getKeypath()); } if (fragment.rootModel) { fragment.rootModel.context = model; fragment.rootModel.applyValue(model.getKeypath(fragment.ractive.root)); } // handle any aliases var aliases = fragment.aliases; section.aliases && section.aliases.forEach(function (a) { if (a.x.r === '.') { aliases[a.n] = model; } else if (a.x.r === '@index') { aliases[a.n] = fragment.getIndex(); } else if (a.x.r === '@key') { aliases[a.n] = fragment.getKey(); } else if (a.x.r === '@keypath') { aliases[a.n] = fragment.getKeypath(); } else if (a.x.r === '@rootpath') { aliases[a.n] = fragment.getKeypath(true); } }); } function shuffleValues(section, shuffler) { var array = section.context.get() || []; if (shuffler === true) { return array.slice(); } else { return array.map(function (v) { return shuffler.reduce(function (a, c) { return a && a[c]; }, v); }); } } function contextFor(section, fragment, key) { if (section.source) { var idx; var source = section.source.model.get(); if (source.indexOf && ~(idx = source.indexOf(section.context.joinKey(key).get()))) { return section.source.model.joinKey(idx); } } return section.context.joinKey(key); } function isEmpty(value) { return ( !value || (isArray(value) && value.length === 0) || (isObject(value) && keys(value).length === 0) ); } function getType(value, hasIndexRef) { if (hasIndexRef || isArray(value)) { return SECTION_EACH; } if (isObjectLike(value)) { return SECTION_IF_WITH; } if (isUndefined(value)) { return null; } return SECTION_IF; } var Section = (function (MustacheContainer) { function Section(options) { MustacheContainer.call(this, options); this.isAlias = options.template.t === ALIAS; this.sectionType = options.template.n || (this.isAlias && SECTION_WITH) || null; this.templateSectionType = this.sectionType; this.subordinate = options.template.l === 1; this.fragment = null; } if ( MustacheContainer ) Section.__proto__ = MustacheContainer; var Section__proto__ = Section.prototype = Object.create( MustacheContainer && MustacheContainer.prototype ); Section__proto__.constructor = Section; Section__proto__.bind = function bind () { MustacheContainer.prototype.bind.call(this); if (this.subordinate) { this.sibling = this.up.items[this.up.items.indexOf(this) - 1]; this.sibling.nextSibling = this; } // if we managed to bind, we need to create children if (this.model || this.isAlias) { this.dirty = true; this.update(); } else if ( this.sectionType && this.sectionType === SECTION_UNLESS && (!this.sibling || !this.sibling.isTruthy()) ) { this.fragment = new Fragment({ owner: this, template: this.template.f }).bind(); } }; Section__proto__.bubble = function bubble () { if (!this.dirty && this.yield) { this.dirty = true; this.containerFragment.bubble(); } else { MustacheContainer.prototype.bubble.call(this); } }; Section__proto__.detach = function detach () { var frag = this.fragment || this.detached; return frag ? frag.detach() : MustacheContainer.prototype.detach.call(this); }; Section__proto__.isTruthy = function isTruthy () { if (this.subordinate && this.sibling.isTruthy()) { return true; } var value = !this.model ? undefined : this.model.isRoot ? this.model.value : this.model.get(); return !!value && (this.templateSectionType === SECTION_IF_WITH || !isEmpty(value)); }; Section__proto__.rebind = function rebind (next, previous, safe) { if (MustacheContainer.prototype.rebind.call(this, next, previous, safe)) { if (this.fragment && this.sectionType !== SECTION_IF && this.sectionType !== SECTION_UNLESS) { this.fragment.rebind(next); } } }; Section__proto__.rebound = function rebound (update) { if (this.model) { if (this.model.rebound) { this.model.rebound(update); } else { MustacheContainer.prototype.unbind.call(this); MustacheContainer.prototype.bind.call(this); if ( this.sectionType === SECTION_WITH || this.sectionType === SECTION_IF_WITH || this.sectionType === SECTION_EACH ) { if (this.fragment) { this.fragment.rebind(this.model); } } if (update) { this.bubble(); } } } if (this.fragment) { this.fragment.rebound(update); } }; Section__proto__.render = function render (target, occupants) { this.rendered = true; if (this.fragment) { this.fragment.render(target, occupants); } }; Section__proto__.shuffle = function shuffle (newIndices) { if (this.fragment && this.sectionType === SECTION_EACH) { this.fragment.shuffle(newIndices); } }; Section__proto__.unbind = function unbind (view) { MustacheContainer.prototype.unbind.call(this, view); if (this.fragment) { this.fragment.unbind(view); } }; Section__proto__.unrender = function unrender (shouldDestroy) { if (this.rendered && this.fragment) { this.fragment.unrender(shouldDestroy); } this.rendered = false; }; Section__proto__.update = function update () { var this$1 = this; if (!this.dirty) { return; } if (this.fragment && this.sectionType !== SECTION_IF && this.sectionType !== SECTION_UNLESS) { this.fragment.context = this.model; } if (!this.model && this.sectionType !== SECTION_UNLESS && !this.isAlias) { return; } this.dirty = false; var value = !this.model ? undefined : this.model.isRoot ? this.model.value : this.model.get(); var siblingFalsey = !this.subordinate || !this.sibling.isTruthy(); var lastType = this.sectionType; if (this.yield && this.yield !== value) { this.up = this.containerFragment; this.container = null; this.yield = null; if (this.rendered) { this.fragment.unbind().unrender(true); } this.fragment = null; } else if (this.rendered && !this.yield && value instanceof Context) { if (this.rendered) { this.fragment.unbind().unrender(true); } this.fragment = null; } // watch for switching section types if (this.sectionType === null || this.templateSectionType === null) { this.sectionType = getType(value, this.template.i); } if (lastType && lastType !== this.sectionType && this.fragment) { if (this.rendered) { this.fragment.unbind().unrender(true); } this.fragment = null; } var newFragment; var fragmentShouldExist = this.sectionType === SECTION_EACH || // each always gets a fragment, which may have no iterations this.sectionType === SECTION_WITH || // with (partial context) always gets a fragment (siblingFalsey && (this.sectionType === SECTION_UNLESS ? !this.isTruthy() : this.isTruthy())) || // if, unless, and if-with depend on siblings and the condition this.isAlias; if (fragmentShouldExist) { if (!this.fragment) { this.fragment = this.detached; } if (this.fragment) { // check for detached fragment if (this.detached) { attach(this, this.fragment); this.detached = false; this.rendered = true; } if (!this.fragment.bound) { this.fragment.bind(this.model); } this.fragment.update(); } else { if (this.sectionType === SECTION_EACH) { newFragment = new RepeatedFragment({ owner: this, template: this.template.f, indexRef: this.template.i }).bind(this.model); } else { // only with and if-with provide context - if and unless do not var context = this.sectionType !== SECTION_IF && this.sectionType !== SECTION_UNLESS ? this.model : null; if (value instanceof Context) { this.yield = value; this.containerFragment = this.up; this.up = value.fragment; this.container = value.ractive; context = undefined; } newFragment = new Fragment({ owner: this, template: this.template.f }).bind(context); } } } else { if (this.fragment && this.rendered) { if (keep !== true) { this.fragment.unbind().unrender(true); } else { this.unrender(false); this.detached = this.fragment; runloop.promise().then(function () { if (this$1.detached) { this$1.detach(); } }); } } else if (this.fragment) { this.fragment.unbind(); } this.fragment = null; } if (newFragment) { if (this.rendered) { attach(this, newFragment); } this.fragment = newFragment; } if (this.nextSibling) { this.nextSibling.dirty = true; this.nextSibling.update(); } }; return Section; }(MustacheContainer)); function attach(section, fragment) { var anchor = (section.containerFragment || section.up).findNextNode(section); if (anchor) { var docFrag = createDocumentFragment(); fragment.render(docFrag); anchor.parentNode.insertBefore(docFrag, anchor); } else { fragment.render(section.up.findParentNode()); } } var Select = (function (Element) { function Select(options) { Element.call(this, options); this.options = []; } if ( Element ) Select.__proto__ = Element; var Select__proto__ = Select.prototype = Object.create( Element && Element.prototype ); Select__proto__.constructor = Select; Select__proto__.foundNode = function foundNode (node) { if (this.binding) { var selectedOptions = getSelectedOptions(node); if (selectedOptions.length > 0) { this.selectedOptions = selectedOptions; } } }; Select__proto__.render = function render (target, occupants) { Element.prototype.render.call(this, target, occupants); this.sync(); var node = this.node; var i = node.options.length; while (i--) { node.options[i].defaultSelected = node.options[i].selected; } this.rendered = true; }; Select__proto__.sync = function sync () { var this$1 = this; var selectNode = this.node; if (!selectNode) { return; } var options = toArray(selectNode.options); if (this.selectedOptions) { options.forEach(function (o) { if (this$1.selectedOptions.indexOf(o) >= 0) { o.selected = true; } else { o.selected = false; } }); this.binding.setFromNode(selectNode); delete this.selectedOptions; return; } var selectValue = this.getAttribute('value'); var isMultiple = this.getAttribute('multiple'); var array = isMultiple && isArray(selectValue); // If the <select> has a specified value, that should override // these options if (selectValue !== undefined) { var optionWasSelected; options.forEach(function (o) { var optionValue = o._ractive ? o._ractive.value : o.value; var shouldSelect = isMultiple ? array && this$1.valueContains(selectValue, optionValue) : this$1.compare(selectValue, optionValue); if (shouldSelect) { optionWasSelected = true; } o.selected = shouldSelect; }); if (!optionWasSelected && !isMultiple) { if (this.binding) { this.binding.forceUpdate(); } } } else if (this.binding && this.binding.forceUpdate) { // Otherwise the value should be initialised according to which // <option> element is selected, if twoway binding is in effect this.binding.forceUpdate(); } }; Select__proto__.valueContains = function valueContains (selectValue, optionValue) { var this$1 = this; var i = selectValue.length; while (i--) { if (this$1.compare(optionValue, selectValue[i])) { return true; } } }; Select__proto__.compare = function compare (optionValue, selectValue) { var comparator = this.getAttribute('value-comparator'); if (comparator) { if (isFunction(comparator)) { return comparator(selectValue, optionValue); } if (selectValue && optionValue) { return selectValue[comparator] == optionValue[comparator]; } } return selectValue == optionValue; }; Select__proto__.update = function update () { var dirty = this.dirty; Element.prototype.update.call(this); if (dirty) { this.sync(); } }; return Select; }(Element)); var Textarea = (function (Input) { function Textarea(options) { var template = options.template; options.deferContent = true; Input.call(this, options); // check for single interpolator binding if (!this.attributeByName.value) { if (template.f && isBindable({ template: template })) { (this.attributes || (this.attributes = [])).push( createItem({ owner: this, template: { t: ATTRIBUTE, f: template.f, n: 'value' }, up: this.up }) ); } else { this.fragment = new Fragment({ owner: this, cssIds: null, template: template.f }); } } } if ( Input ) Textarea.__proto__ = Input; var Textarea__proto__ = Textarea.prototype = Object.create( Input && Input.prototype ); Textarea__proto__.constructor = Textarea; Textarea__proto__.bubble = function bubble () { var this$1 = this; if (!this.dirty) { this.dirty = true; if (this.rendered && !this.binding && this.fragment) { runloop.scheduleTask(function () { this$1.dirty = false; this$1.node.value = this$1.fragment.toString(); }); } this.up.bubble(); // default behaviour } }; return Textarea; }(Input)); var Text = (function (Item) { function Text(options) { Item.call(this, options); this.type = TEXT; } if ( Item ) Text.__proto__ = Item; var Text__proto__ = Text.prototype = Object.create( Item && Item.prototype ); Text__proto__.constructor = Text; Text__proto__.detach = function detach () { return detachNode(this.node); }; Text__proto__.firstNode = function firstNode () { return this.node; }; Text__proto__.render = function render (target, occupants) { if (inAttributes()) { return; } this.rendered = true; progressiveText(this, target, occupants, this.template); }; Text__proto__.toString = function toString (escape) { return escape ? escapeHtml(this.template) : this.template; }; Text__proto__.unrender = function unrender (shouldDestroy) { if (this.rendered && shouldDestroy) { this.detach(); } this.rendered = false; }; Text__proto__.valueOf = function valueOf () { return this.template; }; return Text; }(Item)); var proto$7 = Text.prototype; proto$7.bind = proto$7.unbind = proto$7.update = noop; var visible; var hidden = 'hidden'; if (doc) { var prefix$2; /* istanbul ignore next */ if (hidden in doc) { prefix$2 = ''; } else { var i$1 = vendors.length; while (i$1--) { var vendor = vendors[i$1]; hidden = vendor + 'Hidden'; if (hidden in doc) { prefix$2 = vendor; break; } } } /* istanbul ignore else */ if (prefix$2 !== undefined) { doc.addEventListener(prefix$2 + 'visibilitychange', onChange); onChange(); } else { // gah, we're in an old browser if ('onfocusout' in doc) { doc.addEventListener('focusout', onHide); doc.addEventListener('focusin', onShow); } else { win.addEventListener('pagehide', onHide); win.addEventListener('blur', onHide); win.addEventListener('pageshow', onShow); win.addEventListener('focus', onShow); } visible = true; // until proven otherwise. Not ideal but hey } } function onChange() { visible = !doc[hidden]; } /* istanbul ignore next */ function onHide() { visible = false; } /* istanbul ignore next */ function onShow() { visible = true; } var prefix; /* istanbul ignore next */ if (!isClient) { prefix = null; } else { var prefixCache = {}; var testStyle = createElement('div').style; // technically this also normalizes on hyphenated styles as well prefix = function(prop) { if (!prefixCache[prop]) { var name = hyphenateCamel(prop); if (testStyle[prop] !== undefined) { prefixCache[prop] = name; } else { /* istanbul ignore next */ // test vendors... var i = vendors.length; while (i--) { var vendor = "-" + (vendors[i]) + "-" + name; if (testStyle[vendor] !== undefined) { prefixCache[prop] = vendor; break; } } } } return prefixCache[prop]; }; } var prefix$1 = prefix; var vendorPattern = new RegExp('^(?:' + vendors.join('|') + ')([A-Z])'); function hyphenate(str) { /* istanbul ignore next */ if (!str) { return ''; } // edge case /* istanbul ignore next */ if (vendorPattern.test(str)) { str = '-' + str; } return str.replace(/[A-Z]/g, function (match) { return '-' + match.toLowerCase(); }); } var createTransitions; if (!isClient) { createTransitions = null; } else { var testStyle$1 = createElement('div').style; var linear$1 = function (x) { return x; }; var canUseCssTransitions = {}; var cannotUseCssTransitions = {}; // determine some facts about our environment var TRANSITION$1; var TRANSITIONEND; var CSS_TRANSITIONS_ENABLED; var TRANSITION_DURATION; var TRANSITION_PROPERTY; var TRANSITION_TIMING_FUNCTION; if (testStyle$1.transition !== undefined) { TRANSITION$1 = 'transition'; TRANSITIONEND = 'transitionend'; CSS_TRANSITIONS_ENABLED = true; } else if (testStyle$1.webkitTransition !== undefined) { TRANSITION$1 = 'webkitTransition'; TRANSITIONEND = 'webkitTransitionEnd'; CSS_TRANSITIONS_ENABLED = true; } else { CSS_TRANSITIONS_ENABLED = false; } if (TRANSITION$1) { TRANSITION_DURATION = TRANSITION$1 + 'Duration'; TRANSITION_PROPERTY = TRANSITION$1 + 'Property'; TRANSITION_TIMING_FUNCTION = TRANSITION$1 + 'TimingFunction'; } createTransitions = function(t, to, options, changedProperties, resolve) { // Wait a beat (otherwise the target styles will be applied immediately) // TODO use a fastdom-style mechanism? setTimeout(function () { var jsTransitionsComplete; var cssTransitionsComplete; var cssTimeout; // eslint-disable-line prefer-const function transitionDone() { clearTimeout(cssTimeout); } function checkComplete() { if (jsTransitionsComplete && cssTransitionsComplete) { t.unregisterCompleteHandler(transitionDone); // will changes to events and fire have an unexpected consequence here? t.ractive.fire(t.name + ':end', t.node, t.isIntro); resolve(); } } // this is used to keep track of which elements can use CSS to animate // which properties var hashPrefix = (t.node.namespaceURI || '') + t.node.tagName; // need to reset transition properties var style = t.node.style; var previous = { property: style[TRANSITION_PROPERTY], timing: style[TRANSITION_TIMING_FUNCTION], duration: style[TRANSITION_DURATION] }; function transitionEndHandler(event) { var index = changedProperties.indexOf(event.propertyName); if (index !== -1) { changedProperties.splice(index, 1); } if (changedProperties.length) { // still transitioning... return; } clearTimeout(cssTimeout); cssTransitionsDone(); } function cssTransitionsDone() { style[TRANSITION_PROPERTY] = previous.property; style[TRANSITION_TIMING_FUNCTION] = previous.duration; style[TRANSITION_DURATION] = previous.timing; t.node.removeEventListener(TRANSITIONEND, transitionEndHandler, false); cssTransitionsComplete = true; checkComplete(); } t.node.addEventListener(TRANSITIONEND, transitionEndHandler, false); // safety net in case transitionend never fires cssTimeout = setTimeout(function () { changedProperties = []; cssTransitionsDone(); }, options.duration + (options.delay || 0) + 50); t.registerCompleteHandler(transitionDone); style[TRANSITION_PROPERTY] = changedProperties.join(','); var easingName = hyphenate(options.easing || 'linear'); style[TRANSITION_TIMING_FUNCTION] = easingName; var cssTiming = style[TRANSITION_TIMING_FUNCTION] === easingName; style[TRANSITION_DURATION] = options.duration / 1000 + 's'; setTimeout(function () { var i = changedProperties.length; var hash; var originalValue = null; var index; var propertiesToTransitionInJs = []; var prop; var suffix; var interpolator; while (i--) { prop = changedProperties[i]; hash = hashPrefix + prop; if (cssTiming && CSS_TRANSITIONS_ENABLED && !cannotUseCssTransitions[hash]) { var initial = style[prop]; style[prop] = to[prop]; // If we're not sure if CSS transitions are supported for // this tag/property combo, find out now if (!(hash in canUseCssTransitions)) { originalValue = t.getStyle(prop); // if this property is transitionable in this browser, // the current style will be different from the target style canUseCssTransitions[hash] = t.getStyle(prop) != to[prop]; cannotUseCssTransitions[hash] = !canUseCssTransitions[hash]; // Reset, if we're going to use timers after all if (cannotUseCssTransitions[hash]) { style[prop] = initial; } } } if (!cssTiming || !CSS_TRANSITIONS_ENABLED || cannotUseCssTransitions[hash]) { // we need to fall back to timer-based stuff if (originalValue === null) { originalValue = t.getStyle(prop); } // need to remove this from changedProperties, otherwise transitionEndHandler // will get confused index = changedProperties.indexOf(prop); if (index === -1) { warnIfDebug( 'Something very strange happened with transitions. Please raise an issue at https://github.com/ractivejs/ractive/issues - thanks!', { node: t.node } ); } else { changedProperties.splice(index, 1); } // TODO Determine whether this property is animatable at all suffix = /[^\d]*$/.exec(originalValue)[0]; interpolator = interpolate(parseFloat(originalValue), parseFloat(to[prop])); // ...then kick off a timer-based transition if (interpolator) { propertiesToTransitionInJs.push({ name: prop, interpolator: interpolator, suffix: suffix }); } else { style[prop] = to[prop]; } originalValue = null; } } // javascript transitions if (propertiesToTransitionInJs.length) { var easing; if (isString(options.easing)) { easing = t.ractive.easing[options.easing]; if (!easing) { warnOnceIfDebug(missingPlugin(options.easing, 'easing')); easing = linear$1; } } else if (isFunction(options.easing)) { easing = options.easing; } else { easing = linear$1; } new Ticker({ duration: options.duration, easing: easing, step: function step(pos) { var i = propertiesToTransitionInJs.length; while (i--) { var prop = propertiesToTransitionInJs[i]; style[prop.name] = prop.interpolator(pos) + prop.suffix; } }, complete: function complete() { jsTransitionsComplete = true; checkComplete(); } }); } else { jsTransitionsComplete = true; } if (changedProperties.length) { style[TRANSITION_PROPERTY] = changedProperties.join(','); } else { style[TRANSITION_PROPERTY] = 'none'; // We need to cancel the transitionEndHandler, and deal with // the fact that it will never fire t.node.removeEventListener(TRANSITIONEND, transitionEndHandler, false); cssTransitionsComplete = true; checkComplete(); } }, 0); }, options.delay || 0); }; } var createTransitions$1 = createTransitions; var getComputedStyle = win && win.getComputedStyle; var resolved = Promise.resolve(); var names = { t0: 'intro-outro', t1: 'intro', t2: 'outro' }; var Transition = function Transition(options) { this.owner = options.owner || options.up.owner || findElement(options.up); this.element = this.owner.attributeByName ? this.owner : findElement(options.up); this.ractive = this.owner.ractive; this.template = options.template; this.up = options.up; this.options = options; this.onComplete = []; }; var Transition__proto__ = Transition.prototype; Transition__proto__.animateStyle = function animateStyle (style, value, options) { var this$1 = this; if (arguments.length === 4) { throw new Error( 't.animateStyle() returns a promise - use .then() instead of passing a callback' ); } // Special case - page isn't visible. Don't animate anything, because // that way you'll never get CSS transitionend events if (!visible) { this.setStyle(style, value); return resolved; } var to; if (isString(style)) { to = {}; to[style] = value; } else { to = style; // shuffle arguments options = value; } return new Promise(function (fulfil) { // Edge case - if duration is zero, set style synchronously and complete if (!options.duration) { this$1.setStyle(to); fulfil(); return; } // Get a list of the properties we're animating var propertyNames = keys(to); var changedProperties = []; // Store the current styles var computedStyle = getComputedStyle(this$1.node); var i = propertyNames.length; while (i--) { var prop = propertyNames[i]; var name = prefix$1(prop); var current = computedStyle[prefix$1(prop)]; // record the starting points var init = this$1.node.style[name]; if (!(name in this$1.originals)) { this$1.originals[name] = this$1.node.style[name]; } this$1.node.style[name] = to[prop]; this$1.targets[name] = this$1.node.style[name]; this$1.node.style[name] = init; // we need to know if we're actually changing anything if (current != to[prop]) { // use != instead of !==, so we can compare strings with numbers changedProperties.push(name); // if we happened to prefix, make sure there is a properly prefixed value to[name] = to[prop]; // make the computed style explicit, so we can animate where // e.g. height='auto' this$1.node.style[name] = current; } } // If we're not actually changing anything, the transitionend event // will never fire! So we complete early if (!changedProperties.length) { fulfil(); return; } createTransitions$1(this$1, to, options, changedProperties, fulfil); }); }; Transition__proto__.bind = function bind () { var options = this.options; var type = options.template && options.template.v; if (type) { if (type === 't0' || type === 't1') { this.element.intro = this; } if (type === 't0' || type === 't2') { this.element.outro = this; } this.eventName = names[type]; } var ractive = this.owner.ractive; this.name = options.name || options.template.n; if (options.params) { this.params = options.params; } if (isFunction(this.name)) { this._fn = this.name; this.name = this._fn.name; } else { this._fn = findInViewHierarchy('transitions', ractive, this.name); } if (!this._fn) { warnOnceIfDebug(missingPlugin(this.name, 'transition'), { ractive: ractive }); } setupArgsFn(this, options.template); }; Transition__proto__.getParams = function getParams () { if (this.params) { return this.params; } // get expression args if supplied if (this.fn) { var values = resolveArgs(this, this.template, this.up).map(function (model) { if (!model) { return undefined; } return model.get(); }); return this.fn.apply(this.ractive, values); } }; Transition__proto__.getStyle = function getStyle (props) { var computedStyle = getComputedStyle(this.node); if (isString(props)) { return computedStyle[prefix$1(props)]; } if (!isArray(props)) { throw new Error( 'Transition$getStyle must be passed a string, or an array of strings representing CSS properties' ); } var styles = {}; var i = props.length; while (i--) { var prop = props[i]; var value = computedStyle[prefix$1(prop)]; if (value === '0px') { value = 0; } styles[prop] = value; } return styles; }; Transition__proto__.processParams = function processParams (params, defaults) { if (isNumber(params)) { params = { duration: params }; } else if (isString(params)) { if (params === 'slow') { params = { duration: 600 }; } else if (params === 'fast') { params = { duration: 200 }; } else { params = { duration: 400 }; } } else if (!params) { params = {}; } return assign({}, defaults, params); }; Transition__proto__.registerCompleteHandler = function registerCompleteHandler (fn) { addToArray(this.onComplete, fn); }; Transition__proto__.setStyle = function setStyle (style, value) { var this$1 = this; if (isString(style)) { var name = prefix$1(style); if (!hasOwn(this.originals, name)) { this.originals[name] = this.node.style[name]; } this.node.style[name] = value; this.targets[name] = this.node.style[name]; } else { var prop; for (prop in style) { if (hasOwn(style, prop)) { this$1.setStyle(prop, style[prop]); } } } return this; }; Transition__proto__.shouldFire = function shouldFire (type) { if (!this.ractive.transitionsEnabled) { return false; } // check for noIntro and noOutro cases, which only apply when the owner ractive is rendering and unrendering, respectively if (type === 'intro' && this.ractive.rendering && nearestProp('noIntro', this.ractive, true)) { return false; } if (type === 'outro' && this.ractive.unrendering && nearestProp('noOutro', this.ractive, false)) { return false; } var params = this.getParams(); // this is an array, the params object should be the first member // if there's not a parent element, this can't be nested, so roll on if (!this.element.parent) { return true; } // if there is a local param, it takes precedent if (params && params[0] && isObject(params[0]) && 'nested' in params[0]) { if (params[0].nested !== false) { return true; } } else { // use the nearest instance setting // find the nearest instance that actually has a nested setting if (nearestProp('nestedTransitions', this.ractive) !== false) { return true; } } // check to see if this is actually a nested transition var el = this.element.parent; while (el) { if (el[type] && el[type].starting) { return false; } el = el.parent; } return true; }; Transition__proto__.start = function start () { var this$1 = this; var node = (this.node = this.element.node); var originals = (this.originals = {}); //= node.getAttribute( 'style' ); var targets = (this.targets = {}); var completed; var args = this.getParams(); // create t.complete() - we don't want this on the prototype, // because we don't want `this` silliness when passing it as // an argument this.complete = function (noReset) { this$1.starting = false; if (completed) { return; } this$1.onComplete.forEach(function (fn) { return fn(); }); if (!noReset && this$1.isIntro) { for (var k in targets) { if (node.style[k] === targets[k]) { node.style[k] = originals[k]; } } } this$1._manager.remove(this$1); completed = true; }; // If the transition function doesn't exist, abort if (!this._fn) { this.complete(); return; } var promise = this._fn.apply(this.ractive, [this].concat(args)); if (promise) { promise.then(this.complete); } }; Transition__proto__.toString = function toString () { return ''; }; Transition__proto__.unbind = function unbind () { if (!this.element.attributes.unbinding) { var type = this.options && this.options.template && this.options.template.v; if (type === 't0' || type === 't1') { this.element.intro = null; } if (type === 't0' || type === 't2') { this.element.outro = null; } } }; Transition__proto__.unregisterCompleteHandler = function unregisterCompleteHandler (fn) { removeFromArray(this.onComplete, fn); }; var proto$8 = Transition.prototype; proto$8.destroyed = proto$8.firstNode = proto$8.rebound = proto$8.render = proto$8.unrender = proto$8.update = noop; function nearestProp(prop, ractive, rendering) { var instance = ractive; while (instance) { if ( hasOwn(instance, prop) && (isUndefined(rendering) || rendering ? instance.rendering : instance.unrendering) ) { return instance[prop]; } instance = instance.component && instance.component.ractive; } return ractive[prop]; } var elementCache = {}; var ieBug; var ieBlacklist; try { createElement('table').innerHTML = 'foo'; } catch (/* istanbul ignore next */ err) { ieBug = true; ieBlacklist = { TABLE: ['<table class="x">', '</table>'], THEAD: ['<table><thead class="x">', '</thead></table>'], TBODY: ['<table><tbody class="x">', '</tbody></table>'], TR: ['<table><tr class="x">', '</tr></table>'], SELECT: ['<select class="x">', '</select>'] }; } function insertHtml(html$$1, node) { var nodes = []; // render 0 and false if (html$$1 == null || html$$1 === '') { return nodes; } var container; var wrapper; var selectedOption; /* istanbul ignore if */ if (ieBug && (wrapper = ieBlacklist[node.tagName])) { container = element('DIV'); container.innerHTML = wrapper[0] + html$$1 + wrapper[1]; container = container.querySelector('.x'); if (container.tagName === 'SELECT') { selectedOption = container.options[container.selectedIndex]; } } else if (node.namespaceURI === svg$1) { container = element('DIV'); container.innerHTML = '<svg class="x">' + html$$1 + '</svg>'; container = container.querySelector('.x'); } else if (node.tagName === 'TEXTAREA') { container = createElement('div'); if (typeof container.textContent !== 'undefined') { container.textContent = html$$1; } else { container.innerHTML = html$$1; } } else { container = element(node.tagName); container.innerHTML = html$$1; if (container.tagName === 'SELECT') { selectedOption = container.options[container.selectedIndex]; } } var child; while ((child = container.firstChild)) { nodes.push(child); container.removeChild(child); } // This is really annoying. Extracting <option> nodes from the // temporary container <select> causes the remaining ones to // become selected. So now we have to deselect them. IE8, you // amaze me. You really do // ...and now Chrome too var i; if (node.tagName === 'SELECT') { i = nodes.length; while (i--) { if (nodes[i] !== selectedOption) { nodes[i].selected = false; } } } return nodes; } function element(tagName) { return elementCache[tagName] || (elementCache[tagName] = createElement(tagName)); } var Triple = (function (Mustache) { function Triple(options) { Mustache.call(this, options); } if ( Mustache ) Triple.__proto__ = Mustache; var Triple__proto__ = Triple.prototype = Object.create( Mustache && Mustache.prototype ); Triple__proto__.constructor = Triple; Triple__proto__.detach = function detach () { var docFrag = createDocumentFragment(); if (this.nodes) { this.nodes.forEach(function (node) { return docFrag.appendChild(node); }); } return docFrag; }; Triple__proto__.find = function find (selector) { var this$1 = this; var len = this.nodes.length; var i; for (i = 0; i < len; i += 1) { var node = this$1.nodes[i]; if (node.nodeType !== 1) { continue; } if (matches(node, selector)) { return node; } var queryResult = node.querySelector(selector); if (queryResult) { return queryResult; } } return null; }; Triple__proto__.findAll = function findAll (selector, options) { var this$1 = this; var result = options.result; var len = this.nodes.length; var i; for (i = 0; i < len; i += 1) { var node = this$1.nodes[i]; if (node.nodeType !== 1) { continue; } if (matches(node, selector)) { result.push(node); } var queryAllResult = node.querySelectorAll(selector); if (queryAllResult) { result.push.apply(result, queryAllResult); } } }; Triple__proto__.findComponent = function findComponent () { return null; }; Triple__proto__.firstNode = function firstNode () { return this.rendered && this.nodes[0]; }; Triple__proto__.render = function render (target, occupants, anchor) { var this$1 = this; if (!this.nodes) { var html = this.model ? this.model.get() : ''; this.nodes = insertHtml(html, target); } var nodes = this.nodes; // progressive enhancement if (occupants) { var i = -1; var next; // start with the first node that should be rendered while (occupants.length && (next = this.nodes[i + 1])) { var n = (void 0); // look through the occupants until a matching node is found while ((n = occupants.shift())) { var t = n.nodeType; if ( t === next.nodeType && ((t === 1 && n.outerHTML === next.outerHTML) || ((t === 3 || t === 8) && n.nodeValue === next.nodeValue)) ) { this$1.nodes.splice(++i, 1, n); // replace the generated node with the existing one break; } else { target.removeChild(n); // remove the non-matching existing node } } } if (i >= 0) { // update the list of remaining nodes to attach, excluding any that were replaced by existing nodes nodes = this.nodes.slice(i); } // update the anchor to be the next occupant if (occupants.length) { anchor = occupants[0]; } } // attach any remainging nodes to the parent if (nodes.length) { var frag = createDocumentFragment(); nodes.forEach(function (n) { return frag.appendChild(n); }); if (anchor) { target.insertBefore(frag, anchor); } else { target.appendChild(frag); } } this.rendered = true; }; Triple__proto__.toString = function toString () { var value = this.model && this.model.get(); value = value != null ? '' + value : ''; return inAttribute() ? decodeCharacterReferences(value) : value; }; Triple__proto__.unrender = function unrender () { if (this.nodes) { this.nodes.forEach(function (node) { // defer detachment until all relevant outros are done runloop.detachWhenReady({ node: node, detach: function detach() { detachNode(node); } }); }); } this.rendered = false; this.nodes = null; }; Triple__proto__.update = function update () { if (this.rendered && this.dirty) { this.dirty = false; this.unrender(); this.render(this.up.findParentNode(), null, this.up.findNextNode(this)); } else { // make sure to reset the dirty flag even if not rendered this.dirty = false; } }; return Triple; }(Mustache)); // finds the component constructor in the registry or view hierarchy registries function getComponentConstructor(ractive, name) { var instance = findInstance('components', ractive, name); var Component; if (instance) { Component = instance.components[name]; if (Component && !Component.isInstance) { if (Component.default && Component.default.isInstance) { Component = Component.default; } else if (!Component.then && isFunction(Component)) { // function option, execute and store for reset var fn = Component.bind(instance); fn.isOwner = hasOwn(instance.components, name); Component = fn(); if (!Component) { warnIfDebug(noRegistryFunctionReturn, name, 'component', 'component', { ractive: ractive }); return; } if (isString(Component)) { // allow string lookup Component = getComponentConstructor(ractive, Component); } Component._fn = fn; instance.components[name] = Component; } } } return Component; } function asyncProxy(promise, options) { var partials = options.template.p || {}; var name = options.template.e; var opts = assign({}, options, { template: { t: ELEMENT, e: name }, macro: function macro(handle) { handle.setTemplate(partials['async-loading'] || []); promise.then( function (cmp) { options.up.ractive.components[name] = cmp; if (partials['async-loaded']) { handle.partials.component = [options.template]; handle.setTemplate(partials['async-loaded']); } else { handle.setTemplate([options.template]); } }, function (err) { if (partials['async-failed']) { handle.aliasLocal('error', 'error'); handle.set('@local.error', err); handle.setTemplate(partials['async-failed']); } else { handle.setTemplate([]); } } ); } }); return new Partial(opts); } function extract(tpl, type, name) { var p = tpl.f.find(function (s) { return s.t === type; }); if (p) { if (p.n) { return [ { t: 19, n: 54, f: p.f || [], z: [{ n: p.n, x: { r: ("__await." + name) } }] } ]; } else { return p.f || []; } } else { return []; } } function Await(options) { var tpl = options.template; var success = extract(tpl, THEN, 'value'); var error = extract(tpl, CATCH, 'error'); var pending = extract(tpl, SECTION); var undef = extract(tpl, ELSE); var opts = assign({}, options, { template: { t: ELEMENT, m: [ { t: ATTRIBUTE, n: 'for', f: [{ t: INTERPOLATOR, r: tpl.r, rx: tpl.rx, x: tpl.x }] } ] }, macro: function macro(handle, attrs) { handle.aliasLocal('__await'); function update(attrs) { if (attrs.for && isFunction(attrs.for.then)) { handle.setTemplate(pending); attrs.for.then( function (v) { handle.set('@local.value', v); handle.setTemplate(success); }, function (e) { handle.set('@local.error', e); handle.setTemplate(error); } ); } else if (isUndefined(attrs.for)) { handle.setTemplate(undef); } else { handle.set('@local.value', attrs.for); handle.setTemplate(success); } } update(attrs); return { update: update }; } }); opts.macro.attributes = ['for']; return new Partial(opts); } var constructors = {}; constructors[ALIAS] = Section; constructors[ANCHOR] = Component; constructors[AWAIT] = Await; constructors[DOCTYPE] = Doctype; constructors[INTERPOLATOR] = Interpolator; constructors[PARTIAL] = Partial; constructors[SECTION] = Section; constructors[TRIPLE] = Triple; constructors[YIELDER] = Partial; constructors[ATTRIBUTE] = Attribute; constructors[BINDING_FLAG] = BindingFlag; constructors[DECORATOR] = Decorator; constructors[EVENT] = EventDirective; constructors[TRANSITION] = Transition; constructors[COMMENT] = Comment; var specialElements = { doctype: Doctype, form: Form, input: Input, option: Option, select: Select, textarea: Textarea }; function createItem(options) { if (isString(options.template)) { return new Text(options); } var ctor; var name; var type = options.template.t; if (type === ELEMENT) { name = options.template.e; // could be a macro partial ctor = findInstance('partials', options.up.ractive, name); if (ctor) { ctor = ctor.partials[name]; if (ctor.styleSet) { options.macro = ctor; return new Partial(options); } } // could be component or element ctor = getComponentConstructor(options.up.ractive, name); if (ctor) { if (isFunction(ctor.then)) { return asyncProxy(ctor, options); } else if (isFunction(ctor)) { return new Component(options, ctor); } } ctor = specialElements[name.toLowerCase()] || Element; return new ctor(options); } var Item; // component mappings are a special case of attribute if (type === ATTRIBUTE) { var el = options.owner; if (!el || (el.type !== ANCHOR && el.type !== COMPONENT && el.type !== ELEMENT)) { el = findElement(options.up); } options.element = el; Item = el.type === COMPONENT || el.type === ANCHOR ? Mapping : Attribute; } else { Item = constructors[type]; } if (!Item) { throw new Error(("Unrecognised item type " + type)); } return new Item(options); } // TODO all this code needs to die function processItems(items, values, guid, counter) { if ( counter === void 0 ) counter = 0; return items .map(function (item) { if (item.type === TEXT) { return item.template; } if (item.fragment) { if (item.fragment.iterations) { return item.fragment.iterations .map(function (fragment) { return processItems(fragment.items, values, guid, counter); }) .join(''); } else { return processItems(item.fragment.items, values, guid, counter); } } var placeholderId = guid + "-" + (counter++); var model = item.model || item.newModel; values[placeholderId] = model ? model.wrapper ? model.wrapperValue : model.get() : undefined; return '${' + placeholderId + '}'; }) .join(''); } function resolveAliases(aliases, fragment, dest) { if ( dest === void 0 ) dest = {}; for (var i = 0; i < aliases.length; i++) { if (!dest[aliases[i].n]) { var m = resolve(fragment, aliases[i].x); dest[aliases[i].n] = m; m.reference(); } } return dest; } var Fragment = function Fragment(options) { this.owner = options.owner; // The item that owns this fragment - an element, section, partial, or attribute this.isRoot = !options.owner.up; this.parent = this.isRoot ? null : this.owner.up; this.ractive = options.ractive || (this.isRoot ? options.owner : this.parent.ractive); this.componentParent = this.isRoot && this.ractive.component ? this.ractive.component.up : null; if (!this.isRoot || this.ractive.delegate) { this.delegate = this.owner.containerFragment ? this.owner.containerFragment && this.owner.containerFragment.delegate : (this.componentParent && this.componentParent.delegate) || (this.parent && this.parent.delegate); } else { this.delegate = false; } this.context = null; this.rendered = false; // encapsulated styles should be inherited until they get applied by an element if ('cssIds' in options) { this.cssIds = options.cssIds && options.cssIds.length && options.cssIds; } else { this.cssIds = this.parent ? this.parent.cssIds : null; } this.dirty = false; this.dirtyValue = true; // used for attribute values this.template = options.template || []; this.createItems(); }; var Fragment__proto__ = Fragment.prototype; Fragment__proto__.bind = function bind (context) { var this$1 = this; this.context = context; if (this.owner.template.z) { this.aliases = resolveAliases( this.owner.template.z, this.owner.containerFragment || this.parent ); } var len = this.items.length; for (var i = 0; i < len; i++) { this$1.items[i].bind(); } this.bound = true; // in rare cases, a forced resolution (or similar) will cause the // fragment to be dirty before it's even finished binding. In those // cases we update immediately if (this.dirty) { this.update(); } return this; }; Fragment__proto__.bubble = function bubble () { this.dirtyValue = true; if (!this.dirty) { this.dirty = true; if (this.isRoot) { // TODO encapsulate 'is component root, but not overall root' check? if (this.ractive.component) { this.ractive.component.bubble(); } else if (this.bound) { runloop.addFragment(this); } } else { this.owner.bubble(this.index); } } }; Fragment__proto__.createItems = function createItems () { var this$1 = this; // this is a hot code path var max = this.template.length; this.items = []; for (var i = 0; i < max; i++) { this$1.items[i] = createItem({ up: this$1, template: this$1.template[i], index: i }); } }; Fragment__proto__.destroyed = function destroyed () { var this$1 = this; var len = this.items.length; for (var i = 0; i < len; i++) { this$1.items[i].destroyed(); } if (this.pathModel) { this.pathModel.destroyed(); } if (this.rootModel) { this.rootModel.destroyed(); } }; Fragment__proto__.detach = function detach () { var docFrag = createDocumentFragment(); var xs = this.items; var len = xs.length; for (var i = 0; i < len; i++) { docFrag.appendChild(xs[i].detach()); } return docFrag; }; Fragment__proto__.find = function find (selector, options) { return findMap(this.items, function (i) { return i.find(selector, options); }); }; Fragment__proto__.findAll = function findAll (selector, options) { if (this.items) { this.items.forEach(function (i) { return i.findAll && i.findAll(selector, options); }); } }; Fragment__proto__.findComponent = function findComponent (name, options) { return findMap(this.items, function (i) { return i.findComponent(name, options); }); }; Fragment__proto__.findAllComponents = function findAllComponents (name, options) { if (this.items) { this.items.forEach(function (i) { return i.findAllComponents && i.findAllComponents(name, options); }); } }; Fragment__proto__.findContext = function findContext () { var base = findParentWithContext(this); if (!base || !base.context) { return this.ractive.viewmodel; } else { return base.context; } }; Fragment__proto__.findNextNode = function findNextNode (item) { var this$1 = this; // search for the next node going forward if (item) { var it; for (var i = item.index + 1; i < this.items.length; i++) { it = this$1.items[i]; if (!it || !it.firstNode) { continue; } var node = it.firstNode(true); if (node) { return node; } } } // if this is the root fragment, and there are no more items, // it means we're at the end... if (this.isRoot) { if (this.ractive.component) { return this.ractive.component.up.findNextNode(this.ractive.component); } // TODO possible edge case with other content // appended to this.ractive.el? return null; } if (this.parent) { return this.owner.findNextNode(this); } // the argument is in case the parent is a RepeatedFragment }; Fragment__proto__.findParentNode = function findParentNode () { var fragment = this; do { if (fragment.owner.type === ELEMENT) { return fragment.owner.node; } if (fragment.isRoot && !fragment.ractive.component) { // TODO encapsulate check return fragment.ractive.el; } if (fragment.owner.type === YIELDER) { fragment = fragment.owner.containerFragment; } else { fragment = fragment.componentParent || fragment.parent; // TODO ugh } } while (fragment); throw new Error('Could not find parent node'); // TODO link to issue tracker }; Fragment__proto__.firstNode = function firstNode (skipParent) { var node = findMap(this.items, function (i) { return i.firstNode(true); }); if (node) { return node; } if (skipParent) { return null; } return this.parent.findNextNode(this.owner); }; Fragment__proto__.getKey = function getKey () { return this.keyModel || (this.keyModel = new KeyModel(this.key)); }; Fragment__proto__.getIndex = function getIndex () { return this.idxModel || (this.idxModel = new KeyModel(this.index)); }; Fragment__proto__.rebind = function rebind (next) { this.context = next; if (this.rootModel) { this.rootModel.context = this.context; } if (this.pathModel) { this.pathModel.context = this.context; } }; Fragment__proto__.rebound = function rebound (update$$1) { if (this.owner.template.z) { var aliases = this.aliases; for (var k in aliases) { if (aliases[k].rebound) { aliases[k].rebound(update$$1); } else { aliases[k].unreference(); aliases[k] = 0; } } resolveAliases(this.owner.template.z, this.owner.containerFragment || this.parent, aliases); } this.items.forEach(function (x) { return x.rebound(update$$1); }); if (update$$1) { if (this.rootModel) { this.rootModel.applyValue(this.context.getKeypath(this.ractive.root)); } if (this.pathModel) { this.pathModel.applyValue(this.context.getKeypath()); } } }; Fragment__proto__.render = function render (target, occupants) { if (this.rendered) { throw new Error('Fragment is already rendered!'); } this.rendered = true; var xs = this.items; var len = xs.length; for (var i = 0; i < len; i++) { xs[i].render(target, occupants); } }; Fragment__proto__.resetTemplate = function resetTemplate (template) { var wasBound = this.bound; var wasRendered = this.rendered; // TODO ensure transitions are disabled globally during reset if (wasBound) { if (wasRendered) { this.unrender(true); } this.unbind(); } this.template = template; this.createItems(); if (wasBound) { this.bind(this.context); if (wasRendered) { var parentNode = this.findParentNode(); var anchor = this.findNextNode(); if (anchor) { var docFrag = createDocumentFragment(); this.render(docFrag); parentNode.insertBefore(docFrag, anchor); } else { this.render(parentNode); } } } }; Fragment__proto__.shuffled = function shuffled$2 () { this.items.forEach(shuffled); if (this.rootModel) { this.rootModel.applyValue(this.context.getKeypath(this.ractive.root)); } if (this.pathModel) { this.pathModel.applyValue(this.context.getKeypath()); } }; Fragment__proto__.toString = function toString (escape) { return this.items.map(escape ? toEscapedString : toString$1).join(''); }; Fragment__proto__.unbind = function unbind (view) { var this$1 = this; if (this.owner.template.z && !this.owner.yielder) { for (var k in this$1.aliases) { this$1.aliases[k].unreference(); } this.aliases = {}; } this.context = null; var len = this.items.length; for (var i = 0; i < len; i++) { this$1.items[i].unbind(view); } this.bound = false; return this; }; Fragment__proto__.unrender = function unrender (shouldDestroy) { var this$1 = this; var len = this.items.length; for (var i = 0; i < len; i++) { this$1.items[i].unrender(shouldDestroy); } this.rendered = false; }; Fragment__proto__.update = function update () { var this$1 = this; if (this.dirty) { if (!this.updating) { this.dirty = false; this.updating = true; var len = this.items.length; for (var i = 0; i < len; i++) { this$1.items[i].update(); } this.updating = false; } else if (this.isRoot) { runloop.addFragmentToRoot(this); } } }; Fragment__proto__.valueOf = function valueOf () { if (this.items.length === 1) { return this.items[0].valueOf(); } if (this.dirtyValue) { var values = {}; var source = processItems(this.items, values, this.ractive._guid); var parsed = parseJSON(source, values); this.value = parsed ? parsed.value : this.toString(); this.dirtyValue = false; } return this.value; }; Fragment.prototype.getContext = getContext; Fragment.prototype.getKeypath = getKeypath; function getKeypath(root) { var base = findParentWithContext(this); var model; if (root) { if (!this.rootModel) { this.rootModel = new KeyModel( this.context.getKeypath(this.ractive.root), this.context, this.ractive.root ); model = this.rootModel; } else { return this.rootModel; } } else { if (!this.pathModel) { this.pathModel = new KeyModel(this.context.getKeypath(), this.context); model = this.pathModel; } else { return this.pathModel; } } if (base && base.context) { base.getKeypath(root).registerChild(model); } return model; } function initialise(ractive, userOptions, options) { // initialize settable computeds var computed = ractive.viewmodel.computed; if (computed) { for (var k in computed) { if (k in ractive.viewmodel.value && computed[k] && !computed[k].isReadonly) { computed[k].set(ractive.viewmodel.value[k]); } } } // init config from Parent and options config.init(ractive.constructor, ractive, userOptions); // call any passed in plugins if (isArray(userOptions.use)) { ractive.use.apply(ractive, userOptions.use.filter(function (p) { return !p.construct; })); } hooks.config.fire(ractive); hooks.init.begin(ractive); var fragment = (ractive.fragment = createFragment$1(ractive, options)); if (fragment) { fragment.bind(ractive.viewmodel); } hooks.init.end(ractive); // general config done, set up observers subscribe(ractive, userOptions, 'observe'); if (fragment) { // render automatically ( if `el` is specified ) var el = (ractive.el = ractive.target = getElement(ractive.el || ractive.target)); if (el && !ractive.component) { var promise = ractive.render(el, ractive.append); if (Ractive.DEBUG_PROMISES) { promise.catch(function (err) { warnOnceIfDebug( 'Promise debugging is enabled, to help solve errors that happen asynchronously. Some browsers will log unhandled promise rejections, in which case you can safely disable promise debugging:\n Ractive.DEBUG_PROMISES = false;' ); warnIfDebug('An error happened during rendering', { ractive: ractive }); logIfDebug(err); throw err; }); } } } } function createFragment$1(ractive, options) { if ( options === void 0 ) options = {}; if (ractive.template) { var cssIds = [].concat(ractive.constructor._cssIds || [], options.cssIds || []); return new Fragment({ owner: ractive, template: ractive.template, cssIds: cssIds }); } } function render$1(ractive, target, anchor, occupants) { // set a flag to let any transitions know that this instance is currently rendering ractive.rendering = true; var promise = runloop.start(); runloop.scheduleTask(function () { return hooks.render.fire(ractive); }, true); if (ractive.fragment.rendered) { throw new Error( 'You cannot call ractive.render() on an already rendered instance! Call ractive.unrender() first' ); } if (ractive.destroyed) { ractive.destroyed = false; ractive.fragment = createFragment$1(ractive).bind(ractive.viewmodel); } anchor = getElement(anchor) || ractive.anchor; ractive.el = ractive.target = target; ractive.anchor = anchor; // ensure encapsulated CSS is up-to-date if (ractive.cssId) { applyCSS(); } if (target) { (target.__ractive_instances__ || (target.__ractive_instances__ = [])).push(ractive); if (anchor) { var docFrag = doc.createDocumentFragment(); ractive.fragment.render(docFrag); target.insertBefore(docFrag, anchor); } else { ractive.fragment.render(target, occupants); } } runloop.end(); ractive.rendering = false; return promise.then(function () { if (ractive.torndown) { return; } hooks.complete.fire(ractive); }); } function Ractive$render(target, anchor) { if (this.torndown) { warnIfDebug('ractive.render() was called on a Ractive instance that was already torn down'); return Promise.resolve(); } target = getElement(target) || this.el; if (!this.append && target) { // Teardown any existing instances *before* trying to set up the new one - // avoids certain weird bugs var others = target.__ractive_instances__; if (others) { others.forEach(teardown); } // make sure we are the only occupants if (!this.enhance) { target.innerHTML = ''; // TODO is this quicker than removeChild? Initial research inconclusive } } var occupants = this.enhance ? toArray(target.childNodes) : null; var promise = render$1(this, target, anchor, occupants); if (occupants) { while (occupants.length) { target.removeChild(occupants.pop()); } } return promise; } var shouldRerender = ['template', 'partials', 'components', 'decorators', 'events']; function Ractive$reset(data) { data = data || {}; if (!isObjectType(data)) { throw new Error('The reset method takes either no arguments, or an object containing new data'); } // TEMP need to tidy this up data = dataConfigurator.init(this.constructor, this, { data: data }); var promise = runloop.start(); // If the root object is wrapped, try and use the wrapper's reset value var wrapper = this.viewmodel.wrapper; if (wrapper && wrapper.reset) { if (wrapper.reset(data) === false) { // reset was rejected, we need to replace the object this.viewmodel.set(data); } } else { this.viewmodel.set(data); } // reset config items and track if need to rerender var changes = config.reset(this); var rerender; var i = changes.length; while (i--) { if (shouldRerender.indexOf(changes[i]) > -1) { rerender = true; break; } } if (rerender) { hooks.unrender.fire(this); this.fragment.resetTemplate(this.template); hooks.render.fire(this); hooks.complete.fire(this); } runloop.end(); hooks.reset.fire(this, data); return promise; } function collect$1(source, name, attr, dest) { source.forEach(function (item) { // queue to rerender if the item is a partial and the current name matches if (item.type === PARTIAL && (item.refName === name || item.name === name)) { item.inAttribute = attr; dest.push(item); return; // go no further } // if it has a fragment, process its items if (item.fragment) { collect$1(item.fragment.iterations || item.fragment.items, name, attr, dest); } else if (isArray(item.items)) { // or if it is itself a fragment, process its items collect$1(item.items, name, attr, dest); } else if (item.type === COMPONENT && item.instance) { // or if it is a component, step in and process its items // ...unless the partial is shadowed if (item.instance.partials[name]) { return; } collect$1(item.instance.fragment.items, name, attr, dest); } // if the item is an element, process its attributes too if (item.type === ELEMENT) { if (isArray(item.attributes)) { collect$1(item.attributes, name, true, dest); } } }); } function resetPartial(name, partial) { var collection = []; collect$1(this.fragment.items, name, false, collection); var promise = runloop.start(); this.partials[name] = partial; collection.forEach(handleChange); runloop.end(); return promise; } // TODO should resetTemplate be asynchronous? i.e. should it be a case // of outro, update template, intro? I reckon probably not, since that // could be achieved with unrender-resetTemplate-render. Also, it should // conceptually be similar to resetPartial, which couldn't be async function Ractive$resetTemplate(template) { templateConfigurator.init(null, this, { template: template }); var transitionsEnabled = this.transitionsEnabled; this.transitionsEnabled = false; // Is this is a component, we need to set the `shouldDestroy` // flag, otherwise it will assume by default that a parent node // will be detached, and therefore it doesn't need to bother // detaching its own nodes var component = this.component; if (component) { component.shouldDestroy = true; } this.unrender(); if (component) { component.shouldDestroy = false; } var promise = runloop.start(); // remove existing fragment and create new one this.fragment.unbind().unrender(true); this.fragment = new Fragment({ template: this.template, root: this, owner: this }); var docFrag = createDocumentFragment(); this.fragment.bind(this.viewmodel).render(docFrag); // if this is a component, its el may not be valid, so find a // target based on the component container if (component && !component.external) { this.fragment.findParentNode().insertBefore(docFrag, component.findNextNode()); } else { this.el.insertBefore(docFrag, this.anchor); } runloop.end(); this.transitionsEnabled = transitionsEnabled; return promise; } var reverse = makeArrayMethod('reverse').path; function Ractive$set(keypath, value, options) { var ractive = this; var opts = isObjectType(keypath) ? value : options; return set(build(ractive, keypath, value, opts && opts.isolated), opts); } var shift = makeArrayMethod('shift').path; var sort = makeArrayMethod('sort').path; var splice = makeArrayMethod('splice').path; function Ractive$subtract(keypath, d, options) { var num = isNumber(d) ? -d : -1; var opts = isObjectType(d) ? d : options; return add(this, keypath, num, opts); } function Ractive$toggle(keypath, options) { if (!isString(keypath)) { throw new TypeError(badArguments); } return set( gather(this, keypath, null, options && options.isolated).map(function (m) { return [m, !m.get()]; }), options ); } function Ractive$toCSS() { var cssIds = [this.cssId ].concat( this.findAllComponents().map(function (c) { return c.cssId; })); var uniqueCssIds = keys(cssIds.reduce(function (ids, id) { return (ids[id] = true, ids); }, {})); return getCSS(uniqueCssIds); } function Ractive$toHTML() { return this.fragment.toString(true); } function toText() { return this.fragment.toString(false); } function Ractive$transition(name, node, params) { if (node instanceof HTMLElement) { // good to go } else if (isObject(node)) { // omitted, use event node params = node; } // if we allow query selector, then it won't work // simple params like "fast" // else if ( typeof node === 'string' ) { // // query selector // node = this.find( node ) // } node = node || this.event.node; if (!node || !node._ractive) { fatal(("No node was supplied for transition " + name)); } params = params || {}; var owner = node._ractive.proxy; var transition = new Transition({ owner: owner, up: owner.up, name: name, params: params }); transition.bind(); var promise = runloop.start(); runloop.registerTransition(transition); runloop.end(); promise.then(function () { return transition.unbind(); }); return promise; } function unlink(here) { var promise = runloop.start(); this.viewmodel.joinAll(splitKeypath(here), { lastLink: false }).unlink(); runloop.end(); return promise; } function Ractive$unrender() { if (!this.fragment.rendered) { warnIfDebug('ractive.unrender() was called on a Ractive instance that was not rendered'); return Promise.resolve(); } this.unrendering = true; var promise = runloop.start(); hooks.unrendering.fire(this); // If this is a component, and the component isn't marked for destruction, // don't detach nodes from the DOM unnecessarily var shouldDestroy = !this.component || (this.component.anchor || {}).shouldDestroy || this.component.shouldDestroy || this.shouldDestroy; this.fragment.unrender(shouldDestroy); if (shouldDestroy) { this.destroyed = true; } removeFromArray(this.el.__ractive_instances__, this); hooks.unrender.fire(this); runloop.end(); this.unrendering = false; return promise; } var unshift = makeArrayMethod('unshift').path; function Ractive$updateModel(keypath, cascade) { var promise = runloop.start(); if (!keypath) { this.viewmodel.updateFromBindings(true); } else { this.viewmodel.joinAll(splitKeypath(keypath)).updateFromBindings(cascade !== false); } runloop.end(); return promise; } function use() { var this$1 = this; var plugins = [], len = arguments.length; while ( len-- ) plugins[ len ] = arguments[ len ]; plugins.forEach(function (p) { p({ proto: this$1, Ractive: this$1.constructor.Ractive, instance: this$1 }); }); return this; } var proto$9 = { add: Ractive$add, animate: Ractive$animate, attachChild: attachChild, compute: Ractive$compute, detach: Ractive$detach, detachChild: detachChild, find: Ractive$find, findAll: Ractive$findAll, findAllComponents: Ractive$findAllComponents, findComponent: Ractive$findComponent, findContainer: Ractive$findContainer, findParent: Ractive$findParent, fire: Ractive$fire, get: Ractive$get, getContext: getContext$2, insert: Ractive$insert, link: link, observe: observe, observeOnce: observeOnce, off: Ractive$off, on: Ractive$on, once: Ractive$once, pop: pop, push: push, readLink: readLink, render: Ractive$render, reset: Ractive$reset, resetPartial: resetPartial, resetTemplate: Ractive$resetTemplate, reverse: reverse, set: Ractive$set, shift: shift, sort: sort, splice: splice, subtract: Ractive$subtract, teardown: Ractive$teardown, toggle: Ractive$toggle, toCSS: Ractive$toCSS, toCss: Ractive$toCSS, toHTML: Ractive$toHTML, toHtml: Ractive$toHTML, toText: toText, transition: Ractive$transition, unlink: unlink, unrender: Ractive$unrender, unshift: unshift, update: Ractive$update, updateModel: Ractive$updateModel, use: use }; function isInstance(object) { return object && object instanceof this; } function styleGet(keypath, opts) { return this._cssModel.joinAll(splitKeypath(keypath)).get(true, opts); } var styles = []; function addStyle(id, css) { if (styles.find(function (s) { return s.id === id; })) { throw new Error(("Extra styles with the id '" + id + "' have already been added.")); } styles.push({ id: id, css: css }); if (!this.css) { Object.defineProperty(this, 'css', { configurable: false, writable: false, value: buildCSS }); } if (!this._cssDef) { Object.defineProperty(this, '_cssDef', { configurable: true, writable: false, value: { transform: false, id: 'Ractive.addStyle' } }); addCSS(this._cssDef); } recomputeCSS(this); applyCSS(true); } function buildCSS(data) { return styles .map(function (s) { return "\n/* ---- extra style " + (s.id) + " */\n" + (isFunction(s.css) ? s.css(data) : s.css); }) .join(''); } function hasStyle(id) { return !!styles.find(function (s) { return s.id === id; }); } function sharedSet(keypath, value, options) { var opts = isObjectType(keypath) ? value : options; var model = SharedModel$1; return set(build({ viewmodel: model }, keypath, value, true), opts); } function sharedGet(keypath, opts) { return SharedModel$1.joinAll(splitKeypath(keypath)).get(true, opts); } function use$1() { var this$1 = this; var plugins = [], len = arguments.length; while ( len-- ) plugins[ len ] = arguments[ len ]; plugins.forEach(function (p) { isFunction(p) && p({ proto: this$1.prototype, Ractive: this$1.Ractive, instance: this$1 }); }); return this; } var callsSuper = /super\s*\(|\.call\s*\(\s*this/; function extend() { var options = [], len = arguments.length; while ( len-- ) options[ len ] = arguments[ len ]; if (!options.length) { return extendOne(this); } else { return options.reduce(extendOne, this); } } function extendWith(Class, options) { if ( options === void 0 ) options = {}; return extendOne(this, options, Class); } function extendOne(Parent, options, Target) { if ( options === void 0 ) options = {}; var proto; var Child = isFunction(Target) && Target; if (options.prototype instanceof Ractive) { throw new Error("Ractive no longer supports multiple inheritance."); } if (Child) { if (!(Child.prototype instanceof Parent)) { throw new Error( "Only classes that inherit the appropriate prototype may be used with extend" ); } if (!callsSuper.test(Child.toString())) { throw new Error("Only classes that call super in their constructor may be used with extend"); } proto = Child.prototype; } else { Child = function(options) { if (!(this instanceof Child)) { return new Child(options); } construct(this, options || {}); initialise(this, options || {}, {}); }; proto = create(Parent.prototype); proto.constructor = Child; Child.prototype = proto; } // Static properties defineProperties(Child, { // alias prototype as defaults defaults: { value: proto }, extend: { value: extend, writable: true, configurable: true }, extendWith: { value: extendWith, writable: true, configurable: true }, extensions: { value: [] }, use: { value: use$1 }, isInstance: { value: isInstance }, Parent: { value: Parent }, Ractive: { value: Ractive }, styleGet: { value: styleGet.bind(Child), configurable: true }, styleSet: { value: setCSSData.bind(Child), configurable: true } }); // extend configuration config.extend(Parent, proto, options, Child); // store event and observer registries on the constructor when extending Child._on = (Parent._on || []).concat(toPairs(options.on)); Child._observe = (Parent._observe || []).concat(toPairs(options.observe)); Parent.extensions.push(Child); // attribute defs are not inherited, but they need to be stored if (options.attributes) { var attrs; // allow an array of optional props or an object with arrays for optional and required props if (isArray(options.attributes)) { attrs = { optional: options.attributes, required: [] }; } else { attrs = options.attributes; } // make sure the requisite keys actually store arrays if (!isArray(attrs.required)) { attrs.required = []; } if (!isArray(attrs.optional)) { attrs.optional = []; } Child.attributes = attrs; } dataConfigurator.extend(Parent, proto, options, Child); defineProperty(Child, 'helpers', { writable: true, value: proto.helpers }); if (isArray(options.use)) { Child.use.apply(Child, options.use); } return Child; } defineProperties(Ractive, { sharedGet: { value: sharedGet }, sharedSet: { value: sharedSet }, styleGet: { configurable: true, value: styleGet.bind(Ractive) }, styleSet: { configurable: true, value: setCSSData.bind(Ractive) }, addCSS: { configurable: false, value: addStyle.bind(Ractive) }, hasCSS: { configurable: false, value: hasStyle.bind(Ractive) } }); function macro(fn, opts) { if (!isFunction(fn)) { throw new Error("The macro must be a function"); } assign(fn, opts); defineProperties(fn, { extensions: { value: [] }, _cssIds: { value: [] }, cssData: { value: assign(create(this.cssData), fn.cssData || {}) }, styleGet: { value: styleGet.bind(fn) }, styleSet: { value: setCSSData.bind(fn) } }); defineProperty(fn, '_cssModel', { value: new CSSModel(fn) }); if (fn.css) { initCSS(fn, fn, fn); } this.extensions.push(fn); return fn; } function joinKeys() { var keys = [], len = arguments.length; while ( len-- ) keys[ len ] = arguments[ len ]; return keys.map(escapeKey).join('.'); } function splitKeypath$1(keypath) { return splitKeypath(keypath).map(unescapeKey); } function findPlugin(name, type, instance) { return findInViewHierarchy(type, instance, name); } function Ractive(options) { if (!(this instanceof Ractive)) { return new Ractive(options); } construct(this, options || {}); initialise(this, options || {}, {}); } // check to see if we're being asked to force Ractive as a global for some weird environments if (win && !win.Ractive) { var opts$1 = ''; var script = document.currentScript || /* istanbul ignore next */ document.querySelector('script[data-ractive-options]'); if (script) { opts$1 = script.getAttribute('data-ractive-options') || ''; } /* istanbul ignore next */ if (~opts$1.indexOf('ForceGlobal')) { win.Ractive = Ractive; } } else if (win) { warn("Ractive already appears to be loaded while loading 1.3.0."); } assign(Ractive.prototype, proto$9, defaults); Ractive.prototype.constructor = Ractive; // alias prototype as `defaults` Ractive.defaults = Ractive.prototype; // share defaults with the parser shared.defaults = Ractive.defaults; shared.Ractive = Ractive; // static properties defineProperties(Ractive, { // debug flag DEBUG: { writable: true, value: true }, DEBUG_PROMISES: { writable: true, value: true }, // static methods: extend: { value: extend }, extendWith: { value: extendWith }, escapeKey: { value: escapeKey }, evalObjectString: { value: parseJSON }, findPlugin: { value: findPlugin }, getContext: { value: getContext$1 }, getCSS: { value: getCSS }, isInstance: { value: isInstance }, joinKeys: { value: joinKeys }, macro: { value: macro }, normaliseKeypath: { value: normalise }, parse: { value: parse }, splitKeypath: { value: splitKeypath$1 }, // sharedSet and styleSet are in _extend because circular refs unescapeKey: { value: unescapeKey }, use: { value: use$1 }, // support enhance: { writable: true, value: false }, svg: { value: svg }, // version VERSION: { value: '1.3.0' }, // plugins adaptors: { writable: true, value: {} }, components: { writable: true, value: {} }, decorators: { writable: true, value: {} }, easing: { writable: true, value: easing }, events: { writable: true, value: {} }, extensions: { value: [] }, helpers: { writable: true, value: defaults.helpers }, interpolators: { writable: true, value: interpolators }, partials: { writable: true, value: {} }, transitions: { writable: true, value: {} }, // CSS variables cssData: { configurable: true, value: {} }, // access to @shared without an instance sharedData: { value: data }, // for getting the source Ractive lib from a constructor Ractive: { value: Ractive }, // to allow extending contexts Context: { value: extern.Context.prototype } }); // cssData must already be in place defineProperty(Ractive, '_cssModel', { configurable: true, value: new CSSModel(Ractive) }); defineProperty(Ractive.prototype, 'rendered', { get: function get() { return this.fragment && this.fragment.rendered; } }); return Ractive; }))); //# sourceMappingURL=ractive.js.map
{ "content_hash": "bd6008d22a09b211304e67e8b1b64645", "timestamp": "", "source": "github", "line_count": 19196, "max_line_length": 667, "avg_line_length": 26.529693686184622, "alnum_prop": 0.6155314335982909, "repo_name": "cdnjs/cdnjs", "id": "89070268cceb888fb119236c2a9f4c29d30484fe", "size": "509270", "binary": false, "copies": "4", "ref": "refs/heads/master", "path": "ajax/libs/ractive/1.3.0/ractive.js", "mode": "33188", "license": "mit", "language": [], "symlink_target": "" }
using System; using System.Collections.Generic; using System.Text; namespace NAudio.Utils { class MergeSort { /// <summary> /// In-place and stable implementation of MergeSort /// </summary> static void Sort<T>(IList<T> list, int lowIndex, int highIndex, IComparer<T> comparer) { if (lowIndex >= highIndex) { return; } int midIndex = (lowIndex + highIndex) / 2; // Partition the list into two lists and Sort them recursively Sort(list, lowIndex, midIndex, comparer); Sort(list, midIndex + 1, highIndex, comparer); // Merge the two sorted lists int endLow = midIndex; int startHigh = midIndex + 1; while ((lowIndex <= endLow) && (startHigh <= highIndex)) { // MRH, if use < 0 sort is not stable if (comparer.Compare(list[lowIndex], list[startHigh]) <= 0) { lowIndex++; } else { // list[lowIndex] > list[startHigh] // The next element comes from the second list, // move the list[start_hi] element into the next // position and shuffle all the other elements up. T t = list[startHigh]; for (int k = startHigh - 1; k >= lowIndex; k--) { list[k + 1] = list[k]; } list[lowIndex] = t; lowIndex++; endLow++; startHigh++; } } } /// <summary> /// MergeSort a list of comparable items /// </summary> public static void Sort<T>(IList<T> list) where T : IComparable<T> { Sort(list, 0, list.Count - 1, Comparer<T>.Default); } /// <summary> /// MergeSort a list /// </summary> public static void Sort<T>(IList<T> list, IComparer<T> comparer) { Sort(list, 0, list.Count - 1, comparer); } } }
{ "content_hash": "1765da58eee12abc350a57627e801117", "timestamp": "", "source": "github", "line_count": 76, "max_line_length": 94, "avg_line_length": 29.486842105263158, "alnum_prop": 0.4524765729585007, "repo_name": "Aragas/VKPlayer", "id": "421b315268a9bd27363b99092d5461861881b890", "size": "2241", "binary": false, "copies": "7", "ref": "refs/heads/master", "path": "VKPlayer/NAudio/Utils/MergeSort.cs", "mode": "33188", "license": "mit", "language": [ { "name": "C#", "bytes": "1109323" } ], "symlink_target": "" }
import java.util.concurrent.*; public class EvenChecker implements Runnable { private IntGenerator generator; private final int id; public EvenChecker(IntGenerator g, int ident) { generator = g; id = ident; } public void run() { while(!generator.isCanceled()) { int val = generator.next(); if(val % 2 != 0) { System.out.println(val + " not even!"); generator.cancel(); // Cancels all EvenCheckers } } } // Test any type of IntGenerator: public static void test(IntGenerator gp, int count) { System.out.println("Press Control-C to exit"); ExecutorService exec = Executors.newCachedThreadPool(); for(int i = 0; i < count; i++) exec.execute(new EvenChecker(gp, i)); exec.shutdown(); } // Default value for count: public static void test(IntGenerator gp) { test(gp, 10); } } ///:~
{ "content_hash": "56769d79fb806b13c21404e4add3df0a", "timestamp": "", "source": "github", "line_count": 31, "max_line_length": 59, "avg_line_length": 28.322580645161292, "alnum_prop": 0.6332574031890661, "repo_name": "alvachien/aclearning", "id": "c1c96e69f4bf15fbd2dccb3fa261d2bcce472c9a", "size": "911", "binary": false, "copies": "1", "ref": "refs/heads/master", "path": "languages_and_platforms/java/thinkinjava/00_lib/concurrency/EvenChecker.java", "mode": "33188", "license": "mit", "language": [ { "name": "AngelScript", "bytes": "521" }, { "name": "C++", "bytes": "2139" }, { "name": "CSS", "bytes": "169" }, { "name": "HTML", "bytes": "13081" }, { "name": "Java", "bytes": "829314" }, { "name": "Python", "bytes": "23238" }, { "name": "TypeScript", "bytes": "26902" } ], "symlink_target": "" }
from networkx import DiGraph, dijkstra_path import os.path, sys from pydispatch import dispatcher try: import xml.etree.cElementTree as ElementTree except ImportError: import xml.etree.ElementTree as ElementTree import inspect, marshal, types from object import Object from region import Region from pathway import Pathway from neuron import Neuron from neurite import Neurite from arborization import Arborization from synapse import Synapse from gap_junction import GapJunction from stimulus import Stimulus from muscle import Muscle from innervation import Innervation from attribute import Attribute try: import pydot # pylint: disable=F0401,W0611 except ImportError: pydot = None class Network: def __init__(self): """ Networks are containers for all :class:`objects <Network.Object.Object>` that exist in a neural circuit. """ self.graph = DiGraph() self.objects = [] self.idDict = {} # TODO: weak ref dict? self.displays = [] self._nextUniqueId = -1 self._savePath = None self._attributes = [] self._displaysAreSynchronized = True self._weightingFunction = None self._bulkLoading = False self._bulkAddObjects = [] self._modified = False @classmethod def _fromXMLElement(cls, xmlElement): network = cls() network.setBulkLoading(True) # Load the classes in such an order that any referenced objects are guaranteed to have already been created. for moduleName, className in [('region', 'Region'), ('pathway', 'Pathway'), ('neuron', 'Neuron'), ('muscle', 'Muscle'), ('arborization', 'Arborization'), ('innervation', 'Innervation'), ('gap_junction', 'GapJunction'), ('synapse', 'Synapse'), ('stimulus', 'Stimulus')]: elementModule = getattr(sys.modules['network'], moduleName) elementClass = getattr(elementModule, className) for element in xmlElement.findall(className): networkObject = elementClass._fromXMLElement(network, element) if networkObject is not None: network.addObject(networkObject) weightingFunctionElement = xmlElement.find('WeightingFunction') if weightingFunctionElement is not None: funcType = weightingFunctionElement.get('type') funcName = weightingFunctionElement.get('name') if funcType == 'source': exec(weightingFunctionElement.text) network._weightingFunction = eval(funcName) elif funcType == 'marshal': code = marshal.loads(eval(weightingFunctionElement.text)) network._weightingFunction = types.FunctionType(code, globals(), funcName or 'weightingFunction') else: raise ValueError, gettext('Unknown weighting function type: %s') % (funcType) for element in xmlElement.findall('Attribute'): attribute = Attribute._fromXMLElement(network, element) if attribute is not None: network._attributes.append(attribute) network.setBulkLoading(False) return network def _toXMLElement(self, parentElement): networkElement = ElementTree.SubElement(parentElement, 'Network') for networkObject in self.objects: # Nested regions are handled by their parents and neurites are handled by their neurons. if not (isinstance(networkObject, Region) and networkObject.parentRegion is not None) and not isinstance(networkObject, Neurite): objectElement = networkObject._toXMLElement(networkElement) if objectElement is None: pass # TODO: are there any cases where this is NOT an error? if self._weightingFunction: weightingFunctionElement = ElementTree.SubElement(networkElement, 'WeightingFunction') weightingFunctionElement.set('name', self._weightingFunction.func_name) # First try to get the function source and if that fails then marshal the byte code. try: source = inspect.getsource(self._weightingFunction) weightingFunctionElement.text = source weightingFunctionElement.set('type', 'source') except IOError: weightingFunctionElement.text = repr(marshal.dumps(self._weightingFunction.func_code)) weightingFunctionElement.set('type', 'marshal') for attribute in self._attributes: attribute._toXMLElement(networkElement) return networkElement def _toScriptFile(self, scriptFile, scriptRefs): if len(self._attributes) > 0: scriptFile.write(gettext('# Create the network') + '\n\n') for attribute in self._attributes: attribute._toScriptFile(scriptFile, scriptRefs) if self._weightingFunction: # First try to get the function source and if that fails then marshal the byte code. scriptFile.write(gettext('# Add the weighting function') + '\n\n') funcName = self._weightingFunction.func_name try: source = inspect.getsource(self._weightingFunction) scriptFile.write(source + '\n\nnetwork.setWeightingFunction(' + funcName + ')\n\n') except IOError: scriptFile.write('import marshal, types\n') scriptFile.write('code = marshal.loads(' + repr(marshal.dumps(self._weightingFunction.func_code)) + ')\n') scriptFile.write('network.setWeightingFunction(types.FunctionType(code, globals(), \'' + funcName + '\'))\n\n') # Add each network object to the script in an order that guarantees dependent objects will already have been added. # Neurites will be added by their neurons, sub-regions by their root region. for objectClass in (Region, Pathway, Muscle, Neuron, Arborization, GapJunction, Innervation, Synapse, Stimulus): objects = self.objectsOfClass(objectClass) if len(objects) > 0: scriptFile.write('\n# ' + gettext('Create each %s') % (objectClass.displayName().lower()) + '\n\n') for networkObject in objects: if networkObject._includeInScript(atTopLevel = True): networkObject._toScriptFile(scriptFile, scriptRefs) def setBulkLoading(self, bulkLoading): """ Indicate whether or not a large quantity of objects are being added to the network. >>> network.setBulkLoading(True) >>> # ... add lots of objects ... >>> network.setBulkLoading(False) If bulk loading is enabled then various actions are delayed to make loading faster. """ if bulkLoading != self._bulkLoading: self._bulkLoading = bulkLoading if self._bulkLoading == False: self._updateGraph() if any(self._bulkAddObjects): dispatcher.send('addition', self, affectedObjects = self._bulkAddObjects) self._bulkAddObjects = [] dispatcher.send(('set', 'bulkLoading'), self) def setSavePath(self, path): if path != self._savePath: self._savePath = path dispatcher.send(('set', 'savePath'), self) def savePath(self): return self._savePath def name(self): if self._savePath is None: return gettext('Untitled Network') else: return os.path.splitext(os.path.basename(self._savePath))[0] def _generateUniqueId(self): self._nextUniqueId += 1 return self._nextUniqueId def findObject(self, objectClass, name = None, default = False): """ Return the first object of the given class with the given name. >>> neuron = network.findObject(Neuron, 'AVAL') Returns an :class:`Object <Network.Object.Object>` or None if there are no matching objects. If default is True then each object's :meth:`defaultName() <Network.Object.Object.defaultName>` will be queried instead of its name. """ if name is not None: for networkObject in self.objects: if isinstance(networkObject, objectClass) and ((not default and networkObject.name == name) or (default and networkObject.defaultName() == name)): return networkObject return None def findObjects(self, objectClass, name = None, default = False): """ Return all objects of the given class with the given name. >>> neuron = network.findObject(Neuron, 'AVAL') Returns a list of :class:`Object <Network.Object.Object>` or None if there are no matching objects. If default is True then each object's :meth:`defaultName() <Network.Object.Object.defaultName>` will be queried instead of its name. """ objects = [] if name is not None: for networkObject in self.objects: if isinstance(networkObject, objectClass) and ((not default and networkObject.name == name) or (default and networkObject.defaultName() == name)): objects.append(networkObject) return objects if objects else None def findObjectsRegex(self, objectClass, nameRegex = None, default = False): """ Return all objects of the given class whos name matches the regular expression >>> neuron = network.findObject(Neuron, 'AVAL') Returns a list of :class:`Object <Network.Object.Object>` or None if there are no matching objects. """ from re import search matchingObjects = [] if nameRegex is not None: for networkObject in self.objects: if isinstance(networkObject, objectClass) and ((not default and search(nameRegex, networkObject.name)) or (default and search(nameRegex, networkObject.defaultName()))): matchingObjects.append(networkObject) return matchingObjects if matchingObjects else None def createRegion(self, addSubTerms = False, *args, **keywordArgs): """ Create a new region optionally associated with an ontology term. >>> region = network.createRegion(name = 'Glomerulus 2') To associate the region with an ontology term pass in a term from an ontology in the library: >>> flyBrainOnt = library.ontology('flybrain') >>> ellipsoidBody = network.createRegion(ontologyTerm = flyBrainOnt.findTerm(name = 'Ellipsoid body')) If addSubTerms is true then sub-regions will be created for all sub-terms in the ontology. Returns the :class:`region <Network.Region.Region>` that is created. """ region = Region(self, *args, **keywordArgs) self.addObject(region) if region.ontologyTerm is not None and addSubTerms: for term in region.ontologyTerm.parts: self.createRegion(ontologyTerm = term, parentRegion = region, addSubTerms = True) return region def findRegion(self, name = None): """ Find the first region with the given name. >>> region = network.findRegion('Ellipsoid body') Returns a :class:`region <Network.Region.Region>` or None if there are no regions with the name. """ return self.findObject(Region, name) def regions(self): """ Return a list of all :class:`regions <Network.Region.Region>` in the network. >>> for region in network.regions(): ... display.setVisibleColor(region, (1.0, 0.0, 0.0)) An empty list will be returned if there are no regions in the network. """ return self.objectsOfClass(Region) def pathways(self): """ Return a list of all :class:`pathways <Network.Pathway.Pathway>` in the network. >>> for pathway in network.pathways(): ... display.setVisibleColor(pathway, (1.0, 0.0, 0.0)) An empty list will be returned if there are no pathways in the network. """ return self.objectsOfClass(Pathway) def createNeuron(self, *args, **keywordArgs): """ Create a new neuron. >>> neuron = network.createNeuron(name = 'AVAL') Returns the :class:`neuron <Network.Neuron.Neuron>` that is created. """ neuron = Neuron(self, *args, **keywordArgs) self.addObject(neuron) return neuron def findNeuron(self, name = None): """ Find the first neuron with the given name. >>> neuron = network.findNeuron('AVAL') Returns a :class:`neuron <Network.Neuron.Neuron>` or None if there are no neurons with the name. """ return self.findObject(Neuron, name) def neurons(self): """ Return a list of all :class:`neurons <Network.Neuron.Neuron>` in the network. >>> for neuron in network.neurons(): ... neuron.setHasFunction(Neuron.Function.SENSORY, False) An empty list will be returned if there are no neurons in the network. """ return self.objectsOfClass(Neuron) def neurites(self): """ Return a list of all :class:`neurites <Network.Neurite.Neurite>` in the network. >>> for neurite in network.neurites(): ... neurite.setPathway(None) An empty list will be returned if there are no neurites in the network. """ return self.objectsOfClass(Neurite) def arborizations(self): """ Return a list of all :class:`arborizations <Network.Arborization.Arborization>` in the network. >>> for arborization in network.arborizations(): ... display.setVisibleShape(arborization, shapes['Cone']) An empty list will be returned if there are no arborizations in the network. """ return self.objectsOfClass(Arborization) def gapJunctions(self): """ Return a list of all :class:`gap junctions <Network.GapJunction.GapJunction>` in the network. >>> for gapJunction in network.gapJunctions(): ... display.setVisibleColor(gapJunction, (0, 0, 0)) An empty list will be returned if there are no gap junctions in the network. """ return self.objectsOfClass(GapJunction) def innervations(self): """ Return a list of all :class:`innervations <Network.Innervation.Innervation>` in the network. >>> for innervation in network.innervations(): ... display.setVisibleWeight(innervation, 2.0) An empty list will be returned if there are no innervations in the network. """ return self.objectsOfClass(Innervation) def synapses(self): """ Return a list of all :class:`chemical synapses <Network.Synapse.Synapse>` in the network. >>> for synapse in network.synapses(): ... synapse.activation = None An empty list will be returned if there are no chemical synapses in the network. """ return self.objectsOfClass(Synapse) def createStimulus(self, *args, **keywordArgs): """ Create a new stimulus. DEPRECATED: Call :meth:`stimulate() <Network.Object.Object.stimulate>` on the desired target object instead. >>> stimulus = network.createStimulus(target = neuron1, modality = library.modality('light')) Returns the :class:`stimulus <Network.Stimulus.Stimulus>` that is created. """ target = keywordArgs['target'] del keywordArgs['target'] return target.stimulate(*args, **keywordArgs) def findStimulus(self, name = None): """ Find the first stimulus with the given name. >>> stimulus = network.findStimulus('Light') Returns a :class:`stimulus <Network.Stimulus.Stimulus>` or None if there are no stimuli with the name. """ return self.findObject(Stimulus, name) def stimuli(self): """ Return a list of all :class:`stimuli <Network.Stimulus.Stimulus>` in the network. >>> for stimulus in network.stimuli(): ... if stimulus.modality == library.modality('light'): ... display.setVisibleColor(stimulus, (1, 1, 1)) An empty list will be returned if there are no stimuli in the network. """ return self.objectsOfClass(Stimulus) def createMuscle(self, *args, **keywordArgs): """ Create a new muscle. >>> muscle = network.createMuscle(name = 'M1') Returns the :class:`muscle <Network.Muscle.Muscle>` that is created. """ muscle = Muscle(self, *args, **keywordArgs) self.addObject(muscle) return muscle def findMuscle(self, name = None): """ Find the first muscle with the given name. >>> muscle = network.findMuscle('M1') Returns a :class:`muscle <Network.Muscle.Muscle>` or None if there are no muscles with the name. """ return self.findObject(Muscle, name) def muscles(self): """ Return a list of all :class:`muscles <Network.Muscle.Muscle>` in the network. >>> for muscle in network.muscles(): ... display.setVisibleOpacity(muscle, 0.5) An empty list will be returned if there are no muscles in the network. """ return self.objectsOfClass(Muscle) def _updateGraph(self, objectToUpdate = None): if objectToUpdate is None: # Rebuild the entire graph. objectsToUpdate = self.objects self.graph.clear() else: # Just rebuild the connections to the one object. objectsToUpdate = [objectToUpdate] # Remove the object if it was there before. This will also delete any edges from the node. objectId = objectToUpdate.networkId if objectId in self.graph: self.graph.remove_node(objectId) # Maintain a temporary cache of weights so that rebuilding the whole graph doesn't take so long. objectWeights = {} def weightOfObject(weightedObject): if weightedObject.networkId in objectWeights: objectWeight = objectWeights[weightedObject.networkId] else: objectWeight = self.weightOfObject(weightedObject) objectWeights[weightedObject.networkId] = objectWeight return objectWeight for objectToUpdate in objectsToUpdate: objectId = objectToUpdate.networkId # (Re-)Add the object to the graph. self.graph.add_node(objectId) # Get the weight of this object. objectWeight = weightOfObject(objectToUpdate) # Add the connections to other objects already in the graph. # (Each connection to an object not in the graph will be added when that object is added.) # The weight of each edge is the average of the weights of the two objects it connects. inputIds = set([objectInput.networkId for objectInput in objectToUpdate.inputs(recurse = False)]) outputIds = set([objectOutput.networkId for objectOutput in objectToUpdate.outputs(recurse = False)]) unknownIds = set([objectInput.networkId for objectInput in objectToUpdate.connections(recurse = False)]).difference(inputIds).difference(outputIds) for inputId in inputIds.union(unknownIds): if inputId in self.graph: otherWeight = weightOfObject(objectToUpdate) self.graph.add_edge(inputId, objectId, weight = (objectWeight + otherWeight) / 2.0) for outputId in outputIds.union(unknownIds): if outputId in self.graph: otherWeight = weightOfObject(objectToUpdate) self.graph.add_edge(objectId, outputId, weight = (objectWeight + otherWeight) / 2.0) def _objectChanged(self, sender): if not self._bulkLoading: self._updateGraph(sender) if not self._modified: self._modified = True dispatcher.send(('set', 'modified'), self) def simplifiedGraph(self): """ Return a simplified version of the NetworkX representation of the network. This version of the network will have far fewer nodes but will not accurately model edges with more than two end points (hyperedges). This speeds processing when using NetworkX's algorithms. """ def addEdge(graph, object1, object2, weight): node1 = object1.networkId node2 = object2.networkId if node1 in graph and node2 in graph[node1]: if weight < graph[node1][node2]['weight']: # Use a smaller weight for an existing edge. graph[node1][node2]['weight'] = weight else: # Create a new edge. graph.add_edge(node1, node2, weight = weight) simplifiedGraph = DiGraph() # In self.graph edges are actually nodes to support hyperedges. Convert these to standard edges in the simplified graph. # TODO: make this object type independent for arborization in self.arborizations(): if arborization.sendsOutput: addEdge(simplifiedGraph, arborization.neurite.neuron(), arborization.region, self.weightOfObject(arborization)) if arborization.receivesInput: addEdge(simplifiedGraph, arborization.region, arborization.neurite.neuron(), self.weightOfObject(arborization)) for synapse in self.synapses(): for postPartner in synapse.postSynapticPartners: if isinstance(postPartner, Neurite): postPartner = postPartner.neuron() addEdge(simplifiedGraph, synapse.preSynapticNeurite.neuron(), postPartner, self.weightOfObject(synapse)) for gapJunction in self.gapJunctions(): neurites = gapJunction.neurites() addEdge(simplifiedGraph, neurites[0].neuron(), neurites[1].neuron(), self.weightOfObject(gapJunction)) addEdge(simplifiedGraph, neurites[1].neuron(), neurites[0].neuron(), self.weightOfObject(gapJunction)) for innervation in self.innervations(): addEdge(simplifiedGraph, innervation.neurite.neuron(), innervation.muscle, self.weightOfObject(innervation)) for pathway in self.pathways(): region1, region2 = pathway.regions() weight = self.weightOfObject(pathway) if pathway.region1Projects: addEdge(simplifiedGraph, region1, region2, weight) if pathway.region2Projects: addEdge(simplifiedGraph, region2, region1, weight) for stimulus in self.stimuli(): addEdge(simplifiedGraph, stimulus, stimulus.target.rootObject(), self.weightOfObject(stimulus)) return simplifiedGraph def setModified(self, modified): """ Set whether or not this network is dirty and needs to be saved. """ if self._modified != modified: self._modified = modified dispatcher.send(('set', 'modified'), self) def isModified(self): """ Return whether the network has been modified and needs to be saved. """ return self._modified def addObject(self, objectToAdd): if objectToAdd.networkId in self.idDict: raise ValueError, gettext('All objects in a network must have unique identifiers.') self.objects.append(objectToAdd) self.idDict[objectToAdd.networkId] = objectToAdd if objectToAdd.networkId > self._nextUniqueId: self._nextUniqueId = objectToAdd.networkId # Update the NetworkX graph representation of the object and its connections. if not self._bulkLoading: self._updateGraph(objectToAdd) # Watch for any changes to the object so we can update our dirty state and the graph. dispatcher.connect(self._objectChanged, dispatcher.Any, objectToAdd) # Let anyone who cares know that the network was changed. if self._bulkLoading: self._bulkAddObjects += [objectToAdd] else: dispatcher.send('addition', self, affectedObjects = [objectToAdd]) def objectWithId(self, objectId): if (isinstance(objectId, str) or isinstance(objectId, unicode)) and objectId.isdigit(): objectId = int(objectId) return self.idDict[objectId] if objectId in self.idDict else None def objectsOfClass(self, objectClass): objects = [] for networkObject in self.objects: if isinstance(networkObject, objectClass): objects.append(networkObject) return objects def setWeightingFunction(self, weightingFunction = None): """ Set a function to be used to calculate the weight of objects in the network. The function should accept a single argument (an :class:`object <network.object.Object>` in the network) and return a floating point value indicating the weight of the object. An object with a higher weight is considered more expensive to traverse. """ if weightingFunction is not None and not callable(weightingFunction): raise ValueError, gettext('The function passed to setWeightingFunction must be callable.') if weightingFunction != self._weightingFunction: self._weightingFunction = weightingFunction self._updateGraph() dispatcher.send(('set', 'weightingFunction'), self) def weightingFunction(self): """ Return the function being used to calculate the weights of objects in the network. If no function has been set then None will be returned. """ return self._weightingFunction def weightOfObject(self, weightedObject): """ Return the weight of the indicated object or 1.0 if no weighting function has been set. """ return 1.0 if not self._weightingFunction else self._weightingFunction(weightedObject) def shortestPath(self, startObject, endObject): """ Return one of the shortest paths through the :class:`network <Network.Network.Network>` from the first object to the second. Returns a list of objects in the path from the first object to the second. If the second object cannot be reached from the first then an empty list will be returned. """ if not isinstance(startObject, Object) or startObject.network != self or not isinstance(endObject, Object) or endObject.network != self: raise ValueError, 'The objects passed to shortestPath() must be from the same network.' path = [] try: nodeList = dijkstra_path(self.graph, startObject.networkId, endObject.networkId) except: nodeList = [] for nodeID in nodeList: pathObject = self.objectWithId(nodeID) if pathObject is not startObject: path.append(pathObject) return path def removeObject(self, networkObject): """ Remove the indicated object and any dependent objects from the network and any displays. >>> network.removeObject(network.findNeuron('AVAL')) """ if networkObject in self.objects: # Determine all of the objects that will need to be removed objectsToRemove = set([networkObject]) objectsToInspect = [networkObject] while any(objectsToInspect): objectToInspect = objectsToInspect.pop(0) dependentObjects = set(objectToInspect.dependentObjects()) objectsToInspect += list(dependentObjects.difference(objectsToRemove)) objectsToRemove = objectsToRemove.union(dependentObjects) # Remove all of the objects. for objectToRemove in objectsToRemove: objectToRemove.disconnectFromNetwork() self.objects.remove(objectToRemove) del self.idDict[objectToRemove.networkId] # Keep the NetworkX graph in sync. if objectToRemove.networkId in self.graph: self.graph.remove_node(objectToRemove.networkId) # Let anyone who cares know that the network was changed. dispatcher.send('deletion', self, affectedObjects = objectsToRemove) def removeAllObjects(self): """ Remove all objects from the network and any displays. """ removedObjects = list(self.objects) for networkObject in self.objects: networkObject.network = None self.objects = [] self.idDict = {} self.graph.clear() # Let anyone who cares know that the network was changed. dispatcher.send('deletion', self, affectedObjects = removedObjects) def addDisplay(self, display): self.displays.append(display) dispatcher.connect(self._synchronizeDisplays, ('set', 'selection'), display) def removeDisplay(self, display): self.displays.remove(display) dispatcher.disconnect(self._synchronizeDisplays, ('set', 'selection'), display) def setSynchronizeDisplays(self, synchronize): if synchronize != self._displaysAreSynchronized: self._displaysAreSynchronized = synchronize if synchronize and any(self.displays): self._synchronizeDisplays(None, self.displays[0]) def _synchronizeDisplays(self, sender): if self._displaysAreSynchronized: selection = sender.selectedObjects() for display in self.displays: if display != sender: display.selectObjects(selection) def addAttribute(self, name = None, type = None, value = None): # pylint: disable=W0622 """ Add a user-defined attribute to this network. >>> network.addAttribute('Preliminary', Attribute.BOOLEAN_TYPE, True) The type parameter should be one of the :class:`Attribute.*_TYPE <Network.Attribute.Attribute>` values. Returns the attribute object that is created. """ if name is None or type is None or value is None: raise ValueError, gettext('The name, type and value parameters must be specified when adding an attribute.') if not isinstance(name, str): raise TypeError, 'The name parameter passed to addAttribute() must be a string.' if type not in Attribute.TYPES: raise TypeError, 'The type parameter passed to addAttribute() must be one of the Attribute.*_TYPE values.' # TODO: validate value based on the type? attribute = Attribute(self, name, type, value) self._attributes.append(attribute) dispatcher.send(('set', 'attributes'), self) return attribute def getAttribute(self, name): """ Return the first user-defined :class:`attribute <Network.Attribute.Attribute>` of this network with the given name or None if there is no matching attribute. >>> creationDate = network.getAttribute('Creation Date').value() """ for attribute in self._attributes: if attribute.name() == name: return attribute return None def getAttributes(self, name = None): """ Return a list of all user-defined :class:`attributes <Network.Attribute.Attribute>` of this network or only those with the given name. >>> reviewers = [reviewer.value() for reviewer in network.getAttributes('Reviewed By')] If there are no attributes then an empty list will be returned. """ attributes = [] for attribute in self._attributes: if name == None or attribute.name() == name: attributes += [attribute] return attributes def removeAttribute(self, attribute): """ Remove the given attribute from the network. """ if not isinstance(attribute, Attribute) or not attribute in self._attributes: raise ValueError, 'The attribute passed to removeAttribute() must be an existing attribute of the network.' self._attributes.remove(attribute) dispatcher.send(('set', 'attributes'), self)
{ "content_hash": "d5309f19709174d67aef448b7c6b0057", "timestamp": "", "source": "github", "line_count": 849, "max_line_length": 277, "avg_line_length": 40.266195524146056, "alnum_prop": 0.6073538875563096, "repo_name": "JaneliaSciComp/Neuroptikon", "id": "10775cd86e4868857ba068762b04488d45cbcaf4", "size": "34416", "binary": false, "copies": "1", "ref": "refs/heads/master", "path": "Source/network/network.py", "mode": "33188", "license": "bsd-3-clause", "language": [ { "name": "GLSL", "bytes": "3048" }, { "name": "HTML", "bytes": "97998" }, { "name": "Inno Setup", "bytes": "2349" }, { "name": "Python", "bytes": "8142986" } ], "symlink_target": "" }
\begin{myex} La droite d'ajustement obtenue grâce au tableur passe par le point moyen $G$ dont nous avons calculé les coordonnées. \begin{center} \includegraphics[scale =0.7]{./img/ex2} \end{center} \end{myex}
{ "content_hash": "36cb4c60f70ab00d2804117d8df0f9ff", "timestamp": "", "source": "github", "line_count": 7, "max_line_length": 118, "avg_line_length": 31, "alnum_prop": 0.7327188940092166, "repo_name": "malhys/maths_projects", "id": "7dbdca8f63b4db0ed7cfe5323ef8d5e4795379ad", "size": "220", "binary": false, "copies": "1", "ref": "refs/heads/master", "path": "bac_techno/TST2S/stats/ex2.tex", "mode": "33188", "license": "apache-2.0", "language": [ { "name": "C++", "bytes": "19127" }, { "name": "CSS", "bytes": "51144" }, { "name": "HTML", "bytes": "28318" }, { "name": "JavaScript", "bytes": "2037" }, { "name": "Python", "bytes": "12119" }, { "name": "TeX", "bytes": "1753947" } ], "symlink_target": "" }
using UnityEngine; using UnityEngine.UI; using UIWidgets; using System.Collections.Generic; using System.Linq; namespace UIWidgetsSamples { public class DialogTreeViewInputHelper : MonoBehaviour { [SerializeField] public TreeView Folders; ObservableList<TreeNode<TreeViewItem>> nodes; bool _InitDone; public void Refresh() { if (!_InitDone) { var config = new List<int>() { 5, 5, 2 }; nodes = TestTreeView.GenerateTreeNodes(config, isExpanded: true); // Set nodes Folders.Start(); Folders.Nodes = nodes; _InitDone = true; } } } }
{ "content_hash": "f705e16204dd1c835fa5ff77ea83fb31", "timestamp": "", "source": "github", "line_count": 30, "max_line_length": 69, "avg_line_length": 19.8, "alnum_prop": 0.6801346801346801, "repo_name": "carlosCn/Unity-EmojiText", "id": "a2097fc5d71db4dd279eedd2a3d4b642fc48cc3f", "size": "596", "binary": false, "copies": "1", "ref": "refs/heads/master", "path": "TextInlineSpritePro/Assets/UIWidgets/Sample Assets/DialogTreeViewInputHelper.cs", "mode": "33188", "license": "apache-2.0", "language": [ { "name": "C#", "bytes": "805939" }, { "name": "ShaderLab", "bytes": "13560" } ], "symlink_target": "" }
<?php namespace Cake\ORM\Behavior; use Cake\Database\Expression\IdentifierExpression; use Cake\Datasource\EntityInterface; use Cake\Datasource\Exception\RecordNotFoundException; use Cake\Event\Event; use Cake\ORM\Behavior; use Cake\ORM\Query; use InvalidArgumentException; use RuntimeException; /** * Makes the table to which this is attached to behave like a nested set and * provides methods for managing and retrieving information out of the derived * hierarchical structure. * * Tables attaching this behavior are required to have a column referencing the * parent row, and two other numeric columns (lft and rght) where the implicit * order will be cached. * * For more information on what is a nested set and a how it works refer to * http://www.sitepoint.com/hierarchical-data-database-2/ */ class TreeBehavior extends Behavior { /** * Cached copy of the first column in a table's primary key. * * @var string */ protected $_primaryKey; /** * Default config * * These are merged with user-provided configuration when the behavior is used. * * @var array */ protected $_defaultConfig = [ 'implementedFinders' => [ 'path' => 'findPath', 'children' => 'findChildren', 'treeList' => 'findTreeList', ], 'implementedMethods' => [ 'childCount' => 'childCount', 'moveUp' => 'moveUp', 'moveDown' => 'moveDown', 'recover' => 'recover', 'removeFromTree' => 'removeFromTree', 'getLevel' => 'getLevel', 'formatTreeList' => 'formatTreeList', ], 'parent' => 'parent_id', 'left' => 'lft', 'right' => 'rght', 'scope' => null, 'level' => null, 'recoverOrder' => null, ]; /** * {@inheritDoc} */ public function initialize(array $config) { $this->_config['leftField'] = new IdentifierExpression($this->_config['left']); $this->_config['rightField'] = new IdentifierExpression($this->_config['right']); } /** * Before save listener. * Transparently manages setting the lft and rght fields if the parent field is * included in the parameters to be saved. * * @param \Cake\Event\Event $event The beforeSave event that was fired * @param \Cake\Datasource\EntityInterface $entity the entity that is going to be saved * @return void * @throws \RuntimeException if the parent to set for the node is invalid */ public function beforeSave(Event $event, EntityInterface $entity) { $isNew = $entity->isNew(); $config = $this->config(); $parent = $entity->get($config['parent']); $primaryKey = $this->_getPrimaryKey(); $dirty = $entity->dirty($config['parent']); $level = $config['level']; if ($parent && $entity->get($primaryKey) == $parent) { throw new RuntimeException("Cannot set a node's parent as itself"); } if ($isNew && $parent) { $parentNode = $this->_getNode($parent); $edge = $parentNode->get($config['right']); $entity->set($config['left'], $edge); $entity->set($config['right'], $edge + 1); $this->_sync(2, '+', ">= {$edge}"); if ($level) { $entity->set($level, $parentNode[$level] + 1); } return; } if ($isNew && !$parent) { $edge = $this->_getMax(); $entity->set($config['left'], $edge + 1); $entity->set($config['right'], $edge + 2); if ($level) { $entity->set($level, 0); } return; } if (!$isNew && $dirty && $parent) { $this->_setParent($entity, $parent); if ($level) { $parentNode = $this->_getNode($parent); $entity->set($level, $parentNode[$level] + 1); } return; } if (!$isNew && $dirty && !$parent) { $this->_setAsRoot($entity); if ($level) { $entity->set($level, 0); } } } /** * After save listener. * * Manages updating level of descendants of currently saved entity. * * @param \Cake\Event\Event $event The afterSave event that was fired * @param \Cake\Datasource\EntityInterface $entity the entity that is going to be saved * @return void */ public function afterSave(Event $event, EntityInterface $entity) { if (!$this->_config['level'] || $entity->isNew()) { return; } $this->_setChildrenLevel($entity); } /** * Set level for descendants. * * @param \Cake\Datasource\EntityInterface $entity The entity whose descendants need to be updated. * @return void */ protected function _setChildrenLevel($entity) { $config = $this->config(); if ($entity->get($config['left']) + 1 === $entity->get($config['right'])) { return; } $primaryKey = $this->_getPrimaryKey(); $primaryKeyValue = $entity->get($primaryKey); $depths = [$primaryKeyValue => $entity->get($config['level'])]; $children = $this->_table->find('children', [ 'for' => $primaryKeyValue, 'fields' => [$this->_getPrimaryKey(), $config['parent'], $config['level']], 'order' => $config['left'], ]); /* @var \Cake\ORM\Entity $node */ foreach ($children as $node) { $parentIdValue = $node->get($config['parent']); $depth = $depths[$parentIdValue] + 1; $depths[$node->get($primaryKey)] = $depth; $this->_table->updateAll( [$config['level'] => $depth], [$primaryKey => $node->get($primaryKey)] ); } } /** * Also deletes the nodes in the subtree of the entity to be delete * * @param \Cake\Event\Event $event The beforeDelete event that was fired * @param \Cake\Datasource\EntityInterface $entity The entity that is going to be saved * @return void */ public function beforeDelete(Event $event, EntityInterface $entity) { $config = $this->config(); $this->_ensureFields($entity); $left = $entity->get($config['left']); $right = $entity->get($config['right']); $diff = $right - $left + 1; if ($diff > 2) { $this->_table->deleteAll(function ($exp) use ($config, $left, $right) { return $exp ->gte($config['leftField'], $left + 1) ->lte($config['leftField'], $right - 1); }); } $this->_sync($diff, '-', "> {$right}"); } /** * Sets the correct left and right values for the passed entity so it can be * updated to a new parent. It also makes the hole in the tree so the node * move can be done without corrupting the structure. * * @param \Cake\Datasource\EntityInterface $entity The entity to re-parent * @param mixed $parent the id of the parent to set * @return void * @throws \RuntimeException if the parent to set to the entity is not valid */ protected function _setParent($entity, $parent) { $config = $this->config(); $parentNode = $this->_getNode($parent); $this->_ensureFields($entity); $parentLeft = $parentNode->get($config['left']); $parentRight = $parentNode->get($config['right']); $right = $entity->get($config['right']); $left = $entity->get($config['left']); if ($parentLeft > $left && $parentLeft < $right) { throw new RuntimeException(sprintf( 'Cannot use node "%s" as parent for entity "%s"', $parent, $entity->get($this->_getPrimaryKey()) )); } // Values for moving to the left $diff = $right - $left + 1; $targetLeft = $parentRight; $targetRight = $diff + $parentRight - 1; $min = $parentRight; $max = $left - 1; if ($left < $targetLeft) { // Moving to the right $targetLeft = $parentRight - $diff; $targetRight = $parentRight - 1; $min = $right + 1; $max = $parentRight - 1; $diff *= -1; } if ($right - $left > 1) { // Correcting internal subtree $internalLeft = $left + 1; $internalRight = $right - 1; $this->_sync($targetLeft - $left, '+', "BETWEEN {$internalLeft} AND {$internalRight}", true); } $this->_sync($diff, '+', "BETWEEN {$min} AND {$max}"); if ($right - $left > 1) { $this->_unmarkInternalTree(); } // Allocating new position $entity->set($config['left'], $targetLeft); $entity->set($config['right'], $targetRight); } /** * Updates the left and right column for the passed entity so it can be set as * a new root in the tree. It also modifies the ordering in the rest of the tree * so the structure remains valid * * @param \Cake\Datasource\EntityInterface $entity The entity to set as a new root * @return void */ protected function _setAsRoot($entity) { $config = $this->config(); $edge = $this->_getMax(); $this->_ensureFields($entity); $right = $entity->get($config['right']); $left = $entity->get($config['left']); $diff = $right - $left; if ($right - $left > 1) { //Correcting internal subtree $internalLeft = $left + 1; $internalRight = $right - 1; $this->_sync($edge - $diff - $left, '+', "BETWEEN {$internalLeft} AND {$internalRight}", true); } $this->_sync($diff + 1, '-', "BETWEEN {$right} AND {$edge}"); if ($right - $left > 1) { $this->_unmarkInternalTree(); } $entity->set($config['left'], $edge - $diff); $entity->set($config['right'], $edge); } /** * Helper method used to invert the sign of the left and right columns that are * less than 0. They were set to negative values before so their absolute value * wouldn't change while performing other tree transformations. * * @return void */ protected function _unmarkInternalTree() { $config = $this->config(); $this->_table->updateAll( function ($exp) use ($config) { $leftInverse = clone $exp; $leftInverse->type('*')->add('-1'); $rightInverse = clone $leftInverse; return $exp ->eq($config['leftField'], $leftInverse->add($config['leftField'])) ->eq($config['rightField'], $rightInverse->add($config['rightField'])); }, function ($exp) use ($config) { return $exp->lt($config['leftField'], 0); } ); } /** * Custom finder method which can be used to return the list of nodes from the root * to a specific node in the tree. This custom finder requires that the key 'for' * is passed in the options containing the id of the node to get its path for. * * @param \Cake\ORM\Query $query The constructed query to modify * @param array $options the list of options for the query * @return \Cake\ORM\Query * @throws \InvalidArgumentException If the 'for' key is missing in options */ public function findPath(Query $query, array $options) { if (empty($options['for'])) { throw new InvalidArgumentException("The 'for' key is required for find('path')"); } $config = $this->config(); list($left, $right) = array_map( function ($field) { return $this->_table->aliasField($field); }, [$config['left'], $config['right']] ); $node = $this->_table->get($options['for'], ['fields' => [$left, $right]]); return $this->_scope($query) ->where([ "$left <=" => $node->get($config['left']), "$right >=" => $node->get($config['right']), ]) ->order([$left => 'ASC']); } /** * Get the number of children nodes. * * @param \Cake\Datasource\EntityInterface $node The entity to count children for * @param bool $direct whether to count all nodes in the subtree or just * direct children * @return int Number of children nodes. */ public function childCount(EntityInterface $node, $direct = false) { $config = $this->config(); $parent = $this->_table->aliasField($config['parent']); if ($direct) { return $this->_scope($this->_table->find()) ->where([$parent => $node->get($this->_getPrimaryKey())]) ->count(); } $this->_ensureFields($node); return ($node->get($config['right']) - $node->get($config['left']) - 1) / 2; } /** * Get the children nodes of the current model * * Available options are: * * - for: The id of the record to read. * - direct: Boolean, whether to return only the direct (true), or all (false) children, * defaults to false (all children). * * If the direct option is set to true, only the direct children are returned (based upon the parent_id field) * * @param \Cake\ORM\Query $query Query. * @param array $options Array of options as described above * @return \Cake\ORM\Query * @throws \InvalidArgumentException When the 'for' key is not passed in $options */ public function findChildren(Query $query, array $options) { $config = $this->config(); $options += ['for' => null, 'direct' => false]; list($parent, $left, $right) = array_map( function ($field) { return $this->_table->aliasField($field); }, [$config['parent'], $config['left'], $config['right']] ); list($for, $direct) = [$options['for'], $options['direct']]; if (empty($for)) { throw new InvalidArgumentException("The 'for' key is required for find('children')"); } if ($query->clause('order') === null) { $query->order([$left => 'ASC']); } if ($direct) { return $this->_scope($query)->where([$parent => $for]); } $node = $this->_getNode($for); return $this->_scope($query) ->where([ "{$right} <" => $node->get($config['right']), "{$left} >" => $node->get($config['left']), ]); } /** * Gets a representation of the elements in the tree as a flat list where the keys are * the primary key for the table and the values are the display field for the table. * Values are prefixed to visually indicate relative depth in the tree. * * ### Options * * - keyPath: A dot separated path to fetch the field to use for the array key, or a closure to * return the key out of the provided row. * - valuePath: A dot separated path to fetch the field to use for the array value, or a closure to * return the value out of the provided row. * - spacer: A string to be used as prefix for denoting the depth in the tree for each item * * @param \Cake\ORM\Query $query Query. * @param array $options Array of options as described above. * @return \Cake\ORM\Query */ public function findTreeList(Query $query, array $options) { $left = $this->_table->aliasField($this->config('left')); $results = $this->_scope($query) ->find('threaded', [ 'parentField' => $this->config('parent'), 'order' => [$left => 'ASC'], ]); return $this->formatTreeList($results, $options); } /** * Formats query as a flat list where the keys are the primary key for the table * and the values are the display field for the table. Values are prefixed to visually * indicate relative depth in the tree. * * ### Options * * - keyPath: A dot separated path to the field that will be the result array key, or a closure to * return the key from the provided row. * - valuePath: A dot separated path to the field that is the array's value, or a closure to * return the value from the provided row. * - spacer: A string to be used as prefix for denoting the depth in the tree for each item. * * @param \Cake\ORM\Query $query The query object to format. * @param array $options Array of options as described above. * @return \Cake\ORM\Query Augmented query. */ public function formatTreeList(Query $query, array $options = []) { return $query->formatResults(function ($results) use ($options) { $options += [ 'keyPath' => $this->_getPrimaryKey(), 'valuePath' => $this->_table->displayField(), 'spacer' => '_', ]; return $results ->listNested() ->printer($options['valuePath'], $options['keyPath'], $options['spacer']); }); } /** * Removes the current node from the tree, by positioning it as a new root * and re-parents all children up one level. * * Note that the node will not be deleted just moved away from its current position * without moving its children with it. * * @param \Cake\Datasource\EntityInterface $node The node to remove from the tree * @return \Cake\ORM\Entity|false the node after being removed from the tree or * false on error */ public function removeFromTree(EntityInterface $node) { return $this->_table->connection()->transactional(function () use ($node) { $this->_ensureFields($node); return $this->_removeFromTree($node); }); } /** * Helper function containing the actual code for removeFromTree * * @param \Cake\Datasource\EntityInterface $node The node to remove from the tree * @return \Cake\ORM\Entity|false the node after being removed from the tree or * false on error */ protected function _removeFromTree($node) { $config = $this->config(); $left = $node->get($config['left']); $right = $node->get($config['right']); $parent = $node->get($config['parent']); $node->set($config['parent'], null); if ($right - $left == 1) { return $this->_table->save($node); } $primary = $this->_getPrimaryKey(); $this->_table->updateAll( [$config['parent'] => $parent], [$config['parent'] => $node->get($primary)] ); $this->_sync(1, '-', 'BETWEEN ' . ($left + 1) . ' AND ' . ($right - 1)); $this->_sync(2, '-', "> {$right}"); $edge = $this->_getMax(); $node->set($config['left'], $edge + 1); $node->set($config['right'], $edge + 2); $fields = [$config['parent'], $config['left'], $config['right']]; $this->_table->updateAll($node->extract($fields), [$primary => $node->get($primary)]); foreach ($fields as $field) { $node->dirty($field, false); } return $node; } /** * Reorders the node without changing its parent. * * If the node is the first child, or is a top level node with no previous node * this method will return false * * @param \Cake\Datasource\EntityInterface $node The node to move * @param int|bool $number How many places to move the node, or true to move to first position * @throws \Cake\Datasource\Exception\RecordNotFoundException When node was not found * @return \Cake\ORM\Entity|bool $node The node after being moved or false on failure */ public function moveUp(EntityInterface $node, $number = 1) { if ($number < 1) { return false; } return $this->_table->connection()->transactional(function () use ($node, $number) { $this->_ensureFields($node); return $this->_moveUp($node, $number); }); } /** * Helper function used with the actual code for moveUp * * @param \Cake\Datasource\EntityInterface $node The node to move * @param int|bool $number How many places to move the node, or true to move to first position * @throws \Cake\Datasource\Exception\RecordNotFoundException When node was not found * @return \Cake\ORM\Entity|bool $node The node after being moved or false on failure */ protected function _moveUp($node, $number) { $config = $this->config(); list($parent, $left, $right) = [$config['parent'], $config['left'], $config['right']]; list($nodeParent, $nodeLeft, $nodeRight) = array_values($node->extract([$parent, $left, $right])); $targetNode = null; if ($number !== true) { $targetNode = $this->_scope($this->_table->find()) ->select([$left, $right]) ->where(["$parent IS" => $nodeParent]) ->where(function ($exp) use ($config, $nodeLeft) { return $exp->lt($config['rightField'], $nodeLeft); }) ->orderDesc($config['leftField']) ->offset($number - 1) ->limit(1) ->first(); } if (!$targetNode) { $targetNode = $this->_scope($this->_table->find()) ->select([$left, $right]) ->where(["$parent IS" => $nodeParent]) ->where(function ($exp) use ($config, $nodeLeft) { return $exp->lt($config['rightField'], $nodeLeft); }) ->orderAsc($config['leftField']) ->limit(1) ->first(); if (!$targetNode) { return $node; } } list($targetLeft) = array_values($targetNode->extract([$left, $right])); $edge = $this->_getMax(); $leftBoundary = $targetLeft; $rightBoundary = $nodeLeft - 1; $nodeToEdge = $edge - $nodeLeft + 1; $shift = $nodeRight - $nodeLeft + 1; $nodeToHole = $edge - $leftBoundary + 1; $this->_sync($nodeToEdge, '+', "BETWEEN {$nodeLeft} AND {$nodeRight}"); $this->_sync($shift, '+', "BETWEEN {$leftBoundary} AND {$rightBoundary}"); $this->_sync($nodeToHole, '-', "> {$edge}"); $node->set($left, $targetLeft); $node->set($right, $targetLeft + ($nodeRight - $nodeLeft)); $node->dirty($left, false); $node->dirty($right, false); return $node; } /** * Reorders the node without changing the parent. * * If the node is the last child, or is a top level node with no subsequent node * this method will return false * * @param \Cake\Datasource\EntityInterface $node The node to move * @param int|bool $number How many places to move the node or true to move to last position * @throws \Cake\Datasource\Exception\RecordNotFoundException When node was not found * @return \Cake\ORM\Entity|bool the entity after being moved or false on failure */ public function moveDown(EntityInterface $node, $number = 1) { if ($number < 1) { return false; } return $this->_table->connection()->transactional(function () use ($node, $number) { $this->_ensureFields($node); return $this->_moveDown($node, $number); }); } /** * Helper function used with the actual code for moveDown * * @param \Cake\Datasource\EntityInterface $node The node to move * @param int|bool $number How many places to move the node, or true to move to last position * @throws \Cake\Datasource\Exception\RecordNotFoundException When node was not found * @return \Cake\ORM\Entity|bool $node The node after being moved or false on failure */ protected function _moveDown($node, $number) { $config = $this->config(); list($parent, $left, $right) = [$config['parent'], $config['left'], $config['right']]; list($nodeParent, $nodeLeft, $nodeRight) = array_values($node->extract([$parent, $left, $right])); $targetNode = null; if ($number !== true) { $targetNode = $this->_scope($this->_table->find()) ->select([$left, $right]) ->where(["$parent IS" => $nodeParent]) ->where(function ($exp) use ($config, $nodeRight) { return $exp->gt($config['leftField'], $nodeRight); }) ->orderAsc($config['leftField']) ->offset($number - 1) ->limit(1) ->first(); } if (!$targetNode) { $targetNode = $this->_scope($this->_table->find()) ->select([$left, $right]) ->where(["$parent IS" => $nodeParent]) ->where(function ($exp) use ($config, $nodeRight) { return $exp->gt($config['leftField'], $nodeRight); }) ->orderDesc($config['leftField']) ->limit(1) ->first(); if (!$targetNode) { return $node; } } list(, $targetRight) = array_values($targetNode->extract([$left, $right])); $edge = $this->_getMax(); $leftBoundary = $nodeRight + 1; $rightBoundary = $targetRight; $nodeToEdge = $edge - $nodeLeft + 1; $shift = $nodeRight - $nodeLeft + 1; $nodeToHole = $edge - $rightBoundary + $shift; $this->_sync($nodeToEdge, '+', "BETWEEN {$nodeLeft} AND {$nodeRight}"); $this->_sync($shift, '-', "BETWEEN {$leftBoundary} AND {$rightBoundary}"); $this->_sync($nodeToHole, '-', "> {$edge}"); $node->set($left, $targetRight - ($nodeRight - $nodeLeft)); $node->set($right, $targetRight); $node->dirty($left, false); $node->dirty($right, false); return $node; } /** * Returns a single node from the tree from its primary key * * @param mixed $id Record id. * @return \Cake\ORM\Entity * @throws \Cake\Datasource\Exception\RecordNotFoundException When node was not found */ protected function _getNode($id) { $config = $this->config(); list($parent, $left, $right) = [$config['parent'], $config['left'], $config['right']]; $primaryKey = $this->_getPrimaryKey(); $fields = [$parent, $left, $right]; if ($config['level']) { $fields[] = $config['level']; } $node = $this->_scope($this->_table->find()) ->select($fields) ->where([$this->_table->aliasField($primaryKey) => $id]) ->first(); if (!$node) { throw new RecordNotFoundException("Node \"{$id}\" was not found in the tree."); } return $node; } /** * Recovers the lft and right column values out of the hierarchy defined by the * parent column. * * @return void */ public function recover() { $this->_table->connection()->transactional(function () { $this->_recoverTree(); }); } /** * Recursive method used to recover a single level of the tree * * @param int $counter The Last left column value that was assigned * @param mixed $parentId the parent id of the level to be recovered * @param int $level Node level * @return int The next value to use for the left column */ protected function _recoverTree($counter = 0, $parentId = null, $level = -1) { $config = $this->config(); list($parent, $left, $right) = [$config['parent'], $config['left'], $config['right']]; $primaryKey = $this->_getPrimaryKey(); $aliasedPrimaryKey = $this->_table->aliasField($primaryKey); $order = $config['recoverOrder'] ?: $aliasedPrimaryKey; $query = $this->_scope($this->_table->query()) ->select([$aliasedPrimaryKey]) ->where([$this->_table->aliasField($parent) . ' IS' => $parentId]) ->order($order) ->hydrate(false); $leftCounter = $counter; $nextLevel = $level + 1; foreach ($query as $row) { $counter++; $counter = $this->_recoverTree($counter, $row[$primaryKey], $nextLevel); } if ($parentId === null) { return $counter; } $fields = [$left => $leftCounter, $right => $counter + 1]; if ($config['level']) { $fields[$config['level']] = $level; } $this->_table->updateAll( $fields, [$primaryKey => $parentId] ); return $counter + 1; } /** * Returns the maximum index value in the table. * * @return int */ protected function _getMax() { $field = $this->_config['right']; $rightField = $this->_config['rightField']; $edge = $this->_scope($this->_table->find()) ->select([$field]) ->orderDesc($rightField) ->first(); if (empty($edge->{$field})) { return 0; } return $edge->{$field}; } /** * Auxiliary function used to automatically alter the value of both the left and * right columns by a certain amount that match the passed conditions * * @param int $shift the value to use for operating the left and right columns * @param string $dir The operator to use for shifting the value (+/-) * @param string $conditions a SQL snipped to be used for comparing left or right * against it. * @param bool $mark whether to mark the updated values so that they can not be * modified by future calls to this function. * @return void */ protected function _sync($shift, $dir, $conditions, $mark = false) { $config = $this->_config; foreach ([$config['leftField'], $config['rightField']] as $field) { $query = $this->_scope($this->_table->query()); $exp = $query->newExpr(); $movement = clone $exp; $movement->add($field)->add("$shift")->tieWith($dir); $inverse = clone $exp; $movement = $mark ? $inverse->add($movement)->tieWith('*')->add('-1') : $movement; $where = clone $exp; $where->add($field)->add($conditions)->tieWith(''); $query->update() ->set($exp->eq($field, $movement)) ->where($where); $query->execute()->closeCursor(); } } /** * Alters the passed query so that it only returns scoped records as defined * in the tree configuration. * * @param \Cake\ORM\Query $query the Query to modify * @return \Cake\ORM\Query */ protected function _scope($query) { $config = $this->config(); if (is_array($config['scope'])) { return $query->where($config['scope']); } if (is_callable($config['scope'])) { return $config['scope']($query); } return $query; } /** * Ensures that the provided entity contains non-empty values for the left and * right fields * * @param \Cake\Datasource\EntityInterface $entity The entity to ensure fields for * @return void */ protected function _ensureFields($entity) { $config = $this->config(); $fields = [$config['left'], $config['right']]; $values = array_filter($entity->extract($fields)); if (count($values) === count($fields)) { return; } $fresh = $this->_table->get($entity->get($this->_getPrimaryKey()), $fields); $entity->set($fresh->extract($fields), ['guard' => false]); foreach ($fields as $field) { $entity->dirty($field, false); } } /** * Returns a single string value representing the primary key of the attached table * * @return string */ protected function _getPrimaryKey() { if (!$this->_primaryKey) { $this->_primaryKey = (array)$this->_table->primaryKey(); $this->_primaryKey = $this->_primaryKey[0]; } return $this->_primaryKey; } /** * Returns the depth level of a node in the tree. * * @param int|string|\Cake\Datasource\EntityInterface $entity The entity or primary key get the level of. * @return int|bool Integer of the level or false if the node does not exist. */ public function getLevel($entity) { $primaryKey = $this->_getPrimaryKey(); $id = $entity; if ($entity instanceof EntityInterface) { $id = $entity->get($primaryKey); } $config = $this->config(); $entity = $this->_table->find('all') ->select([$config['left'], $config['right']]) ->where([$primaryKey => $id]) ->first(); if ($entity === null) { return false; } $query = $this->_table->find('all')->where([ $config['left'] . ' <' => $entity[$config['left']], $config['right'] . ' >' => $entity[$config['right']], ]); return $this->_scope($query)->count(); } }
{ "content_hash": "c80fd8b5d4f93e9c015e07d026d908f9", "timestamp": "", "source": "github", "line_count": 992, "max_line_length": 114, "avg_line_length": 34.32560483870968, "alnum_prop": 0.5385451234912337, "repo_name": "chirstmaxbox/cakephp3_cars", "id": "c4d5cd48a006d0c66a007ec816fd28a1148bd268", "size": "34635", "binary": false, "copies": "2", "ref": "refs/heads/master", "path": "vendor/cakephp/cakephp/src/ORM/Behavior/TreeBehavior.php", "mode": "33188", "license": "mit", "language": [ { "name": "ApacheConf", "bytes": "130" }, { "name": "Batchfile", "bytes": "861" }, { "name": "CSS", "bytes": "13864" }, { "name": "JavaScript", "bytes": "3648" }, { "name": "PHP", "bytes": "222711" }, { "name": "Shell", "bytes": "1457" } ], "symlink_target": "" }
#include "ser_phy.h" #include "app_error.h" __weak uint32_t ser_phy_open(ser_phy_events_handler_t events_handler) { /* A function stub. Function should be implemented according to ser_phy.h API. */ APP_ERROR_CHECK_BOOL(false); return NRF_SUCCESS; } __weak uint32_t ser_phy_tx_pkt_send(const uint8_t * p_buffer, uint16_t num_of_bytes) { /* A function stub. Function should be implemented according to ser_phy.h API. */ APP_ERROR_CHECK_BOOL(false); return NRF_SUCCESS; } __weak uint32_t ser_phy_rx_buf_set(uint8_t * p_buffer) { /* A function stub. Function should be implemented according to ser_phy.h API. */ APP_ERROR_CHECK_BOOL(false); return NRF_SUCCESS; } __weak void ser_phy_close(void) { /* A function stub. Function should be implemented according to ser_phy.h API. */ APP_ERROR_CHECK_BOOL(false); } __weak void ser_phy_interrupts_enable(void) { /* A function stub. Function should be implemented according to ser_phy.h API. */ APP_ERROR_CHECK_BOOL(false); } __weak void ser_phy_interrupts_disable(void) { /* A function stub. Function should be implemented according to ser_phy.h API. */ APP_ERROR_CHECK_BOOL(false); }
{ "content_hash": "1953ac45c1bd88ac7b2f836f563fe5e0", "timestamp": "", "source": "github", "line_count": 50, "max_line_length": 85, "avg_line_length": 24, "alnum_prop": 0.6841666666666667, "repo_name": "weiyuliang/rt-thread", "id": "c2d1ba62c63b8319c3efb0fa92e6d7a0f5f772c1", "size": "3237", "binary": false, "copies": "16", "ref": "refs/heads/master", "path": "bsp/nrf52832/nRF5_SDK_13.0.0_04a0bfd/components/serialization/common/transport/ser_phy/ser_phy.c", "mode": "33188", "license": "apache-2.0", "language": [ { "name": "Assembly", "bytes": "10845457" }, { "name": "Batchfile", "bytes": "187090" }, { "name": "C", "bytes": "585304292" }, { "name": "C++", "bytes": "8035069" }, { "name": "CMake", "bytes": "148026" }, { "name": "CSS", "bytes": "9978" }, { "name": "DIGITAL Command Language", "bytes": "13234" }, { "name": "GDB", "bytes": "11796" }, { "name": "HTML", "bytes": "1646865" }, { "name": "Lex", "bytes": "7026" }, { "name": "Logos", "bytes": "7078" }, { "name": "M4", "bytes": "17515" }, { "name": "Makefile", "bytes": "271627" }, { "name": "Module Management System", "bytes": "1548" }, { "name": "Objective-C", "bytes": "4109718" }, { "name": "Pawn", "bytes": "2854" }, { "name": "Perl", "bytes": "9520" }, { "name": "PowerShell", "bytes": "1628" }, { "name": "Python", "bytes": "1553852" }, { "name": "RPC", "bytes": "14162" }, { "name": "Rich Text Format", "bytes": "177701" }, { "name": "Roff", "bytes": "4486" }, { "name": "Ruby", "bytes": "869" }, { "name": "Shell", "bytes": "407900" }, { "name": "TeX", "bytes": "3113" }, { "name": "Yacc", "bytes": "16084" } ], "symlink_target": "" }
describe('<About />', () => { it('Expect to have unit tests specified', () => { expect(true).toEqual(false); }); });
{ "content_hash": "cdd9d60f3a207431128ce426793d641b", "timestamp": "", "source": "github", "line_count": 5, "max_line_length": 51, "avg_line_length": 25, "alnum_prop": 0.536, "repo_name": "tarioto/Portfolio", "id": "46f429fdab1acb618884dfb6de6eaa775eff9c6a", "size": "231", "binary": false, "copies": "3", "ref": "refs/heads/master", "path": "app/containers/About/tests/index.test.js", "mode": "33188", "license": "mit", "language": [ { "name": "ApacheConf", "bytes": "1787" }, { "name": "HTML", "bytes": "9923" }, { "name": "JavaScript", "bytes": "98135" } ], "symlink_target": "" }
@implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. return YES; } - (void)applicationWillResignActive:(UIApplication *)application { // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. } - (void)applicationDidEnterBackground:(UIApplication *)application { // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. } - (void)applicationWillEnterForeground:(UIApplication *)application { // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. } - (void)applicationDidBecomeActive:(UIApplication *)application { // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. } - (void)applicationWillTerminate:(UIApplication *)application { // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. } @end
{ "content_hash": "991ed1c3c8a0ee512783fb24b63185e3", "timestamp": "", "source": "github", "line_count": 36, "max_line_length": 281, "avg_line_length": 51.27777777777778, "alnum_prop": 0.7849404117009751, "repo_name": "dolphinsue319/UIViewToUIImage", "id": "3558253e14aac8f22081655d4bc6936bf16837f3", "size": "2009", "binary": false, "copies": "1", "ref": "refs/heads/master", "path": "UIViewCategories/AppDelegate.m", "mode": "33188", "license": "mit", "language": [ { "name": "Objective-C", "bytes": "4149" }, { "name": "Ruby", "bytes": "3799" } ], "symlink_target": "" }
namespace Google.Cloud.VMMigration.V1.Snippets { // [START vmmigration_v1_generated_VmMigration_CreateGroup_async_flattened_resourceNames] using Google.Api.Gax.ResourceNames; using Google.Cloud.VMMigration.V1; using Google.LongRunning; using System.Threading.Tasks; public sealed partial class GeneratedVmMigrationClientSnippets { /// <summary>Snippet for CreateGroupAsync</summary> /// <remarks> /// This snippet has been automatically generated for illustrative purposes only. /// It may require modifications to work in your environment. /// </remarks> public async Task CreateGroupResourceNamesAsync() { // Create client VmMigrationClient vmMigrationClient = await VmMigrationClient.CreateAsync(); // Initialize request argument(s) LocationName parent = LocationName.FromProjectLocation("[PROJECT]", "[LOCATION]"); Group group = new Group(); string groupId = ""; // Make the request Operation<Group, OperationMetadata> response = await vmMigrationClient.CreateGroupAsync(parent, group, groupId); // Poll until the returned long-running operation is complete Operation<Group, OperationMetadata> completedResponse = await response.PollUntilCompletedAsync(); // Retrieve the operation result Group result = completedResponse.Result; // Or get the name of the operation string operationName = response.Name; // This name can be stored, then the long-running operation retrieved later by name Operation<Group, OperationMetadata> retrievedResponse = await vmMigrationClient.PollOnceCreateGroupAsync(operationName); // Check if the retrieved long-running operation has completed if (retrievedResponse.IsCompleted) { // If it has completed, then access the result Group retrievedResult = retrievedResponse.Result; } } } // [END vmmigration_v1_generated_VmMigration_CreateGroup_async_flattened_resourceNames] }
{ "content_hash": "9b7a99f3e3a94d911a5bf4c9329212d0", "timestamp": "", "source": "github", "line_count": 45, "max_line_length": 132, "avg_line_length": 48.46666666666667, "alnum_prop": 0.6694176983035305, "repo_name": "jskeet/google-cloud-dotnet", "id": "1af83ef4b6909ac6b37014826c23a04cd70a84f1", "size": "2803", "binary": false, "copies": "2", "ref": "refs/heads/main", "path": "apis/Google.Cloud.VMMigration.V1/Google.Cloud.VMMigration.V1.GeneratedSnippets/VmMigrationClient.CreateGroupResourceNamesAsyncSnippet.g.cs", "mode": "33188", "license": "apache-2.0", "language": [ { "name": "Batchfile", "bytes": "767" }, { "name": "C#", "bytes": "268415427" }, { "name": "CSS", "bytes": "1346" }, { "name": "Dockerfile", "bytes": "3173" }, { "name": "HTML", "bytes": "3823" }, { "name": "JavaScript", "bytes": "226" }, { "name": "PowerShell", "bytes": "3303" }, { "name": "Python", "bytes": "2744" }, { "name": "Shell", "bytes": "65260" }, { "name": "sed", "bytes": "1030" } ], "symlink_target": "" }
package org.drools.xml.jaxb.util; import java.util.Arrays; import java.util.Collection; import java.util.List; import javax.xml.bind.annotation.adapters.XmlAdapter; public class JaxbCollectionAdapter extends XmlAdapter<JaxbListWrapper, Collection> { @Override public JaxbListWrapper marshal(Collection v) throws Exception { if ( v == null ) { return new JaxbListWrapper( new Object[0] ); } return new JaxbListWrapper( v.toArray( new Object[v.size()]) ); } @Override public Collection unmarshal(JaxbListWrapper v) throws Exception { return Arrays.asList( v.getElements() ); } }
{ "content_hash": "7714e7b791b19fdc1cc1670c0eefd399", "timestamp": "", "source": "github", "line_count": 26, "max_line_length": 84, "avg_line_length": 25.115384615384617, "alnum_prop": 0.6921898928024502, "repo_name": "psiroky/drools", "id": "317aaba4ae86bfb44aa3a054b3571e02065fa6b1", "size": "1246", "binary": false, "copies": "4", "ref": "refs/heads/master", "path": "drools-core/src/main/java/org/drools/xml/jaxb/util/JaxbCollectionAdapter.java", "mode": "33188", "license": "apache-2.0", "language": [ { "name": "CSS", "bytes": "1412" }, { "name": "Java", "bytes": "19071952" }, { "name": "Python", "bytes": "4529" }, { "name": "Ruby", "bytes": "491" }, { "name": "Shell", "bytes": "2039" }, { "name": "Standard ML", "bytes": "82260" }, { "name": "XSLT", "bytes": "24302" } ], "symlink_target": "" }
namespace mscorlib { namespace System { //Constructors Tests //NotSupportedException() TEST(mscorlib_System_NotSupportedException_Fixture,DefaultConstructor) { mscorlib::System::NotSupportedException *value = new mscorlib::System::NotSupportedException(); EXPECT_NE(NULL, value->GetNativeObject()); } //NotSupportedException(mscorlib::System::String message) TEST(mscorlib_System_NotSupportedException_Fixture,Constructor_2) { mscorlib::System::NotSupportedException *value = new mscorlib::System::NotSupportedException(); EXPECT_NE(NULL, value->GetNativeObject()); } //NotSupportedException(mscorlib::System::String message, mscorlib::System::Exception innerException) TEST(mscorlib_System_NotSupportedException_Fixture,Constructor_3) { mscorlib::System::NotSupportedException *value = new mscorlib::System::NotSupportedException(); EXPECT_NE(NULL, value->GetNativeObject()); } //Public Methods Tests //Public Properties Tests // Property InnerException // Return Type: mscorlib::System::Exception // Property Get Method TEST(mscorlib_System_NotSupportedException_Fixture,get_InnerException_Test) { } // Property HelpLink // Return Type: mscorlib::System::String // Property Get Method TEST(mscorlib_System_NotSupportedException_Fixture,get_HelpLink_Test) { } // Property HelpLink // Return Type: mscorlib::System::String // Property Set Method TEST(mscorlib_System_NotSupportedException_Fixture,set_HelpLink_Test) { } // Property HResult // Return Type: mscorlib::System::Int32 // Property Get Method TEST(mscorlib_System_NotSupportedException_Fixture,get_HResult_Test) { } // Property HResult // Return Type: mscorlib::System::Int32 // Property Set Method TEST(mscorlib_System_NotSupportedException_Fixture,set_HResult_Test) { } // Property Message // Return Type: mscorlib::System::String // Property Get Method TEST(mscorlib_System_NotSupportedException_Fixture,get_Message_Test) { } // Property Source // Return Type: mscorlib::System::String // Property Get Method TEST(mscorlib_System_NotSupportedException_Fixture,get_Source_Test) { } // Property Source // Return Type: mscorlib::System::String // Property Set Method TEST(mscorlib_System_NotSupportedException_Fixture,set_Source_Test) { } // Property StackTrace // Return Type: mscorlib::System::String // Property Get Method TEST(mscorlib_System_NotSupportedException_Fixture,get_StackTrace_Test) { } // Property TargetSite // Return Type: mscorlib::System::Reflection::MethodBase // Property Get Method TEST(mscorlib_System_NotSupportedException_Fixture,get_TargetSite_Test) { } // Property Data // Return Type: mscorlib::System::Collections::IDictionary // Property Get Method TEST(mscorlib_System_NotSupportedException_Fixture,get_Data_Test) { } } }
{ "content_hash": "faff8bd7d582a873125f5ca4f31dc434", "timestamp": "", "source": "github", "line_count": 143, "max_line_length": 103, "avg_line_length": 21.573426573426573, "alnum_prop": 0.6952998379254457, "repo_name": "brunolauze/MonoNative", "id": "0cbc2686007abbc4cd9bf7187492bdaed44654cb", "size": "3746", "binary": false, "copies": "1", "ref": "refs/heads/master", "path": "MonoNative.Tests/mscorlib/System/mscorlib_System_NotSupportedException_Fixture.cpp", "mode": "33188", "license": "bsd-2-clause", "language": [ { "name": "C", "bytes": "137243" }, { "name": "C#", "bytes": "104880" }, { "name": "C++", "bytes": "18404064" }, { "name": "CSS", "bytes": "1754" }, { "name": "HTML", "bytes": "16925" }, { "name": "Shell", "bytes": "132" } ], "symlink_target": "" }
class AddTokenResetPasswordToUsers < ActiveRecord::Migration def self.up add_column :userdetails, :token_reset_password, :string end def self.down remove_column :userdetails, :token_reset_password end end
{ "content_hash": "de3190ca01df7ed8abd4e84c0109826e", "timestamp": "", "source": "github", "line_count": 9, "max_line_length": 60, "avg_line_length": 24.666666666666668, "alnum_prop": 0.7567567567567568, "repo_name": "ANUSF/ADAUsers", "id": "be72d161e971824fb19d3b5d4dc9048acce396c5", "size": "222", "binary": false, "copies": "1", "ref": "refs/heads/master", "path": "db/migrate/20110506022702_add_token_reset_password_to_users.rb", "mode": "33188", "license": "mit", "language": [ { "name": "CoffeeScript", "bytes": "5693" }, { "name": "JavaScript", "bytes": "12269" }, { "name": "Ruby", "bytes": "202108" }, { "name": "Shell", "bytes": "1151" } ], "symlink_target": "" }
namespace Contrib.GoogleAnalytics.Models { public class SettingsRecord { public virtual int Id { get; set; } public virtual bool Enable { get; set; } public virtual string Script { get; set; } } }
{ "content_hash": "4aaab616e19b486a2fce65cd0a5af789", "timestamp": "", "source": "github", "line_count": 7, "max_line_length": 50, "avg_line_length": 33.57142857142857, "alnum_prop": 0.6212765957446809, "repo_name": "dminik/voda_code", "id": "398255e4ec2dc83ff3c3581ccfab4f1e7cd2a4d7", "size": "237", "binary": false, "copies": "2", "ref": "refs/heads/master", "path": "src/Orchard.Web/Modules/Contrib.GoogleAnalytics/Models/SettingsRecord.cs", "mode": "33188", "license": "bsd-3-clause", "language": [ { "name": "ASP", "bytes": "2383" }, { "name": "C", "bytes": "4964" }, { "name": "C#", "bytes": "6635399" }, { "name": "JavaScript", "bytes": "1716572" }, { "name": "Shell", "bytes": "6088" }, { "name": "XSLT", "bytes": "123490" } ], "symlink_target": "" }
require 'rubygems' require 'spec/expectations' orm = ENV['ORM'] strategy = ENV['STRATEGY'] if orm && strategy begin require "#{File.dirname(__FILE__)}/../../lib/#{orm}" rescue LoadError raise "You don't have the #{orm} ORM installed" end $:.unshift(File.dirname(__FILE__) + '/../../../lib') require 'database_cleaner' require 'database_cleaner/cucumber' DatabaseCleaner.strategy = strategy.to_sym else raise "Run 'ORM=activerecord|datamapper|mongomapper STRATEGY=transaction|truncation cucumber examples/features'" end
{ "content_hash": "e3c9fa3e3fbdb5ae8665458fb81ae017", "timestamp": "", "source": "github", "line_count": 23, "max_line_length": 114, "avg_line_length": 24.26086956521739, "alnum_prop": 0.6827956989247311, "repo_name": "cykod/Webiva", "id": "d9fd88a1b43ba61b66cbbd623d07d0678c19df45", "size": "558", "binary": false, "copies": "3", "ref": "refs/heads/master", "path": "vendor/gems/database_cleaner-0.4.3/examples/features/support/env.rb", "mode": "33188", "license": "mit", "language": [ { "name": "JavaScript", "bytes": "1603531" }, { "name": "PHP", "bytes": "19204" }, { "name": "Perl", "bytes": "4042" }, { "name": "Ruby", "bytes": "3033832" }, { "name": "Shell", "bytes": "17397" } ], "symlink_target": "" }
package org.apache.druid.client.indexing; import org.apache.druid.indexer.TaskStatusPlus; import org.apache.druid.timeline.DataSegment; import org.joda.time.DateTime; import org.joda.time.Interval; import javax.annotation.Nullable; import java.util.List; import java.util.Map; public interface IndexingServiceClient { void killSegments(String dataSource, Interval interval); int killPendingSegments(String dataSource, DateTime end); void mergeSegments(List<DataSegment> segments); String compactSegments( List<DataSegment> segments, boolean keepSegmentGranularity, long targetCompactionSizeBytes, int compactionTaskPriority, @Nullable ClientCompactQueryTuningConfig tuningConfig, @Nullable Map<String, Object> context ); int getTotalWorkerCapacity(); String runTask(Object taskObject); String killTask(String taskId); List<TaskStatusPlus> getRunningTasks(); List<TaskStatusPlus> getPendingTasks(); List<TaskStatusPlus> getWaitingTasks(); TaskStatusResponse getTaskStatus(String taskId); @Nullable TaskStatusPlus getLastCompleteTask(); }
{ "content_hash": "0b5eee293dd783a3c9d02a8991fa3580", "timestamp": "", "source": "github", "line_count": 47, "max_line_length": 60, "avg_line_length": 23.76595744680851, "alnum_prop": 0.7806624888093107, "repo_name": "dkhwangbo/druid", "id": "d9d35f5e624935bd215306dfa854d9eb34268e5e", "size": "1924", "binary": false, "copies": "1", "ref": "refs/heads/master", "path": "server/src/main/java/org/apache/druid/client/indexing/IndexingServiceClient.java", "mode": "33188", "license": "apache-2.0", "language": [ { "name": "ANTLR", "bytes": "3345" }, { "name": "CSS", "bytes": "15658" }, { "name": "Dockerfile", "bytes": "4856" }, { "name": "HTML", "bytes": "19754" }, { "name": "Java", "bytes": "21183046" }, { "name": "JavaScript", "bytes": "304058" }, { "name": "Makefile", "bytes": "659" }, { "name": "PostScript", "bytes": "5" }, { "name": "R", "bytes": "17002" }, { "name": "Roff", "bytes": "3617" }, { "name": "Shell", "bytes": "28297" }, { "name": "TeX", "bytes": "399508" }, { "name": "Thrift", "bytes": "207" } ], "symlink_target": "" }
namespace DMLibTest { using Microsoft.Azure.Storage.Auth; using System; public class TestExecutionOptions<TDataInfo> where TDataInfo : IDataInfo { public const int DefaultTimeoutInMs = 20 * 60 * 1000; // 20 min public TestExecutionOptions() { this.TimeoutInMs = DefaultTimeoutInMs; this.DestTransferDataInfo = default(TDataInfo); this.DisableSourceGenerator = false; this.DisableDestinationFetch = false; this.DisableSourceCleaner = false; this.LimitSpeed = false; } public int TimeoutInMs { get; set; } public TDataInfo DestTransferDataInfo { get; set; } public bool IsDirectoryTransfer { get; set; } public bool DisableSourceGenerator { get; set; } public bool DisableSourceCleaner { get; set; } public bool DisableDestinationFetch { get; set; } public bool LimitSpeed { get; set; } public int? BlockSize { get; set; } public StorageCredentials SourceCredentials { get; set; } public StorageCredentials DestCredentials { get; set; } public Action<FileNode, TransferItem> TransferItemModifier; public Action AfterDataPrepared; public Action AfterAllItemAdded; } }
{ "content_hash": "5f45b653769cae5d5fb7330916e193f0", "timestamp": "", "source": "github", "line_count": 83, "max_line_length": 76, "avg_line_length": 20.204819277108435, "alnum_prop": 0.5032796660703638, "repo_name": "Azure/azure-storage-net-data-movement", "id": "df8cdf4f66c8ea76ea32343ce9945368e60e2d37", "size": "1963", "binary": false, "copies": "1", "ref": "refs/heads/master", "path": "test/DMLibTest/Framework/TestExecutionOptions.cs", "mode": "33188", "license": "mit", "language": [ { "name": "Batchfile", "bytes": "3177" }, { "name": "C#", "bytes": "2245580" }, { "name": "PowerShell", "bytes": "1228" } ], "symlink_target": "" }
class CandyStrobingShader : public Shader { public: inline uint32_t shade (float height, uint32_t color, uint32_t currentColor, float remaining, uint32_t secondaryColor) { int stobeClock = (int) (remaining * 100.0); if ( 0 == (stobeClock % 2) ) { return colorByBrightness(remaining, candyColors[stobeClock%candyColorCount]); } return colorByBrightness(0.0, color); } }; #endif //H_STROBE
{ "content_hash": "f0bf5dc5071ab04deb4bd0df4fbe163b", "timestamp": "", "source": "github", "line_count": 19, "max_line_length": 123, "avg_line_length": 25.63157894736842, "alnum_prop": 0.5954825462012321, "repo_name": "touchtechio/starcatcher", "id": "8e6494cb77e51dd1fb5a3d35ea41607a039253ab", "size": "555", "binary": false, "copies": "1", "ref": "refs/heads/main", "path": "Arduino/StarCatcherPlasma/CandyStrobingShader.h", "mode": "33188", "license": "mit", "language": [ { "name": "ASP.NET", "bytes": "237298" }, { "name": "C", "bytes": "60201" }, { "name": "C#", "bytes": "3479827" }, { "name": "C++", "bytes": "82490" }, { "name": "GLSL", "bytes": "24352" }, { "name": "HLSL", "bytes": "1383" }, { "name": "JavaScript", "bytes": "9512" }, { "name": "Max", "bytes": "30730" }, { "name": "Objective-C", "bytes": "15710" }, { "name": "Objective-C++", "bytes": "51941" }, { "name": "Processing", "bytes": "9689" }, { "name": "ShaderLab", "bytes": "185803" } ], "symlink_target": "" }
<!DOCTYPE html><!--[if lt IE 9]><html class="no-js lt-ie9" lang="et" dir="ltr"><![endif]--><!--[if gt IE 8]><!--> <html class="no-js" lang="et" dir="ltr"> <!--<![endif]--> <head> <meta charset="utf-8"> <!-- Web Experience Toolkit (WET) / Boîte à outils de l'expérience Web (BOEW) wet-boew.github.io/wet-boew/License-en.html / wet-boew.github.io/wet-boew/Licence-fr.html --> <title>Message title - Government of Canada Web Usability theme</title> <meta content="width=device-width,initial-scale=1" name="viewport"> <!-- Meta data --> <meta name="robots" content="noindex, nofollow, noarchive"> <!-- Meta data--> <!--[if gte IE 9 | !IE ]><!--> <link href="./theme-gcwu-fegc/assets/favicon.ico" rel="icon" type="image/x-icon"> <link rel="stylesheet" href="./theme-gcwu-fegc/css/theme-srv.min.css"> <!--<![endif]--> <!--[if lt IE 9]> <link href="./theme-gcwu-fegc/assets/favicon.ico" rel="shortcut icon" /> <link rel="stylesheet" href="./theme-gcwu-fegc/css/ie8-theme-srv.min.css" /> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> <script src="./wet-boew/js/ie8-wet-boew.min.js"></script> <![endif]--> <noscript><link rel="stylesheet" href="./wet-boew/css/noscript.min.css" /></noscript> </head> <body vocab="http://schema.org/" typeof="WebPage"> <header role="banner" class="container"> <div id="wb-bnr" class="row"> <div class="row"> <div class="col-sm-6"> <object id="gcwu-sig" type="image/svg+xml" tabindex="-1" role="img" data="./theme-gcwu-fegc/assets/sig-alt-et.svg" aria-label="Kanada valitsus"></object> </div> <div class="col-sm-6"> <object id="wmms" type="image/svg+xml" tabindex="-1" role="img" data="./theme-gcwu-fegc/assets/wmms-alt.svg" aria-label="Kanada valitsuse sümbol"></object> </div> </div> </div> </header> <main role="main" property="mainContentOfPage" class="container"> <div class="row mrgn-tp-lg"> <div class="col-md-12"> <h1><span class="glyphicon glyphicon-warning-sign mrgn-rght-md"></span> Kirja teema</h1> <p>Näidistekst&#32;Näidistekst&#32;Näidistekst&#32;Näidistekst&#32;Näidistekst&#32;Näidistekst&#32;Näidistekst</p> </div> </div> </main> <!--[if gte IE 9 | !IE ]><!--> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.js"></script> <script src="./wet-boew/js/wet-boew.min.js"></script> <!--<![endif]--> <!--[if lt IE 9]> <script src="./wet-boew/js/ie8-wet-boew2.min.js"></script> <![endif]--> <script src="./theme-gcwu-fegc/js/theme.min.js"></script> </body> </html>
{ "content_hash": "49c4d409ac847ca0fe7e68540df5a76a", "timestamp": "", "source": "github", "line_count": 56, "max_line_length": 155, "avg_line_length": 44.035714285714285, "alnum_prop": 0.6654501216545012, "repo_name": "tweed1e/canadalayercake", "id": "20c412c5fcbe8e47cddb887c19f75ab176651bb5", "size": "2477", "binary": false, "copies": "1", "ref": "refs/heads/master", "path": "themes-dist-theme-gcwu-fegc/servermessage-et.html", "mode": "33261", "license": "mit", "language": [ { "name": "CSS", "bytes": "10413135" }, { "name": "HTML", "bytes": "8561234" }, { "name": "JavaScript", "bytes": "10646973" }, { "name": "Makefile", "bytes": "2014" } ], "symlink_target": "" }
jQuery(document).ready(function ($) { // clone the collapse menu from mainnav (.t3-navbar) $('.t3-navbar').each(function(){ var $navwrapper = $(this), $menu = null, $placeholder = null; if ($navwrapper.find('.t3-megamenu').length) { // clone for megamenu $menu = $navwrapper.find('ul.level0').clone(), $placeholder = $navwrapper.prev('.navbar-collapse'); if(!$placeholder.length){ //get the empty one $placeholder = $navwrapper.closest('.container, .t3-mainnav').find('.navbar-collapse:empty'); } var lis = $menu.find('li[data-id]'), liactive = lis.filter('.current'); // clean class lis.removeClass('mega dropdown mega-align-left mega-align-right mega-align-center mega-align-adjust'); // rebuild lis.each(function () { // get firstchild - a or span var $li = $(this), $child = $li.find('>:first-child'); if ($child[0].nodeName == 'DIV') { $child.find('>:first-child').prependTo($li); $child.remove(); } // remove caret if($li.data('hidewcol')){ $child.find('.caret').remove(); $child.nextAll().remove(); return; //that is all for this item } // find subnav and inject into one ul var subul = $li.find('ul.level' + $li.data('level')); if (subul.length) { // create subnav $ul = $('<ul class="level' + $li.data('level') + ' dropdown-menu">'); subul.each(function () { // check if the ul not in a hide when collapsed column if ($(this).parents('.mega-col-nav').data('hidewcol')) return ; $(this).find('>li').appendTo($ul); }); if ($ul.children().length) { $ul.appendTo($li); } } // remove all child div $li.find('>div').remove(); // clean caret if there was no real submenu if(!$li.children('ul').length){ $child.find('.caret').remove(); } var divider = $li.hasClass('divider'); // clear all attributes // $li.removeAttr('class'); for (var x in $li.data()) { $li.removeAttr('data-' + x) } $child.removeAttr('class'); for (var x in $child.data()) { $child.removeAttr('data-' + x) } if(divider){ $li.addClass('divider'); } }); // update class current liactive.addClass('current active'); } else { // clone for bootstrap menu $menu = $navwrapper.find ('ul.nav').clone(); $placeholder = $('.t3-navbar-collapse:empty, .navbar-collapse:empty').eq(0); } //so we have all structure, add standard bootstrap class $menu.find ('a[data-toggle="dropdown"]').removeAttr('data-toggle').removeAttr('data-target'); $menu .find('> li > ul.dropdown-menu') .prev('a').attr('data-toggle', 'dropdown').attr('data-target', '#') .parent('li') .addClass(function(){ return 'dropdown' + ($(this).data('level') > 1 ? ' dropdown-submenu' : ''); }); // inject into .t3-navbar-collapse $menu.appendTo ($placeholder); }); });
{ "content_hash": "02db1d4a4b2222e48059e5ebfcc1ac99", "timestamp": "", "source": "github", "line_count": 110, "max_line_length": 114, "avg_line_length": 35.85454545454545, "alnum_prop": 0.43331643002028397, "repo_name": "DannyNunez/joomla-solr", "id": "2615efbacb09522943be90c8fb75f44ef514abb7", "size": "4634", "binary": false, "copies": "91", "ref": "refs/heads/master", "path": "plugins/system/t3/base-bs3/js/nav-collapse.js", "mode": "33261", "license": "mit", "language": [ { "name": "CSS", "bytes": "3202984" }, { "name": "JavaScript", "bytes": "2436457" }, { "name": "PHP", "bytes": "9752955" }, { "name": "Perl", "bytes": "29803" } ], "symlink_target": "" }
package org.wso2.carbon.analytics.data.commons.service; import org.wso2.carbon.analytics.data.commons.sources.RecordGroup; import java.io.Serializable; import java.util.List; /** * This class represents an analytics data service response. */ public class AnalyticsDataResponse implements Serializable { private static final long serialVersionUID = 7912542783175151940L; private List<Entry> entries; public AnalyticsDataResponse() { } public AnalyticsDataResponse(List<Entry> entries) { this.entries = entries; } public List<Entry> getEntries() { return entries; } /** * This class represents a single record store name / record group entry. */ public static class Entry implements Serializable { private static final long serialVersionUID = 3278533423223275273L; private String recordStoreName; private RecordGroup recordGroup; public Entry() { } public Entry(String recordStoreName, RecordGroup recordGroup) { this.recordStoreName = recordStoreName; this.recordGroup = recordGroup; } public String getRecordStoreName() { return recordStoreName; } public RecordGroup getRecordGroup() { return recordGroup; } } }
{ "content_hash": "e89a76c29f73473c44a34367ab7b6617", "timestamp": "", "source": "github", "line_count": 57, "max_line_length": 77, "avg_line_length": 24.473684210526315, "alnum_prop": 0.6422939068100358, "repo_name": "samgregoost/carbon-analytics", "id": "ce1e2917eb12cabc1a1055d3f8c1ae0b90ec8e98", "size": "2080", "binary": false, "copies": "1", "ref": "refs/heads/master", "path": "components/analytics-data-commons/org.wso2.carbon.analytics.data.commons/src/main/java/org/wso2/carbon/analytics/data/commons/service/AnalyticsDataResponse.java", "mode": "33188", "license": "apache-2.0", "language": [ { "name": "Java", "bytes": "1110260" }, { "name": "Thrift", "bytes": "3745" } ], "symlink_target": "" }
@interface NSDate (GHAPIDateFormatting) @property (nonatomic, readonly) NSString *prettyShortTimeIntervalSinceNow; @property (nonatomic, readonly) NSString *prettyTimeIntervalSinceNow; @property (nonatomic, readonly) NSString *stringInGithubAPIFormat; @property (nonatomic, readonly) NSString *stringInV3Format; @end
{ "content_hash": "0151bb058ce88bce7f53135530e4c55b", "timestamp": "", "source": "github", "line_count": 9, "max_line_length": 74, "avg_line_length": 35.55555555555556, "alnum_prop": 0.828125, "repo_name": "OliverLetterer/iHubSC", "id": "58d2705a0db33fb78a4c50b51378114b8b1913d0", "size": "500", "binary": false, "copies": "1", "ref": "refs/heads/master", "path": "iGithub/Shared/GitHub API/Foundation & Class Additions/NSDate/NSDate+GithubAPIAdditions.h", "mode": "33188", "license": "mit", "language": [ { "name": "JavaScript", "bytes": "125460" }, { "name": "Objective-C", "bytes": "1568361" }, { "name": "Ruby", "bytes": "302" } ], "symlink_target": "" }
<mat-toolbar color="primary"> <span>Hi, I'm material toolbar</span> </mat-toolbar>
{ "content_hash": "9097051d61c2ebdd5bfdb560c4b78bf4", "timestamp": "", "source": "github", "line_count": 3, "max_line_length": 39, "avg_line_length": 28.333333333333332, "alnum_prop": 0.6941176470588235, "repo_name": "nycJSorg/angular-presentation", "id": "b40c58a4a2ac0562523e8ecbf3c6b24497428b2a", "size": "85", "binary": false, "copies": "2", "ref": "refs/heads/master", "path": "apps/codelab/src/app/codelabs/angular/material/samples/basic/app.1.html", "mode": "33188", "license": "apache-2.0", "language": [ { "name": "CSS", "bytes": "64088" }, { "name": "HTML", "bytes": "378245" }, { "name": "JavaScript", "bytes": "6734881" }, { "name": "TypeScript", "bytes": "614237" } ], "symlink_target": "" }
using System.IO; using System.Web.Mvc; using System.Web.UI; using Nop.Core.Infrastructure; namespace Nop.Web.Framework.Security.Captcha { public static class HtmlExtensions { public static string GenerateCaptcha(this HtmlHelper helper) { var captchaSettings = EngineContext.Current.Resolve<CaptchaSettings>(); var htmlWriter = new HtmlTextWriter(new StringWriter()); var captchaControl = new GRecaptchaControl(captchaSettings.ReCaptchaVersion) { Theme = captchaSettings.ReCaptchaTheme, Id = "recaptcha", PublicKey = captchaSettings.ReCaptchaPublicKey, Language = captchaSettings.ReCaptchaLanguage }; captchaControl.RenderControl(htmlWriter); return htmlWriter.InnerWriter.ToString(); } } }
{ "content_hash": "20d977a91a1e451e3526501179d869bf", "timestamp": "", "source": "github", "line_count": 27, "max_line_length": 88, "avg_line_length": 32.51851851851852, "alnum_prop": 0.6457858769931663, "repo_name": "Anovative/Nop39", "id": "3f7305d4eac81de4b5f207043e4a58c39f5d9298", "size": "880", "binary": false, "copies": "2", "ref": "refs/heads/develop", "path": "Presentation/Nop.Web.Framework/Security/Captcha/HtmlExtensions.cs", "mode": "33188", "license": "mit", "language": [ { "name": "ASP", "bytes": "98" }, { "name": "C#", "bytes": "13838094" }, { "name": "CSS", "bytes": "996427" }, { "name": "HTML", "bytes": "22119" }, { "name": "JavaScript", "bytes": "1136969" } ], "symlink_target": "" }
'use strict'; var fs = require('fs'); var async = require('async'); var request = require('request'); var hooks = require('feathers-hooks-common'); var auth = require('feathers-authentication').hooks; exports.before = { all: [], find: [], get: [], create: [ auth.verifyToken(), auth.populateUser(), auth.restrictToAuthenticated(), auth.restrictToRoles({ roles: ['editor'] }) ], update: [ auth.verifyToken(), auth.populateUser(), auth.restrictToAuthenticated(), auth.restrictToRoles({ roles: ['editor'] }) ], patch: [ auth.verifyToken(), auth.populateUser(), auth.restrictToAuthenticated(), auth.restrictToRoles({ roles: ['editor'] }) ], remove: [ auth.verifyToken(), auth.populateUser(), auth.restrictToAuthenticated(), auth.restrictToRoles({ roles: ['editor'] }) ] }; exports.after = { all: [], find: [], get: [], create: [], update: [], patch: [], remove: [] };
{ "content_hash": "26ae291488f50db2893d7f546d977385", "timestamp": "", "source": "github", "line_count": 47, "max_line_length": 52, "avg_line_length": 20.574468085106382, "alnum_prop": 0.6049638055842813, "repo_name": "aparabolica/DomeGIS", "id": "a567e89ff3d26ec844d000862e4aa16edad631a7", "size": "967", "binary": false, "copies": "4", "ref": "refs/heads/master", "path": "src/services/category/hooks.js", "mode": "33188", "license": "mit", "language": [ { "name": "CSS", "bytes": "36252" }, { "name": "HTML", "bytes": "62125" }, { "name": "JavaScript", "bytes": "269474" }, { "name": "Shell", "bytes": "5953" } ], "symlink_target": "" }
package Google::Ads::GoogleAds::V11::Services::FeedService::MutateFeedsResponse; use strict; use warnings; use base qw(Google::Ads::GoogleAds::BaseEntity); use Google::Ads::GoogleAds::Utils::GoogleAdsHelper; sub new { my ($class, $args) = @_; my $self = { partialFailureError => $args->{partialFailureError}, results => $args->{results}}; # Delete the unassigned fields in this object for a more concise JSON payload remove_unassigned_fields($self, $args); bless $self, $class; return $self; } 1;
{ "content_hash": "976dead4613b9579da1e87e01f1a7eeb", "timestamp": "", "source": "github", "line_count": 22, "max_line_length": 80, "avg_line_length": 24.318181818181817, "alnum_prop": 0.6822429906542056, "repo_name": "googleads/google-ads-perl", "id": "a6a786d61eef198322ada52a08e2b5ca9a3870b1", "size": "1111", "binary": false, "copies": "1", "ref": "refs/heads/main", "path": "lib/Google/Ads/GoogleAds/V11/Services/FeedService/MutateFeedsResponse.pm", "mode": "33188", "license": "apache-2.0", "language": [ { "name": "Dockerfile", "bytes": "73" }, { "name": "Perl", "bytes": "5866064" } ], "symlink_target": "" }
namespace arrow { class Array; class Status; namespace py { struct PyConversionOptions { PyConversionOptions() = default; PyConversionOptions(const std::shared_ptr<DataType>& type, int64_t size, MemoryPool* pool, bool from_pandas) : type(type), size(size), from_pandas(from_pandas) {} // Set to null if to be inferred std::shared_ptr<DataType> type; // Default is -1, which indicates the size should the same as the input sequence int64_t size = -1; bool from_pandas = false; /// Used to maintain backwards compatibility for /// timezone bugs (see ARROW-9528). Should be removed /// after Arrow 2.0 release. bool ignore_timezone = false; bool strict = false; }; /// \brief Convert sequence (list, generator, NumPy array with dtype object) of /// Python objects. /// \param[in] obj the sequence to convert /// \param[in] mask a NumPy array of true/false values to indicate whether /// values in the sequence are null (true) or not null (false). This parameter /// may be null /// \param[in] options various conversion options /// \param[in] pool MemoryPool to use for allocations /// \return Result ChunkedArray ARROW_PYTHON_EXPORT Result<std::shared_ptr<ChunkedArray>> ConvertPySequence( PyObject* obj, PyObject* mask, PyConversionOptions options, MemoryPool* pool = default_memory_pool()); } // namespace py } // namespace arrow
{ "content_hash": "e56faab240c083173f8b01a0c2085749", "timestamp": "", "source": "github", "line_count": 47, "max_line_length": 82, "avg_line_length": 29.893617021276597, "alnum_prop": 0.703914590747331, "repo_name": "laurentgo/arrow", "id": "d167996ba8da6796ac62da0fa0186419a3211930", "size": "2521", "binary": false, "copies": "4", "ref": "refs/heads/master", "path": "cpp/src/arrow/python/python_to_arrow.h", "mode": "33188", "license": "apache-2.0", "language": [ { "name": "Assembly", "bytes": "73655" }, { "name": "Awk", "bytes": "3683" }, { "name": "Batchfile", "bytes": "32252" }, { "name": "C", "bytes": "328114" }, { "name": "C#", "bytes": "419434" }, { "name": "C++", "bytes": "7254875" }, { "name": "CMake", "bytes": "401649" }, { "name": "CSS", "bytes": "3946" }, { "name": "Dockerfile", "bytes": "42193" }, { "name": "FreeMarker", "bytes": "2274" }, { "name": "Go", "bytes": "364102" }, { "name": "HTML", "bytes": "23047" }, { "name": "Java", "bytes": "2296962" }, { "name": "JavaScript", "bytes": "84850" }, { "name": "Lua", "bytes": "8741" }, { "name": "M4", "bytes": "8713" }, { "name": "MATLAB", "bytes": "9068" }, { "name": "Makefile", "bytes": "44853" }, { "name": "Meson", "bytes": "36931" }, { "name": "Objective-C", "bytes": "7559" }, { "name": "PLpgSQL", "bytes": "56995" }, { "name": "Perl", "bytes": "3799" }, { "name": "Python", "bytes": "1548489" }, { "name": "R", "bytes": "155922" }, { "name": "Ruby", "bytes": "682150" }, { "name": "Rust", "bytes": "1609482" }, { "name": "Shell", "bytes": "251436" }, { "name": "Thrift", "bytes": "137291" }, { "name": "TypeScript", "bytes": "932690" } ], "symlink_target": "" }
module RSpec module Mocks module AnyInstance # Given a class `TheClass`, `TheClass.any_instance` returns a `Recorder`, # which records stubs and message expectations for later playback on # instances of `TheClass`. # # Further constraints are stored in instances of [Chain](Chain). # # @see AnyInstance # @see Chain class Recorder # @private attr_reader :message_chains def initialize(klass) @message_chains = MessageChains.new @observed_methods = [] @played_methods = {} @klass = klass @expectation_set = false end # Initializes the recording a stub to be played back against any # instance of this object that invokes the submitted method. # # @see Methods#stub def stub(method_name_or_method_map, &block) if method_name_or_method_map.is_a?(Hash) method_name_or_method_map.each do |method_name, return_value| stub(method_name).and_return(return_value) end else observe!(method_name_or_method_map) message_chains.add(method_name_or_method_map, StubChain.new(method_name_or_method_map, &block)) end end # Initializes the recording a stub chain to be played back against any # instance of this object that invokes the method matching the first # argument. # # @see Methods#stub_chain def stub_chain(*method_names_and_optional_return_values, &block) normalize_chain(*method_names_and_optional_return_values) do |method_name, args| observe!(method_name) message_chains.add(method_name, StubChainChain.new(*args, &block)) end end # Initializes the recording a message expectation to be played back # against any instance of this object that invokes the submitted # method. # # @see Methods#should_receive def should_receive(method_name, &block) @expectation_set = true observe!(method_name) message_chains.add(method_name, PositiveExpectationChain.new(method_name, &block)) end def should_not_receive(method_name, &block) should_receive(method_name, &block).never end # Removes any previously recorded stubs, stub_chains or message # expectations that use `method_name`. # # @see Methods#unstub def unstub(method_name) unless @observed_methods.include?(method_name.to_sym) raise RSpec::Mocks::MockExpectationError, "The method `#{method_name}` was not stubbed or was already unstubbed" end message_chains.remove_stub_chains_for!(method_name) stop_observing!(method_name) unless message_chains.has_expectation?(method_name) end # @api private # # Used internally to verify that message expectations have been # fulfilled. def verify if @expectation_set && !message_chains.all_expectations_fulfilled? raise RSpec::Mocks::MockExpectationError, "Exactly one instance should have received the following message(s) but didn't: #{message_chains.unfulfilled_expectations.sort.join(', ')}" end ensure stop_all_observation! ::RSpec::Mocks.space.remove_any_instance_recorder_for(@klass) end # @private def stub!(*) raise "stub! is not supported on any_instance. Use stub instead." end # @private def unstub!(*) raise "unstub! is not supported on any_instance. Use unstub instead." end # @private def stop_all_observation! @observed_methods.each {|method_name| restore_method!(method_name)} end # @private def playback!(instance, method_name) RSpec::Mocks.space.ensure_registered(instance) message_chains.playback!(instance, method_name) @played_methods[method_name] = instance received_expected_message!(method_name) if message_chains.has_expectation?(method_name) end # @private def instance_that_received(method_name) @played_methods[method_name] end def build_alias_method_name(method_name) "__#{method_name}_without_any_instance__" end def already_observing?(method_name) @observed_methods.include?(method_name) end private def normalize_chain(*args) args.shift.to_s.split('.').map {|s| s.to_sym}.reverse.each {|a| args.unshift a} yield args.first, args end def received_expected_message!(method_name) message_chains.received_expected_message!(method_name) restore_method!(method_name) mark_invoked!(method_name) end def restore_method!(method_name) if public_protected_or_private_method_defined?(build_alias_method_name(method_name)) restore_original_method!(method_name) else remove_dummy_method!(method_name) end end def restore_original_method!(method_name) alias_method_name = build_alias_method_name(method_name) @klass.class_eval do remove_method method_name alias_method method_name, alias_method_name remove_method alias_method_name end end def remove_dummy_method!(method_name) @klass.class_eval do remove_method method_name end end def backup_method!(method_name) alias_method_name = build_alias_method_name(method_name) @klass.class_eval do alias_method alias_method_name, method_name end if public_protected_or_private_method_defined?(method_name) end def public_protected_or_private_method_defined?(method_name) @klass.method_defined?(method_name) || @klass.private_method_defined?(method_name) end def stop_observing!(method_name) restore_method!(method_name) @observed_methods.delete(method_name) end def observe!(method_name) stop_observing!(method_name) if already_observing?(method_name) @observed_methods << method_name backup_method!(method_name) @klass.class_eval(<<-EOM, __FILE__, __LINE__ + 1) def #{method_name}(*args, &blk) klass = ::RSpec::Mocks.method_handle_for(self, :#{method_name}).owner ::RSpec::Mocks.any_instance_recorder_for(klass).playback!(self, :#{method_name}) self.__send__(:#{method_name}, *args, &blk) end EOM end def mark_invoked!(method_name) backup_method!(method_name) @klass.class_eval(<<-EOM, __FILE__, __LINE__ + 1) def #{method_name}(*args, &blk) method_name = :#{method_name} klass = ::RSpec::Mocks.method_handle_for(self, :#{method_name}).owner invoked_instance = ::RSpec::Mocks.any_instance_recorder_for(klass).instance_that_received(method_name) raise RSpec::Mocks::MockExpectationError, "The message '#{method_name}' was received by \#{self.inspect} but has already been received by \#{invoked_instance}" end EOM end end end end end
{ "content_hash": "f38ed6f13d7bd57c054e12a2f3f60053", "timestamp": "", "source": "github", "line_count": 206, "max_line_length": 193, "avg_line_length": 36.592233009708735, "alnum_prop": 0.5988325815866278, "repo_name": "kelseymok/syllable_counter", "id": "64b0a8fadfe5105cb13a37196fa522aa58ae09f5", "size": "7538", "binary": false, "copies": "13", "ref": "refs/heads/master", "path": "vendor/bundle/gems/rspec-mocks-2.14.3/lib/rspec/mocks/any_instance/recorder.rb", "mode": "33188", "license": "mit", "language": [ { "name": "Ruby", "bytes": "7127" } ], "symlink_target": "" }
.. _config: Configuring Holland =================== By default, Holland's configuration files reside in /etc/holland. The main configuration file is holland.conf, however there are a number of other configuration files for configuring default settings for providers and for configuring backup sets. Each configuration file has one ore more sections, defined by square brackets Underneath each section, one or more configuration option can be specified. These options are in a standard "option = value" format. Comments are prefixed by the # sign. Note that many settings have default values and, as a result, can either be commented out or omitted entirely. .. _config-global: Global Config ------------- The main configuration file (usually ``/etc/holland/holland.conf``) defines both global settings as well as the active backup sets. It is divided into two sections :ref:`[holland]<holland-config>` and :ref:`[logging]<logging-config>`. .. _holland-config: [holland] ^^^^^^^^^ .. _holland-config-plugin_dirs: .. describe:: plugin_dirs = [directory1],[directory2],...,[directoryN] Defines where the plugins can be found. This can be a comma-separated list but usually does not need to be modified. For most installations, this will usually be ``/usr/share/holland/plugins``. .. deprecated:: 1.0.8 This option is no longer required and can be omitted. .. _holland-config-backup_directory: .. describe:: backup_directory = [directory] Top-level directory where backups are held. This is usually ``/var/spool/holland``. .. _holland-config-backupsets: .. describe:: backupsets = [backupset1],[backupset2],...,[backupsetN] A comma-separated list of all the backup sets Holland should backup. Each backup set is defined in ``/etc/holland/backupsets/<name>.conf`` by default. .. describe:: umask = [0000-7777] Sets the umask of the resulting backup files. .. describe:: path = <directory1>:<directory2>:...:<directoryN> Defines a path for holland and its spawned processes. .. _logging-config: [logging] ^^^^^^^^^ .. describe:: filename = [path]/[filename] The log file itself. .. describe:: level = [debug|info|warning|error|critical] Sets the verbosity of Holland's logging process. Available options are ``debug``, ``info``, ``warning``, ``error``, and ``critical`` Example ^^^^^^^ .. code-block:: ini ## Root holland config file [holland] ## Paths where holland plugins may be found. ## Can be comma separated plugin_dirs = /usr/share/holland/plugins ## Top level directory where backups are held backup_directory = /var/spool/holland ## List of enabled backup sets. Can be comma separated. ## Read from <config_dir>/backupsets/<name>.conf # backupsets = example, traditional, parallel_backups, non_transactional backupsets = mydbbackup, pgdump-full, mysql-lvm-reportingdb # Define a umask for file generated by holland umask = 0007 # Define a path for holland and its spawned processes path = /usr/local/bin:/usr/local/sbin:/bin:/sbin:/usr/bin:/usr/sbin [logging] ## where to write the log filename = /var/log/holland.log ## debug, info, warning, error, critical (case insensitive) level = info .. _config-backupsets: Backup-Set Configs ------------------ Backup-Set configuration files are housed in ``/etc/holland/backupsets`` with the name of the backup-set being the name of the file before the .conf suffix (e.g. 'myfavoritebackup.conf' is the configuration file for the 'myfavoritebackup' backup-set). The backups themselves are placed under the directory defined in the :ref:`backup_directory<holland-config-backup_directory>` section of the main configuration file. Each backup resides under a directory corresponding to the backup-set name followed by one or more date-encoded directories. Backup-Set configuration files inherit the configuration options of the specified plugins (though these settings can be overridden). To define a provider plugin for the backup set, you must put the following at the top of the backup set configuration file. .. code-block:: ini [holland:backup] plugin = <plugin> ... .. _holland-backup-config_options: [holland:backup] Configuration Options ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ This section is for configuring Holland specific options and is usually at the top of a particular backup set configuration file. These options control the behavior of Holland itself, rather than of the backup provider and associated helper plugins (which are defined within their own sections - see below). .. describe:: plugin = [provider plugin] This is the name of the provider that will be used for the backup-set. This is required in order for the backup-set to function. .. describe:: backups-to-keep = # Specifies the number of backups to keep for a backup-set. Defaults to retaining 1 backup. .. describe:: estimated-size-factor = # Specifies the scale factor when Holland decides if there is enough free space to perform a backup. The default is 1.0 and this number is multiplied against what each individual plugin reports its estimated backup size when Holland is verifying sufficient free space for the backupset. .. describe:: auto-purge-failures = [yes|no] Specifies whether to keep a failed backup or to automatically remove the backup directory. By default this is on with the intention that whatever process is calling holland will retry when a backup fails. This behavior can be disabled by setting auto-purge-failures = no when partial backups might be useful or when troubleshooting a backup failure. .. describe:: purge-policy = [manual|before-backup|after-backup] Specifies when to run the purge routine on a backupset. By default this is run after a new successful backup completes. Up to ``backups-to-keep`` backups will be retained including the most recent. ``purge-policy = before-backup`` will run the purge routine just before a new backup starts. This will retain up to ``backups-to-keep`` backups before the new backup is even started allowing purging all previous backups if ``backups-to-keep`` is set to 0. This behavior is useful if some other process is retaining backups off-server and disk space is at a premium. ``purge-policy = after-backup`` will run the purge routine after the completion of the backup. This means more space is required during the backup run. This is safer than ``before-backup`` due to failed backups not causing good backups to be purged. ``purge-policy = manual`` will never run the purge routine automatically. Either ``holland purge`` must be run externally or an explicit removal of desired backup directories can be done at some later time. Hooks """"" .. describe:: before-backup-command = string Run a shell command before a backup starts, such as setting up an iptables rule (taking a mysql slave out of a load balancer) or aborting the backup based on some external condition. The backup will fail if this command exits with a non-zero status. .. versionadded:: 1.0.7 .. describe:: after-backup-command = string Run a shell command after a **successful** backup, such as sending out an e-mail or performing external post backup cleanup tasks (such putting a server back in a load balancer for example). Note if the backup fails, ``failed-backup-command`` will be run instead. Thus, if doing things like pulling the server out of a load-balancer, such commands should added to ``after-backup-command`` and ``failed-backup-command`` to avoid an inconsistent state. The backup will fail if this command exits with a non-zero status. .. versionadded:: 1.0.7 .. describe:: failed-backup-command = string Run a shell command if a backup failed, such as firing off an e-mail to notify relevant folks about the failure. .. versionadded:: 1.0.7 For all hook commands, Holland will perform simple text substitution on the three parameters: * **hook**: The name of the hook being called (one of: ``before-backup-command``, ``after-backup-command``, ``failed-backup-command``) * **backupdir**: The path to the current backup directory (e.g. ``/var/spool/holland/mysqldump/YYYYmmdd_HHMMSS``) * **backupset**: The name of the backupset being run (e.g. ``mysql-lvm``) For Example .. code-block:: ini [holland:backup] plugin = mysqldump before-backup-command = /usr/local/bin/my-custom-script --hook ${hook} --backupset ${backupset} --backupdir ${backupdir} after-backup-command = echo ${backupset} completed successfully. Files are in ${backupdir} failed-backup-command = echo "${backupset} failed!" | mail -s "${backupset} backup failed" [email protected] Provider Plugin Configs ^^^^^^^^^^^^^^^^^^^^^^^ The following are the provider plugins that can be used in a backup-set. These are used within their own braced section in the backup-set configuration file. For specific information on how to configure a desired provider, see the list below. For advanced users, the defaults for each provider plugin can be changed by editing the default configuration file for said provider. These files are located in ``/etc/holland/providers`` by default. For more information on configuring a specific provider, see :doc:`providers` Helper Plugins """""""""""""" .. toctree:: :maxdepth: 1 MySQL Client Helper Plugin <provider_plugins/mysqlconfig> Compression Helper Plugin <provider_plugins/compression> Backup Set Config Example ^^^^^^^^^^^^^^^^^^^^^^^^^ Here is an example backup set which uses mysqldump to backup all but a few databases, in a one-file-per-database fashion. For more specific examples, consult the documentation for the specific provider plugin you wish to use (see above). .. code-block:: ini [holland:backup] plugin = mysqldump backups-to-keep = 1 auto-purge-failures = yes purge-policy = after-backup estimated-size-factor = 0.25 [mysqldump] extra-defaults = no lock-method = auto-detect databases = * exclude-databases = "mydb", "myotherdb" exclude-invalid-views = no flush-logs = no flush-privileges = yes dump-routines = no dump-events = no stop-slave = no max-allowed-packet = 128M bin-log-position = no file-per-database = yes estimate-method = plugin [compression] method = gzip inline = yes level = 1 [mysql:client] defaults-extra-file = ~/.my.cnf
{ "content_hash": "45f3bc0dfa3bc5fca7a9038a3c4f488b", "timestamp": "", "source": "github", "line_count": 310, "max_line_length": 136, "avg_line_length": 34.32258064516129, "alnum_prop": 0.7161654135338346, "repo_name": "m00dawg/holland", "id": "4ddd231840ed90130b68b851f034a6f38a816e83", "size": "10640", "binary": false, "copies": "1", "ref": "refs/heads/master", "path": "docs/source/config.rst", "mode": "33188", "license": "bsd-3-clause", "language": [ { "name": "Makefile", "bytes": "7884" }, { "name": "Python", "bytes": "1720427" }, { "name": "Roff", "bytes": "3761" }, { "name": "Shell", "bytes": "5001" } ], "symlink_target": "" }
[![Build Status](https://travis-ci.org/darrencauthon/three.png)](https://travis-ci.org/darrencauthon/three) [![Code Climate](https://codeclimate.com/github/darrencauthon/three.png)](https://codeclimate.com/github/darrencauthon/three) This gem started as a minor fork of [six](https://github.com/randx/six), a neat, tiny authorization gem. I used six and liked it, but as small was it was I found that I needed maybe half of its code and features. So here is *three*. **three** is a small authentication library, focused on only a few needs: 1. Provide an open/closed method of constructing rules, 2. Provide a way to remove permissions, and 3. Do it as simply as possible. ### Installation ```ruby gem install three ``` ### Usage Here's the simplest working example... a set of rules that apply for all ```ruby # make an object with an "allowed" method that returns an array of permissions module Rules def self.allowed _, _ [:edit, :delete] end end # create an evaluator that can be used to evaluate rules evaluator = Three.evaluator_for Rules # use the evaluator to determine what's allowed or not evaluator.allowed? nil, :edit # true evaluator.allowed? nil, :close # false evaluator.allowed? nil, :delete # true ``` Unfortunately, that's not a very realistic example. We'll almost always want to evaluate the rules based on some sort of subject: ```ruby module AdminRules def self.allowed user, _ return [] unless user.admin? [:edit, :delete] end end evaluator = Three.evaluator_for AdminRules admin_user = User.new(admin: true) not_an_admin = User.new(admin: false) evaluator.allowed? admin_user, :edit # true evaluator.allowed? not_an_admin_user, :edit # false ``` See? The array of permissions returned by the "allowed" method are used to determine if a user can do something. The rules can be compounded, like so: ```ruby module AdminRules def self.allowed user, _ return [] unless user.admin? [:edit, :delete] end end module UserRules def self.allowed user, _ return [] if user.admin? [:view_my_account] end end evaluator = Three.evaluator_for(AdminRules, UserRules) admin_user = User.new(admin: true) not_an_admin = User.new(admin: false) evaluator.allowed? admin_user, :edit # true evaluator.allowed? not_an_admin_user, :edit # false evaluator.allowed? admin_user, :view_my_account # false evaluator.allowed? not_an_admin_user, :view_my_account # true ``` But what about that trailing "_" variable? That's used as an optional target, which you can use to return permissions based on the relationship between the two arguments: ```ruby module MovieRules def self.allowed user, movie if user.is_a_minor? and movie.is_rated_r [] else [:can_buy_the_ticket] end end end evaluator = Three.evaluator_for MovieRules minor = User.new(minor: true) not_a_minor = User.new(minor: false) scary_movie = Movie.new(rating: 'R') kids_movie = Movie.new(rating: 'PG') evaluator.allowed? minor, :can_buy_the_ticket, scary_movie # false evaluator.allowed? not_a_minor, :can_buy_the_ticket, scary_movie # true evaluator.allowed? minor, :can_buy_the_ticket, kids_movie # true evaluator.allowed? not_a_minor, :can_buy_the_ticket, kids_movie # true ``` Only one more special thing... what if we want to right a rule that prevents something? ```ruby module DefaultLibraryRules def self.allowed user, book [:reserve_the_book] end end module FinesOwedRules def self.prevented user, _ if user.owes_fines? [:reserve_the_book] else [] end end end evaluator = Three.evaluator_for(DefaultLibraryRules, FinesOwedRules) deadbeat = User.new(fines: 3.0) responsible_citizen = User.new(fines: 0) evaluator.allowed? deadbeat, :reserve_the_book # false evaluator.allowed? responsible_citizen, :reserve_the_book # true ``` The "prevented" method works just like "allowed," except that it will remove the permission from any other rule's "allowed" method. The "prevented" method is the only only feature added with six. ### Errors By default, errors in a rule or calling a rule is turned off. This means that you don't have to declare "allowed" or "prevented" on your rules, and you can have clean examples like the one above. However, sometimes you may not want to run your production code through blanket rescue statements. So, you can disable this using: ```ruby module RulesMissingMethods end evaluator = Three.evaluator_for RulesMissingMethods evaluator.rescue_errors = false evaluator.allowed? nil, :watch_out # POW an error was raised ``` ### Tracing Ok, so if your security rights are broken out into many different classes, it might be helpful to which one is allowing or preventing permissions. If you'd like to take a peek behind the curtain, try the following: ```ruby Three.when_tracing do |what, details| # "what" will be :allowed/:prevented # details is a hash with the following: # subject # the subject of the rules check # target # the target, if one was provided # permissions # the permissions either allowed or prevented # rule # the rule making the check puts [what, details].inspect end ```
{ "content_hash": "2e2ae14cfd78de9f7380e153e0ac9989", "timestamp": "", "source": "github", "line_count": 186, "max_line_length": 233, "avg_line_length": 28.311827956989248, "alnum_prop": 0.7166729965818458, "repo_name": "darrencauthon/three", "id": "9672cbc42c33e4501455dcb940f9239b93e4dda6", "size": "5336", "binary": false, "copies": "1", "ref": "refs/heads/master", "path": "README.markdown", "mode": "33188", "license": "mit", "language": [ { "name": "Ruby", "bytes": "15126" } ], "symlink_target": "" }
module LLMH_ExpType where -- Haskell datatypes representing abstract syntax of LLMH types and expressions -- for LLMH allow type variables in types data Type = TypeVar String | TypeConst String | Arrow (Type, Type) | Myb Type | -- Myb t represents Maybe t List Type -- List t represents [t] deriving (Show,Eq) data Exp = Num Integer | Boolean Bool | Var String | Op (String, Exp, Exp) | Cond (Exp, Exp, Exp) | Let (String, Exp, Exp) | Lam (String, Exp) | Jst | Nthg | Nil | Cons (Exp,Exp) | MybCase (Exp, String, Exp, Exp) | ListCase (Exp, Exp, String, String, Exp) deriving Show
{ "content_hash": "be8680abbfe74e43e4b0bf4130acaf27", "timestamp": "", "source": "github", "line_count": 29, "max_line_length": 79, "avg_line_length": 25.275862068965516, "alnum_prop": 0.557980900409277, "repo_name": "jaanos/TPJ-2015-16", "id": "75377e60726084eb011aaa1b77314c89ec54432a", "size": "734", "binary": false, "copies": "1", "ref": "refs/heads/master", "path": "homework2/LLMH_ExpType.hs", "mode": "33188", "license": "mit", "language": [ { "name": "Haskell", "bytes": "49293" }, { "name": "Logos", "bytes": "3411" }, { "name": "Yacc", "bytes": "8475" } ], "symlink_target": "" }
<?xml version="1.0" encoding="utf-8"?> <!-- $Revision: 334955 $ --> <refentry xml:id="intlbreakiterator.createlineinstance" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"> <refnamediv> <refname>IntlBreakIterator::createLineInstance</refname> <refpurpose> Create break iterator for logically possible line breaks </refpurpose> </refnamediv> <refsect1 role="description"> &reftitle.description; <methodsynopsis> <modifier>public</modifier> <modifier>static</modifier> <type>ReturnType</type><methodname>IntlBreakIterator::createLineInstance</methodname> <methodparam choice="opt"><type>string</type><parameter>"locale"</parameter></methodparam> </methodsynopsis> <para> </para> &warn.undocumented.func; </refsect1> <refsect1 role="parameters"> &reftitle.parameters; <variablelist> <varlistentry> <term><parameter>"locale"</parameter></term> <listitem> <para> </para> </listitem> </varlistentry> </variablelist> </refsect1> <refsect1 role="returnvalues"> &reftitle.returnvalues; <para> </para> </refsect1> </refentry> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t indent-tabs-mode:nil sgml-parent-document:nil sgml-default-dtd-file:"~/.phpdoc/manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: vim600: syn=xml fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 -->
{ "content_hash": "6da8964e0b5671a262d2ed0bb03978e3", "timestamp": "", "source": "github", "line_count": 69, "max_line_length": 144, "avg_line_length": 23.144927536231883, "alnum_prop": 0.715090795241077, "repo_name": "mziyut/.vim", "id": "c409b41213a64b23bc7fbeeb4e34fc0447a6b802", "size": "1597", "binary": false, "copies": "3", "ref": "refs/heads/master", "path": "dict/.neocomplete-php/phpdoc/en/reference/intl/intlbreakiterator/createlineinstance.xml", "mode": "33188", "license": "mit", "language": [ { "name": "HTML", "bytes": "2223" }, { "name": "Ruby", "bytes": "939" }, { "name": "Shell", "bytes": "582" }, { "name": "Vim script", "bytes": "22415" } ], "symlink_target": "" }
require 'rails/generators' require 'rails/generators/active_record' module Resort # Module containing Resort generators module Generators # Rails generator to add a migration for Resort class MigrationGenerator < ActiveRecord::Generators::Base # Implement the required interface for `Rails::Generators::Migration`. # Taken from `ActiveRecord` code. # @see http://github.com/rails/rails/blob/master/activerecord/lib/generators/active_record.rb def self.next_migration_number(dirname) if ActiveRecord::Base.timestamped_migrations Time.now.utc.strftime("%Y%m%d%H%M%S") else "%.3d" % (current_migration_number(dirname) + 1) end end desc "Creates a Resort migration." source_root File.expand_path("../templates", __FILE__) # Copies a migration file adding resort fields to a given model def copy_migration_file migration_template 'migration.rb', "db/migrate/add_resort_fields_to_#{table_name.pluralize}.rb" end end end end
{ "content_hash": "c8653ebe7bc716d45086cfcebc1ed3e8", "timestamp": "", "source": "github", "line_count": 30, "max_line_length": 103, "avg_line_length": 35.06666666666667, "alnum_prop": 0.6825095057034221, "repo_name": "YettaWeipert/resort", "id": "46a5ed97fd5cb744f31efd12bcebf0aea8157d87", "size": "1052", "binary": false, "copies": "3", "ref": "refs/heads/master", "path": "lib/generators/active_record/resort_generator.rb", "mode": "33188", "license": "mit", "language": [ { "name": "Ruby", "bytes": "28312" } ], "symlink_target": "" }
<?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"> <item android:id="@+id/show_user_photo" android:title="@string/download_display_current" android:checkable="true" app:actionViewClass="android.widget.CheckBox" app:showAsAction="never"/> </menu>
{ "content_hash": "1414341303a7c377a1cbfb8fa3adacd2", "timestamp": "", "source": "github", "line_count": 10, "max_line_length": 64, "avg_line_length": 39.2, "alnum_prop": 0.673469387755102, "repo_name": "mingdroid/tumbviewer", "id": "0dcf94709fa1013abc4d10b9dff3b76f8e7e7289", "size": "392", "binary": false, "copies": "1", "ref": "refs/heads/master", "path": "app/src/main/res/menu/menu_download_photo.xml", "mode": "33188", "license": "apache-2.0", "language": [ { "name": "Java", "bytes": "409625" } ], "symlink_target": "" }
# go-enum [![Actions Status](https://github.com/abice/go-enum/actions/workflows/build_and_test.yml/badge.svg)](https://github.com/abice/go-enum/actions/workflows/build_and_test.yml) [![Go Report Card](https://goreportcard.com/badge/github.com/abice/go-enum)](https://goreportcard.com/report/github.com/abice/go-enum) [![Coverage Status](https://coveralls.io/repos/github/abice/go-enum/badge.svg)](https://coveralls.io/github/abice/go-enum) [![GoDoc](https://godoc.org/github.com/abice/go-enum?status.svg)](https://godoc.org/github.com/abice/go-enum) [![Mentioned in Awesome Go](https://awesome.re/mentioned-badge.svg)](https://github.com/avelino/awesome-go) An enum generator for go ## How it works go-enum will take a commented type declaration like this: ```go // ENUM(jpeg, jpg, png, tiff, gif) type ImageType int ``` and generate a file with the iota definition along various optional niceties that you may need: ```go const ( // ImageTypeJpeg is a ImageType of type Jpeg. ImageTypeJpeg ImageType = iota // ImageTypeJpg is a ImageType of type Jpg. ImageTypeJpg // ImageTypePng is a ImageType of type Png. ImageTypePng // ImageTypeTiff is a ImageType of type Tiff. ImageTypeTiff // ImageTypeGif is a ImageType of type Gif. ImageTypeGif ) // String implements the Stringer interface. func (x ImageType) String() string // ParseImageType attempts to convert a string to a ImageType. func ParseImageType(name string) (ImageType, error) // MarshalText implements the text marshaller method. func (x ImageType) MarshalText() ([]byte, error) // UnmarshalText implements the text unmarshaller method. func (x *ImageType) UnmarshalText(text []byte) error ``` **Fear not the fact that the `MarshalText` and `UnmarshalText` are generated rather than JSON methods... they will still be utilized by the default JSON encoding methods.** If you find that the options given are not adequate for your use case, there is an option to add a custom template (`-t` flag) to the processing engine so that your custom code can be created! ## Now with string typed enums ```go // ENUM(pending, running, completed, failed) type StrState string ``` ```go const ( // StrStatePending is a StrState of type pending. StrStatePending StrState = "pending" // StrStateRunning is a StrState of type running. StrStateRunning StrState = "running" // StrStateCompleted is a StrState of type completed. StrStateCompleted StrState = "completed" // StrStateFailed is a StrState of type failed. StrStateFailed StrState = "failed" ) ``` If you would like to get integer values in sql, but strings elsewhere, you can assign an int value in the declaration like always, and specify the `--sqlint` flag. Those values will be then used to convey the int value to sql, while allowing you to use only strings elsewhere. This might be helpful for things like swagger docs where you want the same type being used on the api layer, as you do in the sql layer, and not have swagger assume that your enumerations are integers, but are in fact strings! ```go // swagger:enum StrState // ENUM(pending, running, completed, failed) type StrState string ``` ## Goal The goal of go-enum is to create an easy to use enum generator that will take a decorated type declaration like `type EnumName int` and create the associated constant values and funcs that will make life a little easier for adding new values. It's not perfect, but I think it's useful. I took the output of the [Stringer](https://godoc.org/golang.org/x/tools/cmd/stringer) command as the `String()` method, and added a way to parse a string value. ## Installation You can now download a release directly from github and use that for generating your enums! (Thanks to [GoReleaser](https://github.com/goreleaser/goreleaser-action)) I did not specify any overrides on the release binary names, so `uname -s` and `uname -m` should provide the correct version of the binary for your distro. ```shell curl -fsSL "https://github.com/abice/go-enum/releases/download/$(GO_ENUM_VERSION)/go-enum_$(uname -s)_$(uname -m)" -o go-enum ``` ## Adding it to your project ### Using go generate 1. Add a go:generate line to your file like so... `//go:generate go-enum --marshal` 1. Run go generate like so `go generate ./...` 1. Enjoy your newly created Enumeration! ### Using Makefile If you prefer makefile stuff, you can always do something like this: ```Makefile STANDARD_ENUMS = ./_example/animal_enum.go \ ./_example/color_enum.go NULLABLE_ENUMS = ./_example/sql_enum.go $(STANDARD_ENUMS): GO_ENUM_FLAGS=--nocase --marshal --names --ptr $(NULLABLE_ENUMS): GO_ENUM_FLAGS=--nocase --marshal --names --sqlnullint --ptr enums: $(STANDARD_ENUMS) $(NULLABLE_ENUMS) # The generator statement for go enum files. Files that invalidate the # enum file: source file, the binary itself, and this file (in case you want to generate with different flags) %_enum.go: %.go $(GOENUM) Makefile $(GOENUM) -f $*.go $(GO_ENUM_FLAGS) ``` ## Command options ``` shell go-enum --help NAME: go-enum - An enum generator for go USAGE: go-enum [global options] [arguments...] VERSION: x.y.z GLOBAL OPTIONS: --file value, -f value The file(s) to generate enums. Use more than one flag for more files. --noprefix Prevents the constants generated from having the Enum as a prefix. (default: false) --lower Adds lowercase variants of the enum strings for lookup. (default: false) --nocase Adds case insensitive parsing to the enumeration (forces lower flag). (default: false) --marshal Adds text (and inherently json) marshalling functions. (default: false) --sql Adds SQL database scan and value functions. (default: false) --flag Adds golang flag functions. (default: false) --prefix value Replaces the prefix with a user one. --names Generates a 'Names() []string' function, and adds the possible enum values in the error response during parsing (default: false) --nocamel Removes the snake_case to CamelCase name changing (default: false) --ptr Adds a pointer method to get a pointer from const values (default: false) --sqlnullint Adds a Null{{ENUM}} type for marshalling a nullable int value to sql (default: false) --sqlnullstr Adds a Null{{ENUM}} type for marshalling a nullable string value to sql. If sqlnullint is specified too, it will be Null{{ENUM}}Str (default: false) --template value, -t value Additional template file(s) to generate enums. Use more than one flag for more files. Templates will be executed in alphabetical order. --alias value, -a value Adds or replaces aliases for a non alphanumeric value that needs to be accounted for. [Format should be "key:value,key2:value2", or specify multiple entries, or both!] --help, -h show help (default: false) --version, -v print the version (default: false) ``` ### Syntax The parser looks for comments on your type defs and parse the enum declarations from it. The parser will look for `ENUM(` and continue to look for comma separated values until it finds a `)`. You can put values on the same line, or on multiple lines.\ If you need to have a specific value jump in the enum, you can now specify that by adding `=numericValue` to the enum declaration. Keep in mind, this resets the data for all following values. So if you specify `50` in the middle of an enum, each value after that will be `51, 52, 53...` #### Comments You can use comments inside enum that start with `//`\ The comment must be at the end of the same line as the comment value, only then it will be added as a comment to the generated constant. ```go // Commented is an enumeration of commented values /* ENUM( value1 // Commented value 1 value2 value3 // Commented value 3 ) */ type Commented int ``` The generated comments in code will look something like: ```go ... const ( // CommentedValue1 is a Commented of type Value1 // Commented value 1 CommentedValue1 Commented = iota // CommentedValue2 is a Commented of type Value2 CommentedValue2 // CommentedValue3 is a Commented of type Value3 // Commented value 3 CommentedValue3 ) ... ``` #### Example There are a few examples in the `_example` [directory](_example). I've included one here for easy access, but can't guarantee it's up to date. ``` go // Color is an enumeration of colors that are allowed. /* ENUM( Black, White, Red Green = 33 // Green starts with 33 */ // Blue // grey= // yellow // blue-green // red-orange // yellow_green // red-orange-blue // ) type Color int32 ``` The generated code will look something like: ``` go // Code generated by go-enum DO NOT EDIT. // Version: example // Revision: example // Build Date: example // Built By: example package example import ( "fmt" "strings" ) const ( // ColorBlack is a Color of type Black. ColorBlack Color = iota // ColorWhite is a Color of type White. ColorWhite // ColorRed is a Color of type Red. ColorRed // ColorGreen is a Color of type Green. // Green starts with 33 ColorGreen Color = iota + 30 // ColorBlue is a Color of type Blue. ColorBlue // ColorGrey is a Color of type Grey. ColorGrey // ColorYellow is a Color of type Yellow. ColorYellow // ColorBlueGreen is a Color of type Blue-Green. ColorBlueGreen // ColorRedOrange is a Color of type Red-Orange. ColorRedOrange // ColorYellowGreen is a Color of type Yellow_green. ColorYellowGreen // ColorRedOrangeBlue is a Color of type Red-Orange-Blue. ColorRedOrangeBlue ) const _ColorName = "BlackWhiteRedGreenBluegreyyellowblue-greenred-orangeyellow_greenred-orange-blue" var _ColorMap = map[Color]string{ ColorBlack: _ColorName[0:5], ColorWhite: _ColorName[5:10], ColorRed: _ColorName[10:13], ColorGreen: _ColorName[13:18], ColorBlue: _ColorName[18:22], ColorGrey: _ColorName[22:26], ColorYellow: _ColorName[26:32], ColorBlueGreen: _ColorName[32:42], ColorRedOrange: _ColorName[42:52], ColorYellowGreen: _ColorName[52:64], ColorRedOrangeBlue: _ColorName[64:79], } // String implements the Stringer interface. func (x Color) String() string { if str, ok := _ColorMap[x]; ok { return str } return fmt.Sprintf("Color(%d)", x) } var _ColorValue = map[string]Color{ _ColorName[0:5]: ColorBlack, strings.ToLower(_ColorName[0:5]): ColorBlack, _ColorName[5:10]: ColorWhite, strings.ToLower(_ColorName[5:10]): ColorWhite, _ColorName[10:13]: ColorRed, strings.ToLower(_ColorName[10:13]): ColorRed, _ColorName[13:18]: ColorGreen, strings.ToLower(_ColorName[13:18]): ColorGreen, _ColorName[18:22]: ColorBlue, strings.ToLower(_ColorName[18:22]): ColorBlue, _ColorName[22:26]: ColorGrey, strings.ToLower(_ColorName[22:26]): ColorGrey, _ColorName[26:32]: ColorYellow, strings.ToLower(_ColorName[26:32]): ColorYellow, _ColorName[32:42]: ColorBlueGreen, strings.ToLower(_ColorName[32:42]): ColorBlueGreen, _ColorName[42:52]: ColorRedOrange, strings.ToLower(_ColorName[42:52]): ColorRedOrange, _ColorName[52:64]: ColorYellowGreen, strings.ToLower(_ColorName[52:64]): ColorYellowGreen, _ColorName[64:79]: ColorRedOrangeBlue, strings.ToLower(_ColorName[64:79]): ColorRedOrangeBlue, } // ParseColor attempts to convert a string to a Color func ParseColor(name string) (Color, error) { if x, ok := _ColorValue[name]; ok { return x, nil } return Color(0), fmt.Errorf("%s is not a valid Color", name) } func (x Color) Ptr() *Color { return &x } // MarshalText implements the text marshaller method func (x Color) MarshalText() ([]byte, error) { return []byte(x.String()), nil } // UnmarshalText implements the text unmarshaller method func (x *Color) UnmarshalText(text []byte) error { name := string(text) tmp, err := ParseColor(name) if err != nil { return err } *x = tmp return nil } ```
{ "content_hash": "535a281b63a1756258e997413b49ac30", "timestamp": "", "source": "github", "line_count": 344, "max_line_length": 288, "avg_line_length": 35.593023255813954, "alnum_prop": 0.7011597517151258, "repo_name": "abice/go-enum", "id": "d7cda7e81c9d853927105165d77ed300bb3b7e4b", "size": "12244", "binary": false, "copies": "1", "ref": "refs/heads/master", "path": "README.md", "mode": "33188", "license": "mit", "language": [ { "name": "Go", "bytes": "151776" }, { "name": "Makefile", "bytes": "2614" }, { "name": "Shell", "bytes": "42" } ], "symlink_target": "" }
namespace DragonSpark.Application.Security.Identity.Authentication; public interface IValidationServices : IAdapters, IAuthenticationValidation {}
{ "content_hash": "3db6be3a7983625e8431533062bed43f", "timestamp": "", "source": "github", "line_count": 3, "max_line_length": 78, "avg_line_length": 49.333333333333336, "alnum_prop": 0.8716216216216216, "repo_name": "DragonSpark/Framework", "id": "109a4e84a83874c67eb0241413d7c85a9760ff1b", "size": "150", "binary": false, "copies": "1", "ref": "refs/heads/master", "path": "DragonSpark.Application/Security/Identity/Authentication/IValidationServices.cs", "mode": "33188", "license": "mit", "language": [ { "name": "C#", "bytes": "2079497" }, { "name": "CSS", "bytes": "673" }, { "name": "HTML", "bytes": "103546" }, { "name": "JavaScript", "bytes": "1311" }, { "name": "TypeScript", "bytes": "2495" } ], "symlink_target": "" }
using Avalonia.Data; namespace Avalonia.PropertyStore { /// <summary> /// Represents an untyped interface to <see cref="IValue{T}"/>. /// </summary> internal interface IValue { BindingPriority Priority { get; } Optional<object?> GetValue(); void Start(); void RaiseValueChanged( IValueSink sink, IAvaloniaObject owner, AvaloniaProperty property, Optional<object?> oldValue, Optional<object?> newValue); } /// <summary> /// Represents an object that can act as an entry in a <see cref="ValueStore"/>. /// </summary> /// <typeparam name="T">The property type.</typeparam> internal interface IValue<T> : IValue { Optional<T> GetValue(BindingPriority maxPriority = BindingPriority.Animation); } }
{ "content_hash": "b0aed281a9ee20d0f552613198102516", "timestamp": "", "source": "github", "line_count": 29, "max_line_length": 86, "avg_line_length": 29.24137931034483, "alnum_prop": 0.6061320754716981, "repo_name": "jkoritzinsky/Perspex", "id": "a4ec06e64e7a5fa4a757cc091175079bdc476e80", "size": "850", "binary": false, "copies": "2", "ref": "refs/heads/master", "path": "src/Avalonia.Base/PropertyStore/IValue.cs", "mode": "33188", "license": "mit", "language": [ { "name": "C#", "bytes": "2991416" }, { "name": "PowerShell", "bytes": "4831" }, { "name": "Smalltalk", "bytes": "49324" } ], "symlink_target": "" }
package us.nineworlds.serenity.core.subtitles.formats; import java.io.IOException; import java.io.InputStream; public interface TimedTextFileFormat { /** * This methods receives the path to a file, parses it, and returns a TimedTextObject * * @param path String that contains the path to the file * @return TimedTextObject representing the parsed file * @throws IOException when having trouble reading the file from the given path */ TimedTextObject parseFile(String fileName, InputStream is) throws IOException, FatalParsingException; /** * This method transforms a given TimedTextObject into a formated subtitle file * * @param tto the object to transform into a file * @return NULL if the given TimedTextObject has not been built first, * or String[] where each String is at least a line, if size is 2, then the file has at least two lines. * or byte[] in case the file is a binary (as is the case of STL format) */ Object toFile(TimedTextObject tto); }
{ "content_hash": "72dcff9777e38a71384d9449684e91dc", "timestamp": "", "source": "github", "line_count": 29, "max_line_length": 107, "avg_line_length": 35.62068965517241, "alnum_prop": 0.7250726040658277, "repo_name": "0359xiaodong/serenity-android", "id": "cb04fe5b112a1ab8532feb2e3ec5df75cff33f81", "size": "2589", "binary": false, "copies": "3", "ref": "refs/heads/master", "path": "subtitle-converter/src/main/java/us/nineworlds/serenity/core/subtitles/formats/TimedTextFileFormat.java", "mode": "33188", "license": "mit", "language": [], "symlink_target": "" }
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <android.support.design.widget.AppBarLayout android:id="@+id/appbar" android:layout_width="match_parent" android:layout_height="wrap_content" android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" android:background="?attr/colorPrimary" app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/> </android.support.design.widget.AppBarLayout> <ScrollView android:layout_width="match_parent" android:layout_height="match_parent"> <RelativeLayout android:id="@+id/rlEdit" android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="@dimen/activity_horizontal_margin"> <EditText android:id="@+id/etMark" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="@string/mark" android:imeOptions="actionDone" android:inputType="numberDecimal" android:selectAllOnFocus="true"/> <View android:id="@+id/vDivider" android:layout_width="match_parent" android:layout_height="1dp" android:layout_below="@id/etMark" android:layout_marginBottom="@dimen/activity_horizontal_margin" android:layout_marginTop="@dimen/activity_horizontal_margin" android:background="@color/divider"/> <ImageView android:id="@+id/ivWeight" android:layout_width="wrap_content" android:layout_height="30dp" android:layout_below="@id/vDivider" android:layout_marginRight="@dimen/widget_margin_large" android:layout_marginTop="9dp" android:adjustViewBounds="true" android:scaleType="fitCenter" android:src="@drawable/ic_weight" android:tint="@color/red_dark"/> <EditText android:id="@+id/etWeight" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@id/vDivider" android:layout_toRightOf="@id/ivWeight" android:hint="@string/weighting" android:imeOptions="actionDone" android:inputType="numberDecimal" android:selectAllOnFocus="true" android:text="1.0"/> <View android:id="@+id/vDivider2" android:layout_width="match_parent" android:layout_height="1dp" android:layout_below="@id/etWeight" android:layout_marginBottom="@dimen/activity_horizontal_margin" android:layout_marginTop="@dimen/activity_horizontal_margin" android:layout_toRightOf="@id/ivWeight" android:background="@color/divider"/> <ImageView android:id="@+id/ivDate" android:layout_width="wrap_content" android:layout_height="30dp" android:layout_below="@id/vDivider2" android:layout_marginRight="@dimen/widget_margin_large" android:layout_marginTop="9dp" android:adjustViewBounds="true" android:scaleType="fitCenter" android:src="@drawable/ic_calendar" android:tint="@color/red_dark"/> <EditText android:id="@+id/etDate" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@id/vDivider2" android:layout_toRightOf="@id/ivDate" android:hint="@string/date" android:imeOptions="actionDone" android:inputType="date"/> <TextView android:id="@+id/tvSem" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/etDate" android:layout_marginLeft="5dp" android:layout_marginTop="@dimen/widget_margin" android:layout_toRightOf="@id/ivDate"/> </RelativeLayout> </ScrollView> </LinearLayout>
{ "content_hash": "6f7deee00a2a20840d6042f3f48462b0", "timestamp": "", "source": "github", "line_count": 117, "max_line_length": 79, "avg_line_length": 41.85470085470085, "alnum_prop": 0.5609556871554012, "repo_name": "martindisch/Kantidroid", "id": "fa713b9fa61b9310bc89a3cb420d8527eefff08f", "size": "4897", "binary": false, "copies": "1", "ref": "refs/heads/master", "path": "app/src/main/res/layout/fachview_edit_mark_dialog.xml", "mode": "33188", "license": "mit", "language": [ { "name": "HTML", "bytes": "193" }, { "name": "Java", "bytes": "284729" } ], "symlink_target": "" }
<?php namespace common\models; use Yii; /** * This is the model class for table "tbl_libs_showroom". * * @property string $sh_id * @property string $sh_name * @property string $sh_address * * @property Cars[] $cars * @property Users $shUser * @property UserShowroom[] $userShowrooms */ class Showroom extends \yii\db\ActiveRecord { public $users; /** * @inheritdoc */ public static function tableName() { return 'tbl_libs_showroom'; } /** * @inheritdoc */ public function rules() { return [ [['sh_name', 'sh_address'], 'required'], [['sh_name', 'sh_address'], 'string', 'max' => 100], [['users'], 'safe'], ]; } /** * @inheritdoc */ public function attributeLabels() { return [ 'sh_id' => 'Sh ID', 'sh_name' => 'Име на автосалон', 'sh_address' => 'Адрес', ]; } /** * @return \yii\db\ActiveQuery */ public function getCars() { return $this->hasMany(Cars::className(), ['car_sh_id' => 'sh_id']); } /** * @return \yii\db\ActiveQuery */ public function getUserShowrooms() { return $this->hasMany(UserShowroom::className(), ['id_showroom' => 'sh_id']); } }
{ "content_hash": "447c3c0501a07adb112927306727e473", "timestamp": "", "source": "github", "line_count": 70, "max_line_length": 85, "avg_line_length": 19.02857142857143, "alnum_prop": 0.509009009009009, "repo_name": "rosislavm/automanager", "id": "41c449da16e91df7446fdfce8e06afd035f0626e", "size": "1351", "binary": false, "copies": "1", "ref": "refs/heads/automanager_prj", "path": "common/models/Showroom.php", "mode": "33188", "license": "bsd-3-clause", "language": [ { "name": "Batchfile", "bytes": "1541" }, { "name": "CSS", "bytes": "10960" }, { "name": "JavaScript", "bytes": "61071" }, { "name": "PHP", "bytes": "354671" } ], "symlink_target": "" }
package org.ovirt.mobile.movirt.facade; import android.content.Context; import android.content.Intent; import android.database.Cursor; import org.androidannotations.annotations.Bean; import org.androidannotations.annotations.EBean; import org.ovirt.mobile.movirt.model.EntityMapper; import org.ovirt.mobile.movirt.model.Host; import org.ovirt.mobile.movirt.model.trigger.HostTriggerResolver; import org.ovirt.mobile.movirt.model.trigger.Trigger; import org.ovirt.mobile.movirt.rest.OVirtClient; import org.ovirt.mobile.movirt.sync.SyncAdapter; import org.ovirt.mobile.movirt.ui.hosts.HostDetailActivity_; import java.util.List; @EBean public class HostFacade implements EntityFacade<Host> { @Bean SyncAdapter syncAdapter; @Bean HostTriggerResolver hostTriggerResolver; @Override public Host mapFromCursor(Cursor cursor) { return EntityMapper.forEntity(Host.class).fromCursor(cursor); } @Override public List<Trigger<Host>> getTriggers(Host entity) { return hostTriggerResolver.getTriggers(entity); } @Override public Intent getDetailIntent(Host entity, Context context) { Intent intent = new Intent(context, HostDetailActivity_.class); intent.setData(entity.getUri()); return intent; } @Override public void sync(String id, OVirtClient.Response<Host> response) { syncAdapter.syncHost(id, response); } }
{ "content_hash": "973a77de49b67953ced789a16d386e5e", "timestamp": "", "source": "github", "line_count": 49, "max_line_length": 71, "avg_line_length": 29.081632653061224, "alnum_prop": 0.7529824561403509, "repo_name": "jelkosz/moVirt", "id": "786ed2d470699f4a79cb7105097985de99d12f64", "size": "1425", "binary": false, "copies": "1", "ref": "refs/heads/master", "path": "moVirt/src/main/java/org/ovirt/mobile/movirt/facade/HostFacade.java", "mode": "33188", "license": "apache-2.0", "language": [ { "name": "Batchfile", "bytes": "86" }, { "name": "Java", "bytes": "346118" } ], "symlink_target": "" }
<?xml version="1.0" encoding="UTF-8"?> <billStatus> <bill> <originChamber>Senate</originChamber> <billNumber>534</billNumber> <notes /> <committees> <billCommittees> <item> <type>Standing</type> <systemCode>ssju00</systemCode> <subcommittees /> <chamber>Senate</chamber> <name>Judiciary Committee</name> <activities> <item> <date>2017-06-08T17:28:30Z</date> <name>Reported by</name> </item> <item> <date>2017-05-11T14:00:34Z</date> <name>Markup by</name> </item> <item> <date>2017-03-28T14:00:00Z</date> <name>Hearings by</name> </item> <item> <date>2017-03-06T22:44:45Z</date> <name>Referred to</name> </item> </activities> </item> </billCommittees> </committees> <calendarNumbers> <item> <number>0121</number> <calendar>Senate Calendar of Business</calendar> </item> </calendarNumbers> <laws /> <subjects> <billSubjects> <policyArea> <name>Crime and Law Enforcement</name> </policyArea> <legislativeSubjects> <item> <name>Athletes</name> </item> <item> <name>Civil actions and liability</name> </item> <item> <name>Correctional facilities and imprisonment</name> </item> <item> <name>Crime victims</name> </item> <item> <name>Crimes against children</name> </item> <item> <name>Criminal justice information and records</name> </item> <item> <name>Domestic violence and child abuse</name> </item> <item> <name>Fraud offenses and financial crimes</name> </item> <item> <name>Human trafficking</name> </item> <item> <name>Jurisdiction and venue</name> </item> <item> <name>Juvenile crime and gang violence</name> </item> <item> <name>Olympic games</name> </item> <item> <name>Pornography</name> </item> <item> <name>Sex offenses</name> </item> </legislativeSubjects> </billSubjects> </subjects> <summaries> <billSummaries /> </summaries> <relatedBills> <item> <latestTitle>Protecting Young Victims from Sexual Abuse Act of 2017</latestTitle> <latestAction> <text>Received in the Senate and Read twice and referred to the Committee on the Judiciary.</text> <actionDate>2017-06-05</actionDate> </latestAction> <relationshipDetails> <item> <identifiedBy>House</identifiedBy> <type>Related bill</type> </item> <item> <identifiedBy>CRS</identifiedBy> <type>Related bill</type> </item> </relationshipDetails> <type>HR</type> <congress>115</congress> <number>1973</number> </item> </relatedBills> <titles> <item> <chamberName>Senate</chamberName> <title>Protecting Young Victims from Sexual Abuse Act of 2017</title> <titleType>(Extracted from GPO) Short Titles as Reported to Senate</titleType> <chamberCode>S</chamberCode> <parentTitleType /> </item> <item> <chamberName /> <title>Protecting Young Victims from Sexual Abuse Act of 2017</title> <titleType>(Extracted from GPO) Short Titles as Introduced</titleType> <chamberCode /> <parentTitleType /> </item> <item> <chamberName>Senate</chamberName> <title>Protecting Young Victims from Sexual Abuse Act of 2017</title> <titleType>Short Titles as Reported to Senate</titleType> <chamberCode>S</chamberCode> <parentTitleType>Short Titles Senate</parentTitleType> </item> <item> <chamberName /> <title>Protecting Young Victims from Sexual Abuse Act of 2017</title> <titleType>Short Titles as Introduced</titleType> <chamberCode /> <parentTitleType /> </item> <item> <chamberName /> <title>A bill to prevent the sexual abuse of minors and amateur athletes by requiring the prompt reporting of sexual abuse to law enforcement authorities, and for other purposes.</title> <titleType>Official Title as Introduced</titleType> <chamberCode /> <parentTitleType /> </item> <item> <chamberName /> <title>Protecting Young Victims from Sexual Abuse Act of 2017</title> <titleType>Display Title</titleType> <chamberCode /> <parentTitleType /> </item> </titles> <version>1.0.0</version> <congress>115</congress> <createDate>2017-03-07T05:14:52Z</createDate> <committeeReports /> <billType>S</billType> <updateDate>2017-08-04T07:36:17Z</updateDate> <actions> <actionTypeCounts> <orderedReported>1</orderedReported> <placedOnCalendarGeneralOrders>1</placedOnCalendarGeneralOrders> <introducedInSenate>1</introducedInSenate> <hearingsHeld>1</hearingsHeld> <referredToCommittee>1</referredToCommittee> <reportedToSenate>2</reportedToSenate> </actionTypeCounts> <item> <actionDate>2017-06-08</actionDate> <committee /> <links /> <sourceSystem> <name>Senate</name> <code>0</code> </sourceSystem> <text>Placed on Senate Legislative Calendar under General Orders. Calendar No. 121.</text> <type>Calendars</type> </item> <item> <actionDate>2017-06-08</actionDate> <committee> <name>Judiciary Committee</name> <systemCode>ssju00</systemCode> </committee> <links /> <sourceSystem> <name>Senate</name> <code>0</code> </sourceSystem> <text>Committee on the Judiciary. Reported by Senator Grassley with an amendment in the nature of a substitute. Without written report.</text> <type>Committee</type> </item> <item> <sourceSystem> <name>Library of Congress</name> <code>9</code> </sourceSystem> <actionCode>14000</actionCode> <links /> <actionDate>2017-06-08</actionDate> <type>Committee</type> <committee> <name>Judiciary Committee</name> <systemCode>ssju00</systemCode> </committee> <text>Committee on the Judiciary. Reported by Senator Grassley with an amendment in the nature of a substitute. Without written report.</text> </item> <item> <actionDate>2017-05-11</actionDate> <committee> <name>Judiciary Committee</name> <systemCode>ssju00</systemCode> </committee> <links /> <sourceSystem> <name>Senate</name> <code>0</code> </sourceSystem> <text>Committee on the Judiciary. Ordered to be reported with an amendment in the nature of a substitute favorably.</text> <type>Committee</type> </item> <item> <actionDate>2017-03-28</actionDate> <committee> <name>Judiciary Committee</name> <systemCode>ssju00</systemCode> </committee> <links /> <sourceSystem> <name>Senate</name> <code>0</code> </sourceSystem> <text>Committee on the Judiciary. Hearings held.</text> <type>Committee</type> </item> <item> <actionDate>2017-03-06</actionDate> <committee> <name>Judiciary Committee</name> <systemCode>ssju00</systemCode> </committee> <links /> <sourceSystem> <name>Senate</name> <code>0</code> </sourceSystem> <text>Read twice and referred to the Committee on the Judiciary.</text> <type>IntroReferral</type> </item> <item> <sourceSystem> <name>Library of Congress</name> <code>9</code> </sourceSystem> <actionCode>10000</actionCode> <links /> <actionDate>2017-03-06</actionDate> <type>IntroReferral</type> <committee /> <text>Introduced in Senate</text> </item> <actionByCounts> <senate>7</senate> </actionByCounts> </actions> <cosponsors> <item> <isOriginalCosponsor>True</isOriginalCosponsor> <sponsorshipDate>2017-03-06</sponsorshipDate> <fullName>Sen. Collins, Susan M. [R-ME]</fullName> <bioguideId>C001035</bioguideId> <middleName>MARGARET</middleName> <identifiers> <gpoId>8291</gpoId> <bioguideId>C001035</bioguideId> <lisID>1541</lisID> </identifiers> <sponsorshipWithdrawnDate /> <party>R</party> <firstName>SUSAN</firstName> <lastName>COLLINS</lastName> <state>ME</state> </item> <item> <isOriginalCosponsor>True</isOriginalCosponsor> <sponsorshipDate>2017-03-06</sponsorshipDate> <fullName>Sen. Grassley, Chuck [R-IA]</fullName> <bioguideId>G000386</bioguideId> <middleName>ERNEST</middleName> <identifiers> <bioguideId>G000386</bioguideId> <gpoId>8316</gpoId> <lisID>457</lisID> </identifiers> <sponsorshipWithdrawnDate /> <party>R</party> <firstName>CHARLES</firstName> <lastName>GRASSLEY</lastName> <state>IA</state> </item> <item> <isOriginalCosponsor>True</isOriginalCosponsor> <sponsorshipDate>2017-03-06</sponsorshipDate> <fullName>Sen. Nelson, Bill [D-FL]</fullName> <bioguideId>N000032</bioguideId> <middleName>WILLIAM</middleName> <identifiers> <gpoId>8236</gpoId> <bioguideId>N000032</bioguideId> <lisID>859</lisID> </identifiers> <sponsorshipWithdrawnDate /> <party>D</party> <firstName>CLARENCE</firstName> <lastName>NELSON</lastName> <state>FL</state> </item> <item> <isOriginalCosponsor>True</isOriginalCosponsor> <sponsorshipDate>2017-03-06</sponsorshipDate> <fullName>Sen. Flake, Jeff [R-AZ]</fullName> <bioguideId>F000444</bioguideId> <middleName /> <identifiers> <gpoId>7803</gpoId> <lisID>1633</lisID> <bioguideId>F000444</bioguideId> </identifiers> <sponsorshipWithdrawnDate /> <party>R</party> <firstName>JEFF</firstName> <lastName>FLAKE</lastName> <state>AZ</state> </item> <item> <isOriginalCosponsor>True</isOriginalCosponsor> <sponsorshipDate>2017-03-06</sponsorshipDate> <fullName>Sen. Donnelly, Joe [D-IN]</fullName> <bioguideId>D000607</bioguideId> <middleName /> <identifiers> <gpoId>7941</gpoId> <bioguideId>D000607</bioguideId> <lisID>1850</lisID> </identifiers> <sponsorshipWithdrawnDate /> <party>D</party> <firstName>Joe</firstName> <lastName>Donnelly</lastName> <state>IN</state> </item> <item> <isOriginalCosponsor>True</isOriginalCosponsor> <sponsorshipDate>2017-03-06</sponsorshipDate> <fullName>Sen. Rubio, Marco [R-FL]</fullName> <bioguideId>R000595</bioguideId> <middleName /> <identifiers> <bioguideId>R000595</bioguideId> <gpoId>8242</gpoId> <lisID>2084</lisID> </identifiers> <sponsorshipWithdrawnDate /> <party>R</party> <firstName>Marco</firstName> <lastName>Rubio</lastName> <state>FL</state> </item> <item> <isOriginalCosponsor>True</isOriginalCosponsor> <sponsorshipDate>2017-03-06</sponsorshipDate> <fullName>Sen. McCaskill, Claire [D-MO]</fullName> <bioguideId>M001170</bioguideId> <middleName /> <identifiers> <lisID>1820</lisID> <bioguideId>M001170</bioguideId> <gpoId>8252</gpoId> </identifiers> <sponsorshipWithdrawnDate /> <party>D</party> <firstName>Claire</firstName> <lastName>McCaskill</lastName> <state>MO</state> </item> <item> <isOriginalCosponsor>True</isOriginalCosponsor> <sponsorshipDate>2017-03-06</sponsorshipDate> <fullName>Sen. Ernst, Joni [R-IA]</fullName> <bioguideId>E000295</bioguideId> <middleName /> <identifiers> <gpoId /> <lisID>2283</lisID> <bioguideId>E000295</bioguideId> </identifiers> <sponsorshipWithdrawnDate /> <party>R</party> <firstName>Joni</firstName> <lastName>Ernst</lastName> <state>IA</state> </item> <item> <isOriginalCosponsor>True</isOriginalCosponsor> <sponsorshipDate>2017-03-06</sponsorshipDate> <fullName>Sen. Klobuchar, Amy [D-MN]</fullName> <bioguideId>K000367</bioguideId> <middleName /> <identifiers> <lisID>1826</lisID> <bioguideId>K000367</bioguideId> <gpoId>8249</gpoId> </identifiers> <sponsorshipWithdrawnDate /> <party>D</party> <firstName>Amy</firstName> <lastName>Klobuchar</lastName> <state>MN</state> </item> <item> <isOriginalCosponsor>True</isOriginalCosponsor> <sponsorshipDate>2017-03-06</sponsorshipDate> <fullName>Sen. Shaheen, Jeanne [D-NH]</fullName> <bioguideId>S001181</bioguideId> <middleName /> <identifiers> <lisID>1901</lisID> <bioguideId>S001181</bioguideId> <gpoId>8276</gpoId> </identifiers> <sponsorshipWithdrawnDate /> <party>D</party> <firstName>Jeanne</firstName> <lastName>Shaheen</lastName> <state>NH</state> </item> <item> <isOriginalCosponsor>True</isOriginalCosponsor> <sponsorshipDate>2017-03-06</sponsorshipDate> <fullName>Sen. Blumenthal, Richard [D-CT]</fullName> <bioguideId>B001277</bioguideId> <middleName /> <identifiers> <gpoId>8332</gpoId> <bioguideId>B001277</bioguideId> <lisID>2076</lisID> </identifiers> <sponsorshipWithdrawnDate /> <party>D</party> <firstName>Richard</firstName> <lastName>Blumenthal</lastName> <state>CT</state> </item> <item> <isOriginalCosponsor>True</isOriginalCosponsor> <sponsorshipDate>2017-03-06</sponsorshipDate> <fullName>Sen. Warren, Elizabeth [D-MA]</fullName> <bioguideId>W000817</bioguideId> <middleName>A.</middleName> <identifiers> <gpoId /> <lisID>2182</lisID> <bioguideId>W000817</bioguideId> </identifiers> <sponsorshipWithdrawnDate /> <party>D</party> <firstName>Elizabeth</firstName> <lastName>Warren</lastName> <state>MA</state> </item> <item> <isOriginalCosponsor>True</isOriginalCosponsor> <sponsorshipDate>2017-03-06</sponsorshipDate> <fullName>Sen. Harris, Kamala D. [D-CA]</fullName> <bioguideId>H001075</bioguideId> <middleName>D.</middleName> <identifiers> <lisID>2301</lisID> <bioguideId>H001075</bioguideId> <gpoId /> </identifiers> <sponsorshipWithdrawnDate /> <party>D</party> <firstName>Kamala</firstName> <lastName>Harris</lastName> <state>CA</state> </item> <item> <isOriginalCosponsor>True</isOriginalCosponsor> <sponsorshipDate>2017-03-06</sponsorshipDate> <fullName>Sen. Cortez Masto, Catherine [D-NV]</fullName> <bioguideId>C001113</bioguideId> <middleName /> <identifiers> <gpoId /> <lisID>2299</lisID> <bioguideId>C001113</bioguideId> </identifiers> <sponsorshipWithdrawnDate /> <party>D</party> <firstName>Catherine</firstName> <lastName>Cortez Masto</lastName> <state>NV</state> </item> <item> <isOriginalCosponsor>True</isOriginalCosponsor> <sponsorshipDate>2017-03-06</sponsorshipDate> <fullName>Sen. Young, Todd C. [R-IN]</fullName> <bioguideId>Y000064</bioguideId> <middleName>C.</middleName> <identifiers> <gpoId>7948</gpoId> <bioguideId>Y000064</bioguideId> <lisID>2019</lisID> </identifiers> <sponsorshipWithdrawnDate /> <party>R</party> <firstName>Todd</firstName> <lastName>Young</lastName> <state>IN</state> </item> <item> <isOriginalCosponsor>False</isOriginalCosponsor> <sponsorshipDate>2017-03-22</sponsorshipDate> <fullName>Sen. Hirono, Mazie K. [D-HI]</fullName> <bioguideId>H001042</bioguideId> <middleName>K.</middleName> <identifiers> <bioguideId>H001042</bioguideId> <gpoId>7913</gpoId> <lisID>1844</lisID> </identifiers> <sponsorshipWithdrawnDate /> <party>D</party> <firstName>Mazie</firstName> <lastName>Hirono</lastName> <state>HI</state> </item> <item> <isOriginalCosponsor>False</isOriginalCosponsor> <sponsorshipDate>2017-03-23</sponsorshipDate> <fullName>Sen. Franken, Al [D-MN]</fullName> <bioguideId>F000457</bioguideId> <middleName /> <identifiers> <bioguideId>F000457</bioguideId> <gpoId>8339</gpoId> <lisID>1969</lisID> </identifiers> <sponsorshipWithdrawnDate /> <party>D</party> <firstName>Al</firstName> <lastName>Franken</lastName> <state>MN</state> </item> <item> <isOriginalCosponsor>False</isOriginalCosponsor> <sponsorshipDate>2017-04-04</sponsorshipDate> <fullName>Sen. Markey, Edward J. [D-MA]</fullName> <bioguideId>M000133</bioguideId> <middleName>J.</middleName> <identifiers> <bioguideId>M000133</bioguideId> <gpoId>7972</gpoId> <lisID>735</lisID> </identifiers> <sponsorshipWithdrawnDate /> <party>D</party> <firstName>EDWARD</firstName> <lastName>MARKEY</lastName> <state>MA</state> </item> <item> <isOriginalCosponsor>False</isOriginalCosponsor> <sponsorshipDate>2017-04-26</sponsorshipDate> <fullName>Sen. Sullivan, Dan [R-AK]</fullName> <bioguideId>S001198</bioguideId> <middleName /> <identifiers> <bioguideId>S001198</bioguideId> <gpoId /> <lisID>2290</lisID> </identifiers> <sponsorshipWithdrawnDate /> <party>R</party> <firstName>Dan</firstName> <lastName>Sullivan</lastName> <state>AK</state> </item> <item> <isOriginalCosponsor>False</isOriginalCosponsor> <sponsorshipDate>2017-05-03</sponsorshipDate> <fullName>Sen. Merkley, Jeff [D-OR]</fullName> <bioguideId>M001176</bioguideId> <middleName /> <identifiers> <gpoId>8238</gpoId> <bioguideId>M001176</bioguideId> <lisID>1900</lisID> </identifiers> <sponsorshipWithdrawnDate /> <party>D</party> <firstName>Jeff</firstName> <lastName>Merkley</lastName> <state>OR</state> </item> <item> <isOriginalCosponsor>False</isOriginalCosponsor> <sponsorshipDate>2017-05-03</sponsorshipDate> <fullName>Sen. Stabenow, Debbie [D-MI]</fullName> <bioguideId>S000770</bioguideId> <middleName>ANN</middleName> <identifiers> <bioguideId>S000770</bioguideId> <gpoId>8261</gpoId> <lisID>1531</lisID> </identifiers> <sponsorshipWithdrawnDate /> <party>D</party> <firstName>DEBORAH</firstName> <lastName>STABENOW</lastName> <state>MI</state> </item> <item> <isOriginalCosponsor>False</isOriginalCosponsor> <sponsorshipDate>2017-05-08</sponsorshipDate> <fullName>Sen. Hatch, Orrin G. [R-UT]</fullName> <bioguideId>H000338</bioguideId> <middleName>GRANT</middleName> <identifiers> <gpoId>8314</gpoId> <bioguideId>H000338</bioguideId> <lisID>1351</lisID> </identifiers> <sponsorshipWithdrawnDate /> <party>R</party> <firstName>ORRIN</firstName> <lastName>HATCH</lastName> <state>UT</state> </item> <item> <isOriginalCosponsor>False</isOriginalCosponsor> <sponsorshipDate>2017-05-11</sponsorshipDate> <fullName>Sen. Cruz, Ted [R-TX]</fullName> <bioguideId>C001098</bioguideId> <middleName /> <identifiers> <bioguideId>C001098</bioguideId> <gpoId /> <lisID>2175</lisID> </identifiers> <sponsorshipWithdrawnDate /> <party>R</party> <firstName>Ted</firstName> <lastName>Cruz</lastName> <state>TX</state> </item> <item> <isOriginalCosponsor>False</isOriginalCosponsor> <sponsorshipDate>2017-05-11</sponsorshipDate> <fullName>Sen. Durbin, Richard J. [D-IL]</fullName> <bioguideId>D000563</bioguideId> <middleName>J.</middleName> <identifiers> <bioguideId>D000563</bioguideId> <gpoId>8326</gpoId> <lisID>326</lisID> </identifiers> <sponsorshipWithdrawnDate /> <party>D</party> <firstName>RICHARD</firstName> <lastName>DURBIN</lastName> <state>IL</state> </item> <item> <isOriginalCosponsor>False</isOriginalCosponsor> <sponsorshipDate>2017-05-15</sponsorshipDate> <fullName>Sen. Gillibrand, Kirsten E. [D-NY]</fullName> <bioguideId>G000555</bioguideId> <middleName>E.</middleName> <identifiers> <bioguideId>G000555</bioguideId> <gpoId>8336</gpoId> <lisID>1866</lisID> </identifiers> <sponsorshipWithdrawnDate /> <party>D</party> <firstName>Kirsten</firstName> <lastName>Gillibrand</lastName> <state>NY</state> </item> <item> <isOriginalCosponsor>False</isOriginalCosponsor> <sponsorshipDate>2017-06-05</sponsorshipDate> <fullName>Sen. Menendez, Robert [D-NJ]</fullName> <bioguideId>M000639</bioguideId> <middleName /> <identifiers> <lisID>791</lisID> <bioguideId>M000639</bioguideId> <gpoId>8239</gpoId> </identifiers> <sponsorshipWithdrawnDate /> <party>D</party> <firstName>ROBERT</firstName> <lastName>MENENDEZ</lastName> <state>NJ</state> </item> <item> <isOriginalCosponsor>False</isOriginalCosponsor> <sponsorshipDate>2017-06-20</sponsorshipDate> <fullName>Sen. Bennet, Michael F. [D-CO]</fullName> <bioguideId>B001267</bioguideId> <middleName>F.</middleName> <identifiers> <lisID>1965</lisID> <bioguideId>B001267</bioguideId> <gpoId>8302</gpoId> </identifiers> <sponsorshipWithdrawnDate /> <party>D</party> <firstName>Michael</firstName> <lastName>Bennet</lastName> <state>CO</state> </item> <item> <isOriginalCosponsor>False</isOriginalCosponsor> <sponsorshipDate>2017-08-03</sponsorshipDate> <fullName>Sen. Kennedy, John [R-LA]</fullName> <bioguideId>K000393</bioguideId> <middleName>Neely</middleName> <identifiers> <bioguideId>K000393</bioguideId> <gpoId /> <lisID>2303</lisID> </identifiers> <sponsorshipWithdrawnDate /> <party>R</party> <firstName>John</firstName> <lastName>Kennedy</lastName> <state>LA</state> </item> </cosponsors> <amendments /> <recordedVotes /> <latestAction> <text>Placed on Senate Legislative Calendar under General Orders. Calendar No. 121.</text> <links /> <actionDate>2017-06-08</actionDate> </latestAction> <sponsors> <item> <lastName>FEINSTEIN</lastName> <bioguideId>F000062</bioguideId> <firstName>DIANNE</firstName> <party>D</party> <byRequestType /> <state>CA</state> <fullName>Sen. Feinstein, Dianne [D-CA]</fullName> <identifiers> <bioguideId>F000062</bioguideId> <gpoId>8338</gpoId> <lisID>1332</lisID> </identifiers> <middleName /> </item> </sponsors> <cboCostEstimates> <item> <pubDate>2017-07-07T19:34:00Z</pubDate> <title>S. 534, Protecting Young Victims from Sexual Abuse Act of 2017</title> <url>https://www.cbo.gov/publication/52876</url> </item> </cboCostEstimates> <title>Protecting Young Victims from Sexual Abuse Act of 2017</title> <policyArea> <name>Crime and Law Enforcement</name> </policyArea> <introducedDate>2017-03-06</introducedDate> </bill> <dublinCore xmlns:dc="http://purl.org/dc/elements/1.1/"> <dc:format>text/xml</dc:format> <dc:language>EN</dc:language> <dc:rights>Pursuant to Title 17 Section 105 of the United States Code, this file is not subject to copyright protection and is in the public domain.</dc:rights> <dc:contributor>Congressional Research Service, Library of Congress</dc:contributor> <dc:description>This file contains bill summaries and statuses for federal legislation. A bill summary describes the most significant provisions of a piece of legislation and details the effects the legislative text may have on current law and federal programs. Bill summaries are authored by the Congressional Research Service (CRS) of the Library of Congress. As stated in Public Law 91-510 (2 USC 166 (d)(6)), one of the duties of CRS is "to prepare summaries and digests of bills and resolutions of a public general nature introduced in the Senate or House of Representatives". For more information, refer to the User Guide that accompanies this file.</dc:description> </dublinCore> </billStatus>
{ "content_hash": "27a9246999861c836aceafafb62f7ed0", "timestamp": "", "source": "github", "line_count": 799, "max_line_length": 676, "avg_line_length": 34.056320400500624, "alnum_prop": 0.5832935210025357, "repo_name": "peter765/power-polls", "id": "afb3e95f7c9216ea3ec62aacf6564b4573762c44", "size": "27211", "binary": false, "copies": "1", "ref": "refs/heads/master", "path": "db/bills/s/s534/fdsys_billstatus.xml", "mode": "33188", "license": "mit", "language": [ { "name": "HTML", "bytes": "58567" }, { "name": "JavaScript", "bytes": "7370" }, { "name": "Python", "bytes": "22988" } ], "symlink_target": "" }
#ifndef MBED_SPISLAVE_H #define MBED_SPISLAVE_H #include "device.h" #if DEVICE_SPISLAVE #include "platform.h" #include "PinNames.h" #include "PeripheralNames.h" #include "Base.h" namespace mbed { /* Class: SPISlave * A SPI slave, used for communicating with a SPI Master device * * The default format is set to 8-bits, mode 0, and a clock frequency of 1MHz * * Example: * > // Reply to a SPI master as slave * > * > #include "mbed.h" * > * > SPISlave device(p5, p6, p7, p8); // mosi, miso, sclk, ssel * > * > int main() { * > device.reply(0x00); // Prime SPI with first reply * > while(1) { * > if(device.receive()) { * > int v = device.read(); // Read byte from master * > v = (v + 1) % 0x100; // Add one to it, modulo 256 * > device.reply(v); // Make this the next reply * > } * > } * > } */ class SPISlave : public Base { public: /* Constructor: SPI * Create a SPI slave connected to the specified pins * * Variables: * mosi - SPI Master Out, Slave In pin * miso - SPI Master In, Slave Out pin * sclk - SPI Clock pin * ssel - SPI chip select pin * name - (optional) A string to identify the object * * Pin Options: * (5, 6, 7i, 8) or (11, 12, 13, 14) * * mosi or miso can be specfied as NC if not used */ SPISlave(PinName mosi, PinName miso, PinName sclk, PinName ssel, const char *name = NULL); /* Function: format * Configure the data transmission format * * Variables: * bits - Number of bits per SPI frame (4 - 16) * mode - Clock polarity and phase mode (0 - 3) * * > mode | POL PHA * > -----+-------- * > 0 | 0 0 * > 1 | 0 1 * > 2 | 1 0 * > 3 | 1 1 */ void format(int bits, int mode = 0); /* Function: frequency * Set the spi bus clock frequency * * Variables: * hz - SCLK frequency in hz (default = 1MHz) */ void frequency(int hz = 1000000); /* Function: receive * Polls the SPI to see if data has been received * * Variables: * returns - zero if no data, 1 otherwise */ int receive(void); /* Function: read * Retrieve data from receive buffer as slave * * Variables: * returns - the data in the receive buffer */ int read(void); /* Function: reply * Fill the transmission buffer with the value to be written out * as slave on the next received message from the master. * * Variables: * value - the data to be transmitted next */ void reply(int value); protected: SPIName _spi; int _bits; int _mode; int _hz; }; } // namespace mbed #endif #endif
{ "content_hash": "66d7dd5eaea31be53e01d7c8a34e279a", "timestamp": "", "source": "github", "line_count": 125, "max_line_length": 77, "avg_line_length": 23.848, "alnum_prop": 0.5216370345521637, "repo_name": "stvnrhodes/CNCAirbrush", "id": "233881f69e84d97c414325e59c1587cbe79b4d90", "size": "3091", "binary": false, "copies": "2", "ref": "refs/heads/master", "path": "mbed/mbed/SPISlave.h", "mode": "33188", "license": "mit", "language": [ { "name": "C", "bytes": "182628" }, { "name": "C++", "bytes": "176210" }, { "name": "Python", "bytes": "61862" } ], "symlink_target": "" }
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 1.0 Transitional//EN"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <META http-equiv="Content-Type" content="text/html; charset=UTF-8"> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <link rel="stylesheet" href="../includes/main.css" type="text/css"> <link rel="shortcut icon" href="../favicon.ico" type="image/x-icon"> <title>Apache CloudStack | The Power Behind Your Cloud</title> </head> <body> <div id="insidetopbg"> <div id="inside_wrapper"> <div class="uppermenu_panel"> <div class="uppermenu_box"></div> </div> <div id="main_master"> <div id="inside_header"> <div class="header_top"> <a class="cloud_logo" href="http://cloudstack.org"></a> <div class="mainemenu_panel"></div> </div> </div> <div id="main_content"> <div class="inside_apileftpanel"> <div class="inside_contentpanel" style="width:930px;"> <div class="api_titlebox"> <div class="api_titlebox_left"> <span> Apache CloudStack v4.4.1 Domain Admin API Reference </span> <p></p> <h1>listDiskOfferings</h1> <p>Lists all available disk offerings.</p> </div> <div class="api_titlebox_right"> <a class="api_backbutton" href="../TOC_Domain_Admin.html"></a> </div> </div> <div class="api_tablepanel"> <h2>Request parameters</h2> <table class="apitable"> <tr class="hed"> <td style="width:200px;"><strong>Parameter Name</strong></td><td style="width:500px;">Description</td><td style="width:180px;">Required</td> </tr> <tr> <td style="width:200px;"><i>domainid</i></td><td style="width:500px;"><i>the ID of the domain of the disk offering.</i></td><td style="width:180px;"><i>false</i></td> </tr> <tr> <td style="width:200px;"><i>id</i></td><td style="width:500px;"><i>ID of the disk offering</i></td><td style="width:180px;"><i>false</i></td> </tr> <tr> <td style="width:200px;"><i>keyword</i></td><td style="width:500px;"><i>List by keyword</i></td><td style="width:180px;"><i>false</i></td> </tr> <tr> <td style="width:200px;"><i>name</i></td><td style="width:500px;"><i>name of the disk offering</i></td><td style="width:180px;"><i>false</i></td> </tr> <tr> <td style="width:200px;"><i>page</i></td><td style="width:500px;"><i></i></td><td style="width:180px;"><i>false</i></td> </tr> <tr> <td style="width:200px;"><i>pagesize</i></td><td style="width:500px;"><i></i></td><td style="width:180px;"><i>false</i></td> </tr> </table> </div> <div class="api_tablepanel"> <h2>Response Tags</h2> <table class="apitable"> <tr class="hed"> <td style="width:200px;"><strong>Response Name</strong></td><td style="width:500px;">Description</td> </tr> <tr> <td style="width:200px;"><strong>id</strong></td><td style="width:500px;">unique ID of the disk offering</td> </tr> <tr> <td style="width:200px;"><strong>cacheMode</strong></td><td style="width:500px;">the cache mode to use for this disk offering. none, writeback or writethrough</td> </tr> <tr> <td style="width:200px;"><strong>created</strong></td><td style="width:500px;">the date this disk offering was created</td> </tr> <tr> <td style="width:200px;"><strong>diskBytesReadRate</strong></td><td style="width:500px;">bytes read rate of the disk offering</td> </tr> <tr> <td style="width:200px;"><strong>diskBytesWriteRate</strong></td><td style="width:500px;">bytes write rate of the disk offering</td> </tr> <tr> <td style="width:200px;"><strong>diskIopsReadRate</strong></td><td style="width:500px;">io requests read rate of the disk offering</td> </tr> <tr> <td style="width:200px;"><strong>diskIopsWriteRate</strong></td><td style="width:500px;">io requests write rate of the disk offering</td> </tr> <tr> <td style="width:200px;"><strong>disksize</strong></td><td style="width:500px;">the size of the disk offering in GB</td> </tr> <tr> <td style="width:200px;"><strong>displayoffering</strong></td><td style="width:500px;">whether to display the offering to the end user or not.</td> </tr> <tr> <td style="width:200px;"><strong>displaytext</strong></td><td style="width:500px;">an alternate display text of the disk offering.</td> </tr> <tr> <td style="width:200px;"><strong>domain</strong></td><td style="width:500px;">the domain name this disk offering belongs to. Ignore this information as it is not currently applicable.</td> </tr> <tr> <td style="width:200px;"><strong>domainid</strong></td><td style="width:500px;">the domain ID this disk offering belongs to. Ignore this information as it is not currently applicable.</td> </tr> <tr> <td style="width:200px;"><strong>hypervisorsnapshotreserve</strong></td><td style="width:500px;">Hypervisor snapshot reserve space as a percent of a volume (for managed storage using Xen or VMware)</td> </tr> <tr> <td style="width:200px;"><strong>iscustomized</strong></td><td style="width:500px;">true if disk offering uses custom size, false otherwise</td> </tr> <tr> <td style="width:200px;"><strong>iscustomizediops</strong></td><td style="width:500px;">true if disk offering uses custom iops, false otherwise</td> </tr> <tr> <td style="width:200px;"><strong>maxiops</strong></td><td style="width:500px;">the max iops of the disk offering</td> </tr> <tr> <td style="width:200px;"><strong>miniops</strong></td><td style="width:500px;">the min iops of the disk offering</td> </tr> <tr> <td style="width:200px;"><strong>name</strong></td><td style="width:500px;">the name of the disk offering</td> </tr> <tr> <td style="width:200px;"><strong>storagetype</strong></td><td style="width:500px;">the storage type for this disk offering</td> </tr> <tr> <td style="width:200px;"><strong>tags</strong></td><td style="width:500px;">the tags for the disk offering</td> </tr> </table> </div> </div> </div> </div> </div> <div id="footer"> <div id="footer_mainmaster"> <p>Copyright &copy; 2014 The Apache Software Foundation, Licensed under the <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License, Version 2.0.</a> <br> Apache, CloudStack, Apache CloudStack, the Apache CloudStack logo, the CloudMonkey logo and the Apache feather logo are trademarks of The Apache Software Foundation.</p> </div> </div> </div> </div> </body> </html>
{ "content_hash": "ed370a590bdca74db0c448495ad98f2e", "timestamp": "", "source": "github", "line_count": 148, "max_line_length": 202, "avg_line_length": 41.32432432432432, "alnum_prop": 0.684434270765206, "repo_name": "terbolous/cloudstack-www", "id": "b666c1808995c3f176c2ba3560f50720ce46a26f", "size": "6116", "binary": false, "copies": "10", "ref": "refs/heads/master", "path": "source/api/apidocs-4.4/domain_admin/listDiskOfferings.html", "mode": "33188", "license": "apache-2.0", "language": [ { "name": "CSS", "bytes": "303768" }, { "name": "HTML", "bytes": "123165841" }, { "name": "Python", "bytes": "2684" }, { "name": "Ruby", "bytes": "1967" }, { "name": "Shell", "bytes": "861" } ], "symlink_target": "" }
package org.drools.guvnor.server.files; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.UnsupportedEncodingException; import java.net.URI; import java.net.URISyntaxException; import java.security.Principal; import java.util.Enumeration; import java.util.Locale; import java.util.Map; import javax.servlet.*; import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; public class MockHTTPRequest implements HttpServletRequest { final private URI uri; private Map<String, String> headers; ServletInputStream stream; String queryString; Map<String, String> parameters; public String method; public StringBuffer url = new StringBuffer("http://foo.com"); public void login(java.lang.String username, java.lang.String password){} public MockHTTPRequest(String uri, Map<String, String> headers) { try { this.uri = new URI (uri); this.headers = headers; } catch (URISyntaxException e) { throw new RuntimeException (e); } } public MockHTTPRequest(String uri, Map<String, String> headers, Map<String, String> parameters) { try { this.uri = new URI (uri); this.headers = headers; this.parameters = parameters; } catch (URISyntaxException e) { throw new RuntimeException (e); } } public MockHTTPRequest(String uri, Map<String, String> headers, InputStream in) { try { this.uri = new URI (uri); this.headers = headers; this.stream = new MockInput(in); } catch (URISyntaxException e) { throw new RuntimeException (e); } } public MockHTTPRequest(String uri, Map<String, String> headers, Map<String,String> parameters, InputStream in) { try { this.uri = new URI (uri); this.headers = headers; this.parameters = parameters; this.stream = new MockInput(in); } catch (URISyntaxException e) { throw new RuntimeException (e); } } public String getAuthType() { return null; } public String getContextPath() { return uri.getPath(); } public Cookie[] getCookies() { return null; } public long getDateHeader(String arg0) { return 0; } public String getHeader(String n) { return headers.get(n); } public Enumeration<String> getHeaderNames() { return null; } public Enumeration getHeaders(String arg0) { return null; } public int getIntHeader(String arg0) { return 0; } public String getMethod() { return method; } public String getPathInfo() { return null; } public String getPathTranslated() { return uri.getPath(); } public String getQueryString() { return queryString; } public String getRemoteUser() { return null; } public String getRequestURI() { return uri.toString(); } public StringBuffer getRequestURL() { return url; } public String getRequestedSessionId() { return null; } public String getServletPath() { return null; } public HttpSession getSession() { return null; } public HttpSession getSession(boolean arg0) { return null; } public Principal getUserPrincipal() { return null; } public boolean isRequestedSessionIdFromCookie() { return false; } public boolean isRequestedSessionIdFromURL() { return false; } public boolean isRequestedSessionIdFromUrl() { return false; } public boolean isRequestedSessionIdValid() { return false; } public boolean isUserInRole(String arg0) { return false; } public Object getAttribute(String arg0) { return null; } public Enumeration getAttributeNames() { return null; } public String getCharacterEncoding() { return null; } public int getContentLength() { return 0; } public String getContentType() { return null; } public ServletInputStream getInputStream() throws IOException { return stream ; } public Locale getLocale() { return null; } public Enumeration getLocales() { return null; } public String getParameter(String arg0) { return parameters.get(arg0); } public Map getParameterMap() { return parameters; } public Enumeration getParameterNames() { return null; } public String[] getParameterValues(String arg0) { return null; } public String getProtocol() { return null; } public BufferedReader getReader() throws IOException { return null; } public String getRealPath(String arg0) { return null; } public int getRemotePort() { return 0; } public String getLocalName() { return null; } public String getLocalAddr() { return null; } public int getLocalPort() { return 0; } public String getRemoteAddr() { return null; } public String getRemoteHost() { return null; } public RequestDispatcher getRequestDispatcher(String arg0) { return null; } public String getScheme() { return null; } public String getServerName() { return null; } public int getServerPort() { return 0; } public boolean isSecure() { return false; } public void removeAttribute(String arg0) { } public void setAttribute(String arg0, Object arg1) { } public void setCharacterEncoding(String arg0) throws UnsupportedEncodingException { } static class MockInput extends ServletInputStream { private InputStream stream; MockInput(InputStream in) { this.stream = in; } public int read() throws IOException { return stream.read(); } } }
{ "content_hash": "b058188f394cb2377187c596fa7acd0c", "timestamp": "", "source": "github", "line_count": 303, "max_line_length": 101, "avg_line_length": 20.834983498349835, "alnum_prop": 0.6028829399651513, "repo_name": "psiroky/guvnor", "id": "c68b402802ec0de790dff141af5f5f7f9fdb631e", "size": "6892", "binary": false, "copies": "2", "ref": "refs/heads/master", "path": "guvnor-webapp-drools/src/test/java/org/drools/guvnor/server/files/MockHTTPRequest.java", "mode": "33188", "license": "apache-2.0", "language": [ { "name": "ActionScript", "bytes": "408232" }, { "name": "CSS", "bytes": "34688" }, { "name": "Java", "bytes": "10019368" }, { "name": "JavaScript", "bytes": "8801" }, { "name": "Shell", "bytes": "6807" } ], "symlink_target": "" }
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Minim : : Constant : : patch</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <link href="stylesheet.css" rel="stylesheet" type="text/css"> </head> <body> <center> <table class="mainTable"> <tr> <td class="header"> <span class="indexheader">Minim</span><br/> <span class="indexnavigation"> <a href="index.html">core</a> | <a href="index_ugens.html">ugens</a> | <a href="index_analysis.html">analysis</a> </span> </td> <td class="border-left">&nbsp;</td> </tr> <tr> <td class="classNavigation"> <p class="mainTextName"><A href="ugen_class_ugen.html">UGen</A></p> <p class="methodName">patch</p> </td> <td class="mainText border-left"> <p class="memberSectionHeader">Description</p> Send the output of this UGen to another UGen, UGenInput, or AudioOutput. For instance, if an Oscil is patched to an AudioOutput, you will hear the sound it generates. If a FilePlayer is patched to a Delay, then the delay effect will be applied to the sound generated by the FilePlayer. <p class="memberSectionHeader">Signature</p> <pre>UGen patch(UGen connectToUGen) UGen patch(UGen.UGenInput connectToInput) void patch(AudioOutput audioOutput) </pre> <p class="memberSectionHeader">Parameters</p> <span class="parameterName">connectToUGen</span>&nbsp;&mdash;&nbsp;<span class="parameterDescription">The UGen to patch to.</span><br/> <span class="parameterName">connectToInput</span>&nbsp;&mdash;&nbsp;<span class="parameterDescription">The UGenInput to patch to.</span><br/> <span class="parameterName">audioOutput</span>&nbsp;&mdash;&nbsp;<span class="parameterDescription">The AudioOutput you want to connect this UGen to.</span><br/> <p class="memberSectionHeader">Returns</p> <p>When patching to a UGen or UGenInput, the UGen being patched to is returned so that you can chain patch calls. For example: <pre> sine.patch( gain ).patch( out ); </pre></p> <p class="memberSectionHeader">Related</p> <p class="memberSectionHeader">Example</p> <pre>/** * This sketch demonstrates how to create a simple synthesis chain that * involves controlling the value of a UGenInput with the output of * a UGen. In this case, we patch an Oscil generating a sine wave into * the amplitude input of an Oscil generating a square wave. The result * is known as amplitude modulation. * &lt;p> * For more information about Minim and additional features, * visit http://code.compartmental.net/minim/ */ import ddf.minim.*; import ddf.minim.ugens.*; Minim minim; AudioOutput out; Oscil wave; Oscil mod; void setup() { size(512, 200, P3D); minim = new Minim(this); // use the getLineOut method of the Minim object to get an AudioOutput object out = minim.getLineOut(); // create a triangle wave Oscil, set to 440 Hz, at 1.0 amplitude // in this case, the amplitude we construct the Oscil with // doesn't matter because we will be patching something to // its amplitude input. wave = new Oscil( 440, 1.0f, Waves.TRIANGLE ); // create a sine wave Oscil for modulating the amplitude of wave mod = new Oscil( 2, 0.4f, Waves.SINE ); // connect up the modulator mod.patch( wave.amplitude ); // patch wave to the output wave.patch( out ); } void draw() { background(0); stroke(255); // draw the waveforms for(int i = 0; i &lt; out.bufferSize() - 1; i++) { line( i, 50 + out.left.get(i)*50, i+1, 50 + out.left.get(i+1)*50 ); line( i, 150 + out.right.get(i)*50, i+1, 150 + out.right.get(i+1)*50 ); } } </pre> <p class="memberSectionHeader">Usage</p> Web & Application </td> </tr> </table> </center> </body> </html>
{ "content_hash": "0cf4edac5fdefae5983be789a70e1683", "timestamp": "", "source": "github", "line_count": 132, "max_line_length": 169, "avg_line_length": 30.227272727272727, "alnum_prop": 0.655889724310777, "repo_name": "OpenBCI/OpenBCI_Processing", "id": "38ca74d5e13fbd5ad6e301d31ecaebe7ae5c21ca", "size": "3990", "binary": false, "copies": "4", "ref": "refs/heads/master", "path": "libraries/minim/documentation/constant_method_patch.html", "mode": "33188", "license": "mit", "language": [ { "name": "CSS", "bytes": "15681" }, { "name": "HTML", "bytes": "5875528" }, { "name": "Java", "bytes": "2014333" }, { "name": "JavaScript", "bytes": "827" }, { "name": "Processing", "bytes": "1099125" } ], "symlink_target": "" }
using Affecto.Mapping.AutoMapper; using AutoMapper; using OrganizationRegister.Application.User; namespace OrganizationRegister.Api.Settings { public class RoleMapper : OneWayMapper<IRole, Role> { protected override void ConfigureMaps() { Mapper.CreateMap<IRole, Role>(); } } }
{ "content_hash": "8f23bb29f1822dd548e0fab4c915002b", "timestamp": "", "source": "github", "line_count": 14, "max_line_length": 55, "avg_line_length": 23.357142857142858, "alnum_prop": 0.6850152905198776, "repo_name": "City-of-Helsinki/organisaatiorekisteri", "id": "fd70f4bbd579f3cff43b14f40ecf59230782e6ba", "size": "329", "binary": false, "copies": "1", "ref": "refs/heads/master", "path": "Source/Api/Settings/RoleMapper.cs", "mode": "33188", "license": "mit", "language": [ { "name": "ASP", "bytes": "130" }, { "name": "Batchfile", "bytes": "896" }, { "name": "C#", "bytes": "594793" }, { "name": "CSS", "bytes": "241829" }, { "name": "Gherkin", "bytes": "57795" }, { "name": "HTML", "bytes": "111823" }, { "name": "JavaScript", "bytes": "25590" }, { "name": "PowerShell", "bytes": "532" }, { "name": "TypeScript", "bytes": "246472" } ], "symlink_target": "" }
from tests.base_unittest import BaseUnitTest from pypokerengine.engine.card import Card from pypokerengine.engine.player import Player from pypokerengine.engine.poker_constants import PokerConstants as Const from nose.tools import * class PlayerTest(BaseUnitTest): def setUp(self): self.player = Player("uuid", 100) def test_add_holecard(self): cards = [Card.from_id(cid) for cid in range(1,3)] self.player.add_holecard(cards) self.true(cards[0] in self.player.hole_card) self.true(cards[1] in self.player.hole_card) @raises(ValueError) def test_add_single_hole_card(self): self.player.add_holecard([Card.from_id(1)]) @raises(ValueError) def test_add_too_many_hole_card(self): self.player.add_holecard([Card.from_id(cid) for cid in range(1,4)]) @raises(ValueError) def test_add_hole_card_twice(self): self.player.add_holecard([Card.from_id(cid) for cid in range(1,3)]) self.player.add_holecard([Card.from_id(cid) for cid in range(1,3)]) def test_clear_holecard(self): self.player.add_holecard([Card.from_id(cid) for cid in range(1,3)]) self.player.clear_holecard() self.eq(0, len(self.player.hole_card)) def test_append_chip(self): self.player.append_chip(10) self.eq(110, self.player.stack) def test_collect_bet(self): self.player.collect_bet(10) self.eq(90, self.player.stack) @raises(ValueError) def test_collect_too_much_bet(self): self.player.collect_bet(200) def test_is_active(self): self.player.pay_info.update_by_pay(10) self.true(self.player.is_active()) def test_if_allin_player_is_active(self): self.player.pay_info.update_to_allin() self.true(self.player.is_active()) def test_if_folded_player_is_not_active(self): self.player.pay_info.update_to_fold() self.false(self.player.is_active()) def test_if_no_money_player_is_active(self): self.player.collect_bet(100) self.true(self.player.is_active()) def test_is_waiting_ask(self): self.player.pay_info.update_by_pay(10) self.true(self.player.is_waiting_ask()) def test_if_allin_player_is_not_waiting_ask(self): self.player.pay_info.update_to_allin() self.false(self.player.is_waiting_ask()) def test_if_folded_player_is_not_waiting_ask(self): self.player.pay_info.update_to_fold() self.false(self.player.is_waiting_ask()) def test_add_fold_action_history(self): self.player.add_action_history(Const.Action.FOLD) self.eq("FOLD", self.player.action_histories[-1]["action"]) def test_add_call_action_history(self): self.player.add_action_history(Const.Action.CALL, 10) action = self.player.action_histories[-1] self.eq("CALL", action["action"]) self.eq(10, action["amount"]) self.eq(10, action["paid"]) def test_add_call_action_history_after_paid(self): self.player.add_action_history(Const.Action.CALL, 10) self.player.add_action_history(Const.Action.CALL, 20) action = self.player.action_histories[-1] self.eq(20, action["amount"]) self.eq(10, action["paid"]) def test_add_raise_action_history(self): self.player.add_action_history(Const.Action.RAISE, 10, 5) action = self.player.action_histories[-1] self.eq("RAISE", action["action"]) self.eq(10, action["amount"]) self.eq(10, action["paid"]) self.eq(5, action["add_amount"]) def test_add_raise_action_history_after_paid(self): self.player.add_action_history(Const.Action.CALL, 10) self.player.add_action_history(Const.Action.RAISE, 20, 10) action = self.player.action_histories[-1] self.eq(20, action["amount"]) self.eq(10, action["paid"]) def test_add_small_blind_history(self): self.player.add_action_history(Const.Action.SMALL_BLIND, sb_amount=5) action = self.player.action_histories[-1] self.eq("SMALLBLIND", action["action"]) self.eq(5, action["amount"]) self.eq(5, action["add_amount"]) def test_add_big_blind_history(self): self.player.add_action_history(Const.Action.BIG_BLIND, sb_amount=5) action = self.player.action_histories[-1] self.eq("BIGBLIND", action["action"]) self.eq(10, action["amount"]) self.eq(5, action["add_amount"]) def test_add_ante_history(self): self.player.add_action_history(Const.Action.ANTE, 10) action = self.player.action_histories[-1] self.eq("ANTE", action["action"]) self.eq(10, action["amount"]) @raises(AssertionError) def test_add_empty_ante_history(self): self.player.add_action_history(Const.Action.ANTE, 0) def test_save_street_action_histories(self): self.assertIsNone(self.player.round_action_histories[Const.Street.PREFLOP]) self.player.add_action_history(Const.Action.BIG_BLIND, sb_amount=5) self.player.save_street_action_histories(Const.Street.PREFLOP) self.eq(1, len(self.player.round_action_histories[Const.Street.PREFLOP])) self.eq("BIGBLIND", self.player.round_action_histories[Const.Street.PREFLOP][0]["action"]) self.eq(0, len(self.player.action_histories)) def test_clear_action_histories(self): self.player.add_action_history(Const.Action.BIG_BLIND, sb_amount=5) self.player.save_street_action_histories(Const.Street.PREFLOP) self.player.add_action_history(Const.Action.CALL, 10) self.assertIsNotNone(0, len(self.player.round_action_histories[Const.Street.PREFLOP])) self.neq(0, len(self.player.action_histories)) self.player.clear_action_histories() self.assertIsNone(self.player.round_action_histories[Const.Street.PREFLOP]) self.eq(0, len(self.player.action_histories)) def test_paid_sum(self): self.eq(0, self.player.paid_sum()) self.player.add_action_history(Const.Action.BIG_BLIND, sb_amount=5) self.eq(10, self.player.paid_sum()) self.player.clear_action_histories() self.eq(0, self.player.paid_sum()) self.player.add_action_history(Const.Action.ANTE, 3) self.eq(0, self.player.paid_sum()) self.player.add_action_history(Const.Action.BIG_BLIND, sb_amount=5) self.eq(10, self.player.paid_sum()) def test_serialization(self): player = self.__setup_player_for_serialization() serial = player.serialize() restored = Player.deserialize(serial) self.eq(player.name, restored.name) self.eq(player.uuid, restored.uuid) self.eq(player.stack, restored.stack) self.eq(player.hole_card, restored.hole_card) self.eq(player.action_histories, restored.action_histories) self.eq(player.round_action_histories, restored.round_action_histories) self.eq(player.pay_info.amount, restored.pay_info.amount) self.eq(player.pay_info.status, restored.pay_info.status) def __setup_player_for_serialization(self): player = Player("uuid", 50, "hoge") player.add_holecard([Card.from_id(cid) for cid in range(1,3)]) player.add_action_history(Const.Action.SMALL_BLIND, sb_amount=5) player.save_street_action_histories(Const.Street.PREFLOP) player.add_action_history(Const.Action.CALL, 10) player.add_action_history(Const.Action.RAISE, 10, 5) player.add_action_history(Const.Action.FOLD) player.pay_info.update_by_pay(15) player.pay_info.update_to_fold() return player
{ "content_hash": "c5fbce926069c5f81cfaaf4158cf824a", "timestamp": "", "source": "github", "line_count": 189, "max_line_length": 94, "avg_line_length": 37.94708994708995, "alnum_prop": 0.7062186279977691, "repo_name": "ishikota/PyPokerEngine", "id": "d765de6c85829a01126665a9c76c196fbb222ccf", "size": "7172", "binary": false, "copies": "2", "ref": "refs/heads/master", "path": "tests/pypokerengine/engine/player_test.py", "mode": "33188", "license": "mit", "language": [ { "name": "Python", "bytes": "248078" } ], "symlink_target": "" }
layout: post title: "RELIC" image: http://slykuiper.com/images/work/intros/relic.png tag: - motion graphics - intro --- ## RELIC Relic was a partnership between [Jusmi](http://slykuiper.com/JUSMIMUSIC) and I. With Jusmi serving as graphic designer / music producer and me serving as motion designer, we created intros/outros, banners, and logos to YouTube gaming content creators looking to stand out among the competition. ### Explainer <iframe src="https://player.vimeo.com/video/184433796" width="640" height="360" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe> Explainer video showing what we could provide to potential clients. Motion design by me and music created by Jusmi. --- ### Sky Ident <iframe src="https://player.vimeo.com/video/183224382" width="640" height="360" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe> Cloudy ident. --- ### Relic Digital Intro <iframe src="https://player.vimeo.com/video/192888713" width="640" height="360" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe> Digital intro.
{ "content_hash": "b2245ee965e2b6c521042cee8ff6f001", "timestamp": "", "source": "github", "line_count": 27, "max_line_length": 294, "avg_line_length": 41.629629629629626, "alnum_prop": 0.7784697508896797, "repo_name": "Slykuiper/slykuiper.github.com", "id": "cd2c0588dfa40683b27bd5450f37044c5872a6bd", "size": "1128", "binary": false, "copies": "1", "ref": "refs/heads/master", "path": "_posts/2014-06-22-RELIC.md", "mode": "33188", "license": "mit", "language": [ { "name": "CSS", "bytes": "37711" }, { "name": "HTML", "bytes": "38815" }, { "name": "JavaScript", "bytes": "1974477" }, { "name": "Ruby", "bytes": "1253" }, { "name": "Shell", "bytes": "831" } ], "symlink_target": "" }
/* A SimpleSchema-compatible JSON schema */ const schema = { // default properties _id: { type: String, viewableBy: ['guests'], }, createdAt: { type: Date, viewableBy: ['guests'], autoValue: (documentOrModifier) => { if (documentOrModifier && !documentOrModifier.$set) return new Date() // if this is an insert, set createdAt to current timestamp } }, userId: { type: String, viewableBy: ['guests'], resolveAs: 'user: User', }, // custom properties body: { label: 'Body', placeholder: 'Add a comment…', type: String, optional: true, viewableBy: ['guests'], insertableBy: ['members'], editableBy: ['members'] }, picId: { type: String, viewableBy: ['guests'], insertableBy: ['members'], hidden: true, }, }; export default schema;
{ "content_hash": "92162241103e6666be3ea260a5e97a4d", "timestamp": "", "source": "github", "line_count": 48, "max_line_length": 137, "avg_line_length": 17.770833333333332, "alnum_prop": 0.5885111371629543, "repo_name": "bengott/Telescope", "id": "9eaebf0fe0f137fc2168a496c77dd5e44d755e59", "size": "855", "binary": false, "copies": "1", "ref": "refs/heads/master", "path": "packages/example-instagram/lib/modules/comments/schema.js", "mode": "33188", "license": "mit", "language": [ { "name": "CSS", "bytes": "23696" }, { "name": "HTML", "bytes": "9667" }, { "name": "JavaScript", "bytes": "621717" }, { "name": "Shell", "bytes": "1534" } ], "symlink_target": "" }
'use strict'; const angular = require('angular'); import _ from 'lodash'; import { CLOUD_PROVIDER_REGISTRY, CONFIRMATION_MODAL_SERVICE, INSTANCE_READ_SERVICE, INSTANCE_WRITE_SERVICE, RECENT_HISTORY_SERVICE, ServerGroupTemplates, } from '@spinnaker/core'; module.exports = angular.module('spinnaker.instance.detail.kubernetes.controller', [ require('@uirouter/angularjs').default, require('angular-ui-bootstrap'), INSTANCE_WRITE_SERVICE, INSTANCE_READ_SERVICE, CONFIRMATION_MODAL_SERVICE, RECENT_HISTORY_SERVICE, CLOUD_PROVIDER_REGISTRY, ]) .controller('kubernetesInstanceDetailsController', function ($scope, $state, $uibModal, instanceWriter, confirmationModalService, recentHistoryService, cloudProviderRegistry, instanceReader, instance, app, kubernetesProxyUiService, $q) { // needed for standalone instances $scope.detailsTemplateUrl = cloudProviderRegistry.getValue('kubernetes', 'instance.detailsTemplateUrl'); $scope.state = { loading: true, standalone: app.isStandalone, }; this.application = app; this.uiLink = function uiLink() { return kubernetesProxyUiService.buildLink($scope.instance.account, 'pod', $scope.instance.region, $scope.instance.name); }; this.showYaml = function showYaml() { $scope.userDataModalTitle = 'Pod YAML'; $scope.userData = $scope.instance.yaml; $uibModal.open({ templateUrl: ServerGroupTemplates.userData, controller: 'CloseableModalCtrl', scope: $scope }); }; function retrieveInstance() { var extraData = {}; var instanceSummary, loadBalancers, account, namespace; if (!app.serverGroups) { // standalone instance instanceSummary = {}; loadBalancers = []; account = instance.account; namespace = instance.region; } else { app.serverGroups.data.some(function (serverGroup) { return serverGroup.instances.some(function (possibleInstance) { if (possibleInstance.id === instance.instanceId) { instanceSummary = possibleInstance; loadBalancers = serverGroup.loadBalancers; account = serverGroup.account; namespace = serverGroup.region; extraData.serverGroup = serverGroup.name; return true; } }); }); if (!instanceSummary) { // perhaps it is in a server group that is part of another application app.loadBalancers.data.some(function (loadBalancer) { return loadBalancer.instances.some(function (possibleInstance) { if (possibleInstance.id === instance.instanceId) { instanceSummary = possibleInstance; loadBalancers = [loadBalancer.name]; account = loadBalancer.account; namespace = loadBalancer.region; return true; } }); }); if (!instanceSummary) { // perhaps it is in a disabled server group via a load balancer app.loadBalancers.data.some(function (loadBalancer) { return loadBalancer.serverGroups.some(function (serverGroup) { if (!serverGroup.isDisabled) { return false; } return serverGroup.instances.some(function (possibleInstance) { if (possibleInstance.id === instance.instanceId) { instanceSummary = possibleInstance; loadBalancers = [loadBalancer.name]; account = loadBalancer.account; namespace = loadBalancer.region; return true; } }); }); }); } } } if (instanceSummary && account && namespace) { extraData.account = account; extraData.namespace = namespace; recentHistoryService.addExtraDataToLatest('instances', extraData); return instanceReader.getInstanceDetails(account, namespace, instance.instanceId).then(function(details) { $scope.state.loading = false; $scope.instance = _.defaults(details, instanceSummary); $scope.instance.account = account; $scope.instance.namespace = namespace; $scope.instance.region = namespace; $scope.instance.loadBalancers = loadBalancers; var pod = $scope.instance.pod; $scope.instance.dnsPolicy = pod.spec.dnsPolicy; $scope.instance.apiVersion = pod.apiVersion; $scope.instance.kind = pod.kind; $scope.instance.nodeName = pod.spec.nodeName; $scope.instance.restartPolicy = pod.spec.restartPolicy; $scope.instance.terminationGracePeriodSeconds = pod.spec.terminationGracePeriodSeconds; $scope.instance.hostIp = pod.status.hostIP; $scope.instance.podIp = pod.status.podIP; $scope.instance.phase = pod.status.phase; $scope.instance.volumes = pod.spec.volumes; $scope.instance.metadata = pod.metadata; $scope.instance.imagePullSecrets = pod.spec.imagePullSecrets; $scope.instance.containers = pod.spec.containers; $scope.instance.containerStatuses = pod.status.containerStatuses; setBaseIpAddress(); }, autoClose ); } if (!instanceSummary) { $scope.instanceIdNotFound = instance.instanceId; $scope.state.loading = false; } return $q.when(null); } const setBaseIpAddress = () => { this.baseIpAddress = kubernetesProxyUiService.getInstanceLink($scope.instance.account, $scope.instance); }; function autoClose() { if ($scope.$$destroyed) { return; } $state.params.allowModalToStayOpen = true; $state.go('^', null, {location: 'replace'}); } this.terminateInstance = function terminateInstance() { var instance = $scope.instance; var taskMonitor = { application: app, title: 'Terminating ' + instance.instanceId, onTaskComplete: function() { if ($state.includes('**.instanceDetails', {instanceId: instance.instanceId})) { $state.go('^'); } } }; var submitMethod = function () { let params = {cloudProvider: 'kubernetes'}; if (instance.serverGroup) { params.managedInstanceGroupName = instance.serverGroup; } params.namespace = instance.namespace; instance.placement = {}; return instanceWriter.terminateInstance(instance, app, params); }; confirmationModalService.confirm({ header: 'Really terminate ' + instance.instanceId + '?', buttonText: 'Terminate ' + instance.instanceId, account: instance.account, provider: 'kubernetes', taskMonitorConfig: taskMonitor, submitMethod: submitMethod }); }; this.registerInstanceWithLoadBalancer = function registerInstanceWithLoadBalancer() { var instance = $scope.instance; var loadBalancerNames = instance.loadBalancers.join(' and '); var taskMonitor = { application: app, title: 'Registering ' + instance.name + ' with ' + loadBalancerNames }; var submitMethod = function () { return instanceWriter.registerInstanceWithLoadBalancer(instance, app, { interestingHealthProviderNames: ['Kubernetes'] } ); }; confirmationModalService.confirm({ header: 'Really register ' + instance.name + ' with ' + loadBalancerNames + '?', buttonText: 'Register ' + instance.name, account: instance.account, taskMonitorConfig: taskMonitor, submitMethod: submitMethod }); }; this.deregisterInstanceFromLoadBalancer = function deregisterInstanceFromLoadBalancer() { var instance = $scope.instance; var loadBalancerNames = instance.loadBalancers.join(' and '); var taskMonitor = { application: app, title: 'Deregistering ' + instance.name + ' from ' + loadBalancerNames }; var submitMethod = function () { return instanceWriter.deregisterInstanceFromLoadBalancer(instance, app, { interestingHealthProviderNames: ['Kubernetes'] } ); }; confirmationModalService.confirm({ header: 'Really deregister ' + instance.name + ' from ' + loadBalancerNames + '?', buttonText: 'Deregister ' + instance.name, provider: 'kubernetes', account: instance.account, taskMonitorConfig: taskMonitor, submitMethod: submitMethod }); }; this.canRegisterWithLoadBalancer = function() { var instance = $scope.instance; if (!instance.loadBalancers || !instance.loadBalancers.length) { return false; } return instance.health.some(function(health) { return health.state === 'OutOfService'; }); }; this.canDeregisterFromLoadBalancer = function() { var instance = $scope.instance; if (!instance.loadBalancers || !instance.loadBalancers.length) { return false; } return instance.healthState !== 'OutOfService'; }; this.hasHealthState = function hasHealthState(healthProviderType, state) { var instance = $scope.instance; return (instance.health.some(function (health) { return health.type === healthProviderType && health.state === state; }) ); }; let initialize = app.isStandalone ? retrieveInstance() : $q.all([app.serverGroups.ready(), app.loadBalancers.ready()]).then(retrieveInstance); initialize.then(() => { // Two things to look out for here: // 1. If the retrieveInstance call completes *after* the user has navigated away from the view, there // is no point in subscribing to the refresh // 2. If this is a standalone instance, there is no application that will refresh if (!$scope.$$destroyed && !app.isStandalone) { app.serverGroups.onRefresh($scope, retrieveInstance); app.serverGroups.onRefresh($scope, retrieveInstance); } }); $scope.account = instance.account; } );
{ "content_hash": "3cddb50f918ba9c76e6081de56e5b96a", "timestamp": "", "source": "github", "line_count": 284, "max_line_length": 148, "avg_line_length": 36.644366197183096, "alnum_prop": 0.6190064379744403, "repo_name": "kenzanlabs/deck", "id": "40a7550db94e07380932a0231eb7503819f8917b", "size": "10407", "binary": false, "copies": "1", "ref": "refs/heads/master", "path": "app/scripts/modules/kubernetes/instance/details/details.controller.js", "mode": "33188", "license": "apache-2.0", "language": [ { "name": "ApacheConf", "bytes": "24139" }, { "name": "CSS", "bytes": "124574" }, { "name": "HTML", "bytes": "1293823" }, { "name": "JavaScript", "bytes": "3000460" }, { "name": "Shell", "bytes": "2126" } ], "symlink_target": "" }
package org.hisp.dhis.schema.descriptors; import org.hisp.dhis.eventchart.EventChart; import org.hisp.dhis.schema.Authority; import org.hisp.dhis.schema.AuthorityType; import org.hisp.dhis.schema.Schema; import org.hisp.dhis.schema.SchemaDescriptor; import org.springframework.stereotype.Component; import com.google.common.collect.Lists; @Component public class EventChartSchemaDescriptor implements SchemaDescriptor { public static final String SINGULAR = "eventChart"; public static final String PLURAL = "eventCharts"; public static final String API_ENDPOINT = "/" + PLURAL; @Override public Schema getSchema() { Schema schema = new Schema( EventChart.class, SINGULAR, PLURAL ); schema.setRelativeApiEndpoint( API_ENDPOINT ); schema.setShareable( true ); schema.setOrder( 1540 ); schema.getAuthorities().add( new Authority( AuthorityType.CREATE_PUBLIC, Lists.newArrayList( "F_EVENTCHART_PUBLIC_ADD" ) ) ); schema.getAuthorities().add( new Authority( AuthorityType.EXTERNALIZE, Lists.newArrayList( "F_EVENTCHART_EXTERNAL" ) ) ); return schema; } }
{ "content_hash": "aab242f065bfe80cc3d5c97efa2938ce", "timestamp": "", "source": "github", "line_count": 37, "max_line_length": 133, "avg_line_length": 31.054054054054053, "alnum_prop": 0.7302001740644039, "repo_name": "kakada/dhis2", "id": "0d2b4b89a328d7d3415ecd4a1be583c67271e47e", "size": "2705", "binary": false, "copies": "1", "ref": "refs/heads/master", "path": "dhis-api/src/main/java/org/hisp/dhis/schema/descriptors/EventChartSchemaDescriptor.java", "mode": "33188", "license": "bsd-3-clause", "language": [ { "name": "CSS", "bytes": "396164" }, { "name": "Game Maker Language", "bytes": "20893" }, { "name": "HTML", "bytes": "340997" }, { "name": "Java", "bytes": "18116166" }, { "name": "JavaScript", "bytes": "7103857" }, { "name": "Ruby", "bytes": "1011" }, { "name": "Shell", "bytes": "376" }, { "name": "XSLT", "bytes": "24103" } ], "symlink_target": "" }
class DocumentsController < ApplicationController layout nil before_action :bouncer, :only => [:show] if Rails.env.staging? before_action :login_required, :only => [:update, :destroy] before_action :prefer_secure, :only => [:show] before_action :api_login_optional, :only => [:send_full_text, :send_pdf, :send_page_text, :send_page_image] before_action :set_p3p_header, :only => [:show] after_action :allow_iframe, :only => [:show] skip_before_action :verify_authenticity_token, :only => [:send_page_text] SIZE_EXTRACTOR = /-(\w+)\Z/ PAGE_NUMBER_EXTRACTOR = /.*-p(\d+)/ def show Account.login_reviewer(params[:key], session, cookies) if params[:key] doc = current_document(true) return forbidden if doc.nil? && Document.exists?(params[:id].to_i) return render :file => "#{Rails.root}/public/doc_404.html", :status => 404 unless doc respond_to do |format| format.html do @no_sidebar = (params[:sidebar] || '').match /no|false/ populate_editor_data if current_account && current_organization return if date_requested? return if entity_requested? end format.pdf { redirect_to(doc.pdf_url) } format.text { redirect_to(doc.full_text_url) } format.json do @response = doc.canonical json_response end format.js do js = "DV.loadJSON(#{doc.canonical.to_json});" cache_page js if doc.cacheable? render :js => js end format.xml do render :xml => doc.canonical.to_xml(:root => 'document') end format.rdf do @doc = doc end end end def update return not_found unless doc = current_document(true) attrs = pick(params, :access, :title, :description, :source, :related_article, :remote_url, :publish_at, :data, :language) success = doc.secure_update attrs, current_account return json(doc, 403) unless success clear_current_document_cache Document.populate_annotation_counts(current_account, [doc]) json doc end def destroy return not_found unless doc = current_document(true) if !current_account.owns_or_collaborates?(doc) doc.errors.add(:base, "You don't have permission to delete the document." ) return json(doc, 403) end clear_current_document_cache doc.destroy json nil end def redact_pages return not_found unless params[:redactions] && (doc = current_document(true)) doc.redact_pages JSON.parse(params[:redactions]), params[:color] json doc end def remove_pages return not_found unless doc = current_document(true) doc.remove_pages(params[:pages].map {|p| p.to_i }) json doc end def reorder_pages return not_found unless doc = current_document(true) return json(nil, 409) if params[:page_order].length != doc.page_count doc.reorder_pages params[:page_order].map {|p| p.to_i } json doc end def upload_insert_document return not_found unless doc = current_document(true) return json(nil, 409) unless params[:file] && params[:document_number] && (params[:insert_page_at] || params[:replace_pages_start]) DC::Import::PDFWrangler.new.ensure_pdf(params[:file], params[:Filename]) do |path| DC::Store::AssetStore.new.save_insert_pdf(doc, path, params[:document_number]+'.pdf') if params[:document_number] == params[:document_count] if params[:replace_pages_start] range = (params[:replace_pages_start].to_i..params[:replace_pages_end].to_i).to_a doc.remove_pages(range, params[:replace_pages_start].to_i, params[:document_count].to_i) else doc.insert_documents(params[:insert_page_at], params[:document_count].to_i) end end end if params[:multi_file_upload] json doc else @document = doc end end def save_page_text return not_found unless doc = current_document(true) modified_pages = JSON.parse(params[:modified_pages]) doc.save_page_text(modified_pages) unless modified_pages.empty? json doc end def loader render :action => 'loader.js.erb', :content_type => :js end def entities ids = Document.accessible(current_account, current_organization).where({:id => params[:ids]}).pluck('id') json 'entities' => Entity.where({ :document_id => ids }) end def entity if params[:entity_id] entity = Entity.find(params[:entity_id]) entities = [] entities << entity if Document.accessible(current_account, current_organization).find_by_id(entity.document_id) else ids = Document.accessible(current_account, current_organization).where({:id => params[:ids]}).pluck('id') entities = Entity.search_in_documents(params[:kind], params[:value], ids) end json({'entities' => entities}.to_json(:include_excerpts => true)) end def dates if params[:id] result = {} entity = EntityDate.find(params[:id]) if Document.accessible(current_account, current_organization).find_by_id(entity.document_id) result = {'date' => entity}.to_json(:include_excerpts => true) end return json(result) end ids = Document.accessible(current_account, current_organization).where({:id => params[:ids]}).pluck('id') dates = EntityDate.where( :document_id => ids).includes(:document) json({'dates' => dates}.to_json) end def occurrence entity = Entity.find(params[:id]) occurrence = Occurrence.new(*(params[:occurrence].split(':') + [entity])) json :excerpts => entity.excerpts(200, {}, [occurrence]) end def mentions return not_found unless doc = current_document(true) mention_data = Page.mentions(doc.id, params[:q], nil) json :mentions => mention_data[:mentions], :total_mentions => mention_data[:total] end # Allows us to poll for status updates in the in-progress document uploads. def status docs = Document.accessible(current_account, current_organization).where({:id => params[:ids]}) Document.populate_annotation_counts(current_account, docs) render :json => { 'documents' => docs.map{|doc| doc.as_json(:cache_busting=>true) } } end # TODO: Fix the note/annotation terminology. def per_page_note_counts json current_document(true).per_page_annotation_counts end def queue_length json 'queue_length' => Document.pending.count end def reprocess_text return not_found unless doc = current_document(true) return json(nil, 403) unless current_account.allowed_to_edit?(doc) doc.reprocess_text(params[:ocr]) json nil end def send_pdf return not_found unless current_document(true) redirect_to current_document.pdf_url(:direct) end def send_page_image return not_found unless current_page size = params[:page_name][SIZE_EXTRACTOR, 1] response.headers["Cache-Control"] = "no-store" redirect_to(current_page.authorized_image_url(size)) end def send_full_text maybe_set_cors_headers return not_found unless current_document(true) redirect_to current_document.full_text_url(:direct) end def send_page_text maybe_set_cors_headers return not_found unless current_page @response = current_page.text return if jsonp_request? render :plain => @response end def set_page_text return not_found unless current_page return forbidden unless current_account.allowed_to_edit?(current_page) json current_page.update_attributes(pick(params, :text)) end def search doc = current_document(true) pages = Page.search_for_page_numbers(params[:q], doc) @response = {'query' => params[:q], 'results' => pages} json_response end def preview return unless login_required doc = current_document(true) return forbidden if doc.nil? && Document.exists?(params[:id].to_i) return not_found unless doc @options = params[:options] end private def populate_editor_data @edits_enabled = true @allowed_to_edit = current_account.allowed_to_edit?(current_document) @allowed_to_review = current_account.reviews?(current_document) @reviewer_inviter = @allowed_to_review && current_document.reviewer_inviter(current_account) || nil end def date_requested? return false unless params[:date] begin date = Time.at(params[:date].to_i).to_date rescue RangeError => e return false end meta = current_document.entity_dates.where(:date=>date).first redirect_to current_document.document_viewer_url(:date => meta, :allow_ssl => true) end def entity_requested? return false unless params[:entity] meta = current_document.entities.find(params[:entity]) page = Occurrence.new(params[:offset], 0, meta).page redirect_to current_document.document_viewer_url(:entity => meta, :page => page.page_number, :offset => params[:offset], :allow_ssl => true) end def current_document(exists=false) @current_document ||= exists ? Document.accessible(current_account, current_organization).find_by_id(params[:id].to_i) : Document.new(:id => params[:id].to_i) end def current_page num = params[:page_name][PAGE_NUMBER_EXTRACTOR, 1] return false unless num return false unless current_document(true) @current_page ||= current_document.pages.find_by_page_number(num.to_i) end def clear_current_document_cache expire_page current_document.canonical_cache_path current_document.annotations.each{ |note| expire_page note.canonical_cache_path } end end
{ "content_hash": "d4989a5d8d844c2ad3b23eabc60797aa", "timestamp": "", "source": "github", "line_count": 283, "max_line_length": 144, "avg_line_length": 33.908127208480565, "alnum_prop": 0.6670487703209671, "repo_name": "dannguyen/documentcloud", "id": "a5d5f4934692135c396648a4286ade452bb66f4c", "size": "9596", "binary": false, "copies": "2", "ref": "refs/heads/master", "path": "app/controllers/documents_controller.rb", "mode": "33188", "license": "mit", "language": [ { "name": "CSS", "bytes": "156414" }, { "name": "HTML", "bytes": "185947" }, { "name": "JavaScript", "bytes": "534312" }, { "name": "Nginx", "bytes": "2493" }, { "name": "Ruby", "bytes": "527799" }, { "name": "Shell", "bytes": "21996" }, { "name": "XSLT", "bytes": "24923" } ], "symlink_target": "" }
package com.example.moon.weather.Bean; /** * Created by Administrator on 2016/4/1. */ public class Suggestion { private SuggestionMessage comf; private SuggestionMessage cw; private SuggestionMessage drsg; private SuggestionMessage flu; private SuggestionMessage sport; private SuggestionMessage trav; private SuggestionMessage uv; public SuggestionMessage getComf() { return comf; } public void setComf(SuggestionMessage comf) { this.comf = comf; } public SuggestionMessage getCw() { return cw; } public void setCw(SuggestionMessage cw) { this.cw = cw; } public SuggestionMessage getDrsg() { return drsg; } public void setDrsg(SuggestionMessage drsg) { this.drsg = drsg; } public SuggestionMessage getFlu() { return flu; } public void setFlu(SuggestionMessage flu) { this.flu = flu; } public SuggestionMessage getSport() { return sport; } public void setSport(SuggestionMessage sport) { this.sport = sport; } public SuggestionMessage getTrav() { return trav; } public void setTrav(SuggestionMessage trav) { this.trav = trav; } public SuggestionMessage getUv() { return uv; } public void setUv(SuggestionMessage uv) { this.uv = uv; } public static class SuggestionMessage { private String brf; private String txt; public String getBrf() { return brf; } public void setBrf(String brf) { this.brf = brf; } public String getTxt() { return txt; } public void setTxt(String txt) { this.txt = txt; } } }
{ "content_hash": "748458e0062e91a0f8c887414688b374", "timestamp": "", "source": "github", "line_count": 91, "max_line_length": 51, "avg_line_length": 19.86813186813187, "alnum_prop": 0.5923672566371682, "repo_name": "tangzhimang/Weather", "id": "6b7939ec4341ddfd22137546d87fa9e54072997c", "size": "1808", "binary": false, "copies": "1", "ref": "refs/heads/master", "path": "app/src/main/java/com/example/moon/weather/Bean/Suggestion.java", "mode": "33188", "license": "apache-2.0", "language": [ { "name": "Java", "bytes": "59882" } ], "symlink_target": "" }