Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
dev:translators:scaffold [2012/02/24 00:52] – [Installation] removing link to old version ajlyondev:translators:scaffold [2024/04/26 06:57] (current) – [Scaffold - an IDE for Zotero translators] dstillman
Line 1: Line 1:
 ====== Scaffold - an IDE for Zotero translators ====== ====== Scaffold - an IDE for Zotero translators ======
  
-Translators are stored as individual JavaScript files in the "translators" subdirectory of the [[:zotero_data|Zotero data directory]]. While translators can be edited with any tool, Scaffold is a Firefox add-on dedicated to writing Zotero translators, offering advantages such as real-time testing and debugging.+[[dev:translators|Translators]] are stored as individual JavaScript files with additional metadata at the top and tests at the bottom in the "translators" subdirectory of the [[:zotero_data|Zotero data directory]]. While translators can be edited with any tool, Scaffold is dedicated to writing Zotero translators, offering advantages such as real-time testing and debugging.
  
 Scaffold supports editing and testing web translators and import translators. Search and export translators can not yet be tested using the IDE. Scaffold supports editing and testing web translators and import translators. Search and export translators can not yet be tested using the IDE.
-===== Installation ===== 
  
-  * [[http://gimranov.com/research/zotero/scaffold-3.0.xpi|Install Scaffold 3.0]] (compatible with Zotero 3.0 and Zotero Multilingual) 
  
-Scaffold 3 includes support for the [[dev:translators:testing|automated translator testing]] system that was introduced in Zotero 2.1.9, as well as for specifying [[dev:translators:connectors|connector compatibility]]. Documentation for these features is not yet available. 
  
-Scaffold does not run in Zotero Standalone. 
 ===== Interface ===== ===== Interface =====
  
-After installation, the "Tools" menu in Firefox should contain a "Scaffold" itemSelecting this item opens the main Scaffold window:+Scaffold is available via Tools → Developer → Translator Editor in Zotero.
  
-{{:dev:scaffold2.0-metadata.png?640&nocache&nolink|}}+When you first open Scaffold, you'll need to select your translator development directory. In most cases, this should be a git clone of the [[https://github.com/zotero/translators|Zotero translators repository]] on GitHub. 
 + 
 +After selecting your translator directory, the main Scaffold window will open: 
 + 
 +{{:dev:translators:scaffold_new_small.png?750&nocache&nolink|}}
  
 ==== Top buttons ==== ==== Top buttons ====
  
-{{:dev:load.png?nocache&nolink|}} **Load** \\ +{{:dev:load.png?nocache&nolink|}} **Open** \\ 
 Opens the "Load Translator" window. Select one of the currently installed translators, and load the translator metadata and code into Scaffold. Opens the "Load Translator" window. Select one of the currently installed translators, and load the translator metadata and code into Scaffold.
  
Line 25: Line 25:
 Saves the translator you are currently working on. Provide a unique label and translator ID for your translator if you don't want to overwrite an existing translator. New translator IDs can be automatically generated via the "Generate" button. Saves the translator you are currently working on. Provide a unique label and translator ID for your translator if you don't want to overwrite an existing translator. New translator IDs can be automatically generated via the "Generate" button.
  
-{{:dev:detectweb.png?nocache&nolink|}} **Run detectWeb** \\  +{{:dev:translators:savetozotero.png?16&nocache&nolink|}} **Save to Zotero** \\ 
-Saves and runs the ''detectWeb'' function of the translator code on the site loaded in the most recently selected tab.+Saves the translator you are currently working on and writes it to the "translators" subdirectory of the Zotero data directory, making it available to the client and Zotero Connector. (To use it in the Connector, open the Connector preferences to the Advanced tab and click Reset Translators.) 
 + 
 +{{:dev:translators:detectweb.png?16&nocache&nolink|}} **Run detect*** \\  
 +Saves and runs the appropriate ''detect'' function: 
 +  * If it's a web translator and a page is loaded in the Browser tab: ''detectWeb'' 
 +  * If it's an import translator and data has been entered in the Test Data tab: ''detectImport'' 
 +  * If it's a search translator and a JSON search object has been entered in the Test Data tab: ''detectSearch'' 
 + 
 +{{:dev:translators:doweb.png?16&nocache&nolink|}} **Run do*** \\  
 +Saves and runs the appropriate ''do'' function of the translator code. Runs the corresponding ''do'' functions for the above situations, plus: 
 +  * If it's an export translator and an item is selected in the main Zotero window: ''doExport''
  
-{{:dev:doweb.png?nocache&nolink|}} **Run doWeb** \\  
-Saves and runs the ''doWeb'' function of the translator code on the site loaded in the most recently selected tab. 
  
 ==== Tabs ==== ==== Tabs ====
Line 35: Line 43:
 **Metadata** \\ Shows the translator metadata. Translator IDs can be generated via the "Generate" button. The target regular expression can be tested with the "Test Regex" button. **Metadata** \\ Shows the translator metadata. Translator IDs can be generated via the "Generate" button. The target regular expression can be tested with the "Test Regex" button.
  
-**Code** \\ The text box in this tab contains the translator's JavaScript code:+**Code** \\ The text box in this tab contains the translator's JavaScript code. The editor supports syntax highlighting, folding of code parts, search and replace, basic type inference, code suggestions, Zotero-specific hints when hovering over an item type or translator UUID string, and more. The editor also integrates ESLint, and you'll be prompted to set it up when you begin using Scaffold.
  
-{{:dev:scaffold2.0-code.png?640&nocache&nolink|}}+**Tests**\\ This tab contains the list of tests saved in the translator, as well as the raw JSON and expected output for each oneYou can run or update tests from here. Create tests from the corresponding tab for the type of test you want to create (Browser or Test Data). 
 + 
 +**Test Data** \\ Input data for import and search translators. 
 + 
 +**Browser**\\ View sites and test detection and data extraction.
  
 ==== Debug Output ==== ==== Debug Output ====
Line 44: Line 56:
  
 === Metadata === === Metadata ===
-When the "Test Regex" button in the "Metadata" tab is clicked, the regular expression in the target field is applied to the site loaded in the most recently selected Firefox tab. The debug window at the right of the Scaffold window will show whether the regular expression matches (''true'' for a match, ''false'' for no match), e.g.:+When the "Test Regex" button in the "Metadata" tab is clicked, the regular expression in the target field is applied to the site loaded in the Browser tab. The debug window at the right of the Scaffold window will show whether the regular expression matches (''true'' for a match, ''false'' for no match), e.g.:
  
 <code> <code>
Line 93: Line 105:
 If running ''detectWeb'' or ''doWeb'' results in an error, the debug window will show an error message. For debugging, additional debug output can be added to the code by adding ''Zotero.debug(string);'' statements. If running ''detectWeb'' or ''doWeb'' results in an error, the debug window will show an error message. For debugging, additional debug output can be added to the code by adding ''Zotero.debug(string);'' statements.
  
-===== Import Translators ===== +===== Import, Export, and Search Translators ===== 
-Starting with version 2.1.2, Scaffold can be used to test import translators. To do so, enter the test import data in the "Import" tab and use the "Run detectImport" and "Run doImport" buttons to test the translator against the data. The output will be displayed in the right-hand pane as with web translators.+Starting with version 6.0, Scaffold can be used to test import, export, and search translators. To test an import or search translator, enter the test data in the "Test Data" tab and use the "Run detect*" and "Run *" buttons to test the translator against the data. The output will be displayed in the right-hand pane as with web translators. For export translators, select an item in the main Zotero window to use it for testing.
  
 In the translator load window, import translators are arranged in alphabetical order at the bottom of the list. In the translator load window, import translators are arranged in alphabetical order at the bottom of the list.
  
-**Note:** The screenshots on this page do not reflect the changes made in Scaffold 2.1.2 to add support for import translators. 
  
 ===== Scaffold Troubleshooting ===== ===== Scaffold Troubleshooting =====
-  * **Why does my translator work in Scaffold but not when I click on the address bar icon in my browser?** 
-Scaffold runs the functions ''detectWeb'' and ''doWeb'' against the active document in the top Firefox window. Outside of Scaffold, clicking the address bar icon runs the first web translator with a matching ''target'' regular expression that returns a non-false value from the function ''detectWeb'', when run on that document and URL. 
  
-This can differ from the active document in Firefox when the ''target'' expression or ''detectWeb'' conditions are too lax, which can allow embedded documents, such as IFRAMES used for advertising or sharing panes, to be detected as content pages. To see if this is what is happening, look at the debug output for a save attempt from Firefox proper and check the URL that is being processed.+**Why does my translator work in Scaffold but not when I click the Save to Zotero button in my browser?** 
 +Scaffold runs the functions ''detectWeb'' and ''doWeb'' against the document in the Browser tab. In your browser, clicking the toolbar button runs the first web translator with a matching ''target'' regular expression that returns a non-false value from the ''detectWeb'' function when run on that document and URL. 
 + 
 +These results can differ when the ''target'' expression or ''detectWeb'' conditions are too lax, which can allow embedded documents, such as ''iframe''used for advertising or sharing panes, to be detected as content pages by the Zotero Connector. To see if this is what is happening, look at the Zotero Connector'debug output for a save attempt in your browser and check the URL that is being processed
 + 
 +**Why won't my attachments save?** 
 + 
 +The output pane in Scaffold shows the item object as Zotero is about to save it. It does not in fact save the object. 
 + 
 +**Why do some fields show in the output pane but not in the created item?** 
 + 
 +As an item is saved, the contents of some fields may change. 
 + 
 +The attachment information in the output pane of Scaffold merely says what Zotero is going to try to save; as the attachments are saved, they may be discarded if their actual content type differs from the one specified, as can happen when PDFs or other attachments are hidden by providers behind an interstitial terms or copyright notice page.
  
-  * **Why won't my attachments save?** +Fields that are not allowed for the specified item type will be added to the Extra fieldeven if they show up in the output pane of Scaffold.
-  * **Why do some fields show in the output pane but not in the created item?** +
-The output pane in Scaffold shows the item object as Zotero is about to save it-- it does not in fact save the object. As an item is saved, the contents of some fields may change.+
  
-The attachment information in the output pane of Scaffold merely says what Zotero is going to try to save; as the attachments are saved, they may be discarded if their actual MIME type differs from the one specified, as can happen when PDFs or other attachments are hidden by providers behind an interstitial terms or copyright notice page.+====== Further Reading ======
  
-Fields that are not allowed for the specified item type will be discarded, even if they show up in the output pane of Scaffold.+More detailed instructions are available at [[https://www.mediawiki.org/wiki/Citoid/Creating_Zotero_translators|MediaWiki]]. These instructions may be slightly out of date.
dev/translators/scaffold.1330062724.txt.gz · Last modified: 2012/02/24 00:52 by ajlyon