Thread: [Refdb-cvs] CVS: makestyle Makestyle.pm,1.1,1.2
Status: Beta
Brought to you by:
mhoenicka
From: David N. <dav...@us...> - 2005-09-19 13:55:27
|
Update of /cvsroot/refdb/makestyle In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25207 Modified Files: Makestyle.pm Log Message: Support version 1.4 of dtd. URL renamed to LINK with role 0. Index: Makestyle.pm =================================================================== RCS file: /cvsroot/refdb/makestyle/Makestyle.pm,v retrieving revision 1.1 retrieving revision 1.2 diff -u -U2 -r1.1 -r1.2 --- Makestyle.pm 19 Sep 2005 12:01:17 -0000 1.1 +++ Makestyle.pm 19 Sep 2005 13:55:14 -0000 1.2 @@ -449,5 +449,5 @@ while ( 1 ) { $value = $self->_input_choice( "Select value:" , $self->get_enumeration() ); - if ( $value ) { last; } + if ( defined( $value ) ) { last; } print "Invalid choice. Sorry, please try again.\n"; } @@ -549,5 +549,5 @@ while ( 1 ) { $value = $self->_input_choice( "Select value: " , $self->get_enumeration() ); - if ( $value ) { last; } + if ( defined( $value ) ) { last; } print "Invalid choice. Sorry, please try again.\n"; } @@ -745,5 +745,5 @@ while ( 1 ) { $value = $self->_input_choice( "Select value: " , sort( $self->get_enumeration() ) ); - if ( $value ) { last; } + if ( defined( $value ) ) { last; } print "Invalid choice. Sorry, please try again.\n"; } @@ -798,5 +798,60 @@ while ( 1 ) { $value = $self->_input_choice( "Select value: " , sort( $self->get_enumeration() ) ); - if ( $value ) { last; } + if ( defined( $value ) ) { last; } + print "Invalid choice. Sorry, please try again.\n"; + } + $_level{$value} = 1; + $self->{value} = $value; + } + } + + sub DESTROY { if ( $_[0]->get_value() ) { $_level{$_[0]->get_value()} = 0 ; } } + + sub select_value { } + + sub get_enumeration { + my ( @enum , $key , $value ) = ( () ); + while ( ( $key , $value ) = each %_level ) { + if ( not ( $_level{$key} ) ) { push( @enum , $key ); } + } + return @enum; + } + + sub reset_counter { foreach ( keys %_level ) { $_level{$_} = 0; } } + +package Role_Link; + use base qw/ _Attribute /; + + our %_level = ( + "0" => 0 , + "1" => 0 , + "2" => 0 , + "3" => 0 , + "4" => 0 , + ); + + sub new { + my $proto = shift; + my $class = ref($proto) || $proto; + my $self = $class->SUPER::new(@_); + $self->set_name ( "ROLE" ); + $self->add_enumeration( qw/ 0 1 2 3 4 / ); + $self->set_default ( "0" ); + $self->set_prompt ( "Determines which link field the enclosing element refers to: 1-4 correspond to L1-L4, 0 corresponds to UR. Each possible option can be used in only one attribute." ); + $self->set_summary( 1 ); + $self->_assign_level(); + return defined( $self->get_value() ) ? $self : "Error: Maximum number of " . $self->get_name() . " attributes already exist for element LINK."; + } + + # Class-specific + + sub _assign_level { + my ( $self , $value ) = ( shift , undef ); + if ( scalar( $self->get_enumeration() ) != 0 ) { + print "Attribute: " . $self->get_name() . "\n"; + print $self->_display( $self->get_prompt() ); + while ( 1 ) { + $value = $self->_input_choice( "Select value: " , sort( $self->get_enumeration() ) ); + if ( defined( $value ) ) { last; } print "Invalid choice. Sorry, please try again.\n"; } @@ -2162,5 +2217,5 @@ B<model_order> -With I<model_noorder> this data member determines the content model for children elements. All of the 64 elements (LINK is excluded) fall into one of three content models regarding children elements: 1. No children elements, 2. An ordered list and 3. An unordered list. +With I<model_noorder> this data member determines the content model for children elements. All of the 64 elements fall into one of three content models regarding children elements: 1. No children elements, 2. An ordered list and 3. An unordered list. This data member is C<undef> in cases (1) and (3). @@ -2181,5 +2236,5 @@ B<model_noorder> -With I<model_order> this data member determines the content model for children elements. All of the 64 elements (LINK is excluded) fall into one of three content models regarding children elements: 1. No children elements, 2. An ordered list and 3. An unordered list. +With I<model_order> this data member determines the content model for children elements. All of the 64 elements fall into one of three content models regarding children elements: 1. No children elements, 2. An ordered list and 3. An unordered list. This data member is C<undef> in cases (1) and (2). @@ -2886,5 +2941,5 @@ while ( 1 ) { $choice = $self->_input_choice( "Select attribute to add:" , @attributes ); - if ( $choice ) { last; } + if ( defined( $choice ) ) { last; } print "Invalid choice. Sorry, please try again.\n"; } @@ -3352,5 +3407,5 @@ while ( 1 ) { $choice = $self->_input_choice( "Select child element to add:" , @menu ); - if ( $choice ) { last; } + if ( defined( $choice ) ) { last; } print "Invalid choice. Sorry, please try again.\n"; } @@ -3437,5 +3492,5 @@ Can test for success using C<ref> function. -Does not copy attributes. Attributes requiring user input during creation are not copyable (this includes Type_PubType, Role_UserDef and Role_Misc). +Does not copy attributes. Attributes requiring user input during creation are not copyable (this includes Type_PubType, Role_UserDef, Role_Misc and Role_Link). Does not copy child elements. For that, use the C<duplicate> method. @@ -3824,5 +3879,5 @@ sub reset_all_counters { - foreach ( qw/ Role_AuthorList Role_PubDate Role_Title Role_UserDef Role_Misc / ) { + foreach ( qw/ Role_AuthorList Role_PubDate Role_Title Role_UserDef Role_Misc Role_Link / ) { $_->reset_counter(); } @@ -4238,5 +4293,5 @@ } ); $self->set_noorder( { - element_list => [ "RefNumber" , "AuthorList" , "PubDate" , "Title" , "JournalName" , "Volume" , "Issue" , "Pages" , "Publisher" , "PubPlace" , "Serial" , "Address" , "UserDef" , "Misc" , "Notes" , "Abstract" ] , + element_list => [ "RefNumber" , "AuthorList" , "PubDate" , "Title" , "JournalName" , "Volume" , "Issue" , "Pages" , "Publisher" , "PubPlace" , "Serial" , "Address" , "UserDef" , "Misc" , "Notes" , "Abstract" , "Link" ] , separator => "Separator" , } ); @@ -5132,4 +5187,34 @@ } +package Link; + use base qw/ _Model_Order /; + + sub new { + my $proto = shift; + my $class = ref($proto) || $proto; + my $self = $class->SUPER::new(@_); + $self->set_name( "LINK" ); + $self->set_prompt( "Specifies the location of a UR field or a link field [L1 - L4]. Determines how the field's contents are formatted." ); + $self->set_help( "Specifies the location of a link field [can be any of UR, L1, L2, L3, L4] in the citation reference. Determines how the field's contents are formatted." ); + $self->set_display( "name" ); + $self->set_summary( "name" ); + $self->set_attributes( { + mandatory => [ "Role_Link" ] , + optional => [ "Style" ] , + } ); + $self->set_order( [ + [ "Preceeding" , "?" ] , + [ "Following" , "?" ] , + ] ); + return $self; + } + + # Class methods + sub default_copyable { undef; } + + sub _test_attributes_mandatory { # override to prevent Role_Link dialog + return Role_Link->get_enumeration(); + } + package Separator; use base qw/ _Model_Childless /; @@ -5718,5 +5803,5 @@ "HELP TOPIC: XML\n\nRefDB style files are well-formed XML files which conform to the \"citestylex\" dtd. While this utility makes generating style files easier than writing them \"by hand\", you should still have some understanding of xml before using it. This is the briefest of introductions to the topic. Several concepts are greatly simplified.\n\nXML is the \"eXtensible Markup Language\". For the purposes of RefDB stylesheets, the central feature of XML is \"elements\". An element is a unit of information. It has the following features: a name, opening and closing tags, attributes and content. Here is an example element:\n\n<ABBREVIATEFIRST DISPLAYAUTHOR=\"255\" MAXAUTHOR=\"256\" STYLE=\"ITALIC\">et al.</ABBREVIATEFIRST>\n\nName:\nThe element's name is ABBREVIATEFIRST.\n\nTags:\nThe element is bounded by opening and closing tags which consist primarily of the element name enclosed in angle brackets. The opening tag has the form '<ELEMENT>'. The closing tag has the form '</ELEMENT>' -- note the slash preceding the element name.\n\nAttributes:\nAn element can have associated attributes. Attributes have names and values. In the example element above there are three attributes: DISPLAYAUTHOR, MAXAUTHOR and STYLE. Attributes are placed inside an element's opening tag after the element name. They are separated by spaces. Most attributes have a list of possible legal values (an \"enumeration\"). Some can accept any value.\n\nContent:\nAn element's content appears between the opening and closing tags. There are few restrictions on element content.\n\n\nFinally, a note about DTDs. In order for XML documents to be useful there must be agreement about the meanings elements and attributes have. One means of specifying these meanings is a Document Type Definition (DTD). A DTD is a set of rules about what element names are legal and in what sequence they can occur, what attributes are associated with each element and what attribute values are legal. The \"citestylex\" DTD determines the structure of RefDB styles. This DTD is included with the RefDB installation."; $cache->{"3. Styles"} = - "HELP TOPIC: Styles\n\nAs mentioned in help topic <RefDB> \"styles\" provide rules for RefDB to follow when formatting bibliographies and citations. Each style is defined in an XML document that conforms to the \"citestylex\" DTD (see help topic <XML> for the briefest of introductions to XML). It will be most advantageous to have some understanding of XML before attempting to use this utility.\n\nEach style file can be divided broadly into four sections.\n\nFIRST SECTION (STYLENAME element)\nThe first section specifies the xml version, the controlling DTD and the style name. It includes the STYLENAME element.\n\nSECOND SECTION (REFSTYLE and PUBSTYLE elements)\nThe second section contains formatting rules for bibliography references. The REFSTYLE element includes a number of PUBSTYLE elements. Each PUBSTYLE element contains a number of subsidiary elements. Each PUBSTYLE element and its children specify formatting rules for a particular type of publication. There are 35 possible publication types, including book, journal and electronic citation. The publication type each PUBTYPE applies to is determined by PUBTYPE's TYPE attribute.\n\nThere are two kinds of elements in each PUBTYPE. One type specifies a component of the reference, for example, the TITLE element signifies the title of each reference work and the AUTHORLIST signifies the list of authors of a given work. These elements have a one-to-one correspondence with reference record ris fields. For example, the VOLUME element corresponds to the ris VL field. (See help topic <Using this utility> for how to access this information while creating your style.) Their presence in the PUBTYPE signifies the presence of the associated component in the bibliography reference. Also, their location in the PUBTYPE signifies the location of the associated component in the bibliography reference. For example, if you put AUTHORLIST first in a PUBTYPE, then the authors will appear first in the reference. If you put REFNUMBER first, the reference will begin with a reference number.\n\nSome elements are simple -- VOLUME, for example, has only one attribute and two possible child elements. Other elements are complex -- AUTHORLIST, for example, has numerous possible child elements with many associated attributes. See help topic <Using this utility> for notes on the help available while using this utility.\n\nThe second type of element specifies formatting and punctuation. These elements include FOLLOWING, PRECEDING and SEPARATOR. FOLLOWING and PRECEDING are associated with parent elements. They appear in a reference only if their parent element does. For example, you may specify the VOLUME element with a PRECEDING element containing 'Vol. '. If a particular reference of that type contains a volume, for example '10', it will appear in the bibliography as 'Vol. 10'. If a particular reference of that type does not contain a volume, the text 'Vol. ' will not appear in the bibliography reference. SEPARATOR, on the other hand, is not associated with any parent elements and will always appear in the reference. It should be used carefully, especially if nearby reference components may be missing from some references.\n\nSome elements can occur an unlimited number of times in each PUBTYPE, for example, PRECEDING, FOLLOWING and even VOLUME and ISSUE. Others can occur a limited number of times: AUTHORLIST, for example, can occur no more than three times in a publication type, PUBDATE (publication date) no more than twice and TITLE no more than three times.\n\nAlthough there are 35 possible publication types you do not have to create a PUBTYPE for all of them. As mentioned above, if a publication type contains an element not found in a particular reference, that element (and associated elements) are simply \"dropped\" from the bibliography for that particular reference. PUBTYPE 'GEN' is the default publication type. You should create it first and then create PUBTYPES for any publication types whose requirements are not met by the 'GEN' PUBTYPE. For example, the 'GEN' PUBTYPE can be designed to meet the needs of an edited work -- it could contain two AUTHORLISTs and TITLEs, the first for the primary work and its authors and the second for the collection details and editors. It will then also serve the needs of books -- the secondary title and author/editor list will simply be left blank.\n\nWarning: Be careful assigning PRECEDING and FOLLOWING child elements to adjacent elements or you may end up with double punctuation in your references.\n\nTHIRD SECTION (CITSTYLE, INTEXTDEF, AUTHORONLY and YEARONLY elements)\nThese elements determine the formatting of in-text citations. RefDB provides for three types of citations: default (i.e., author-year), author-only and year only. The formatting of these citation types are handled, respectively, by the INTEXTDEF, AUTHORONLY and YEARONLY elements (and associated attributes and children elements). These elements follow a similar schema to that outlined for PUBTYPES: some elements specify the presence and order of citation components while other elements (and attributes) determine citation style.\n\nFOURTH SECTION (BIBSTYLE and BIBLIOTITLE elements)\nThe attributes associated with the BIBSTYLE element determine styling that affects the bibliography as a whole. The BIBLIOTITLE element determines the title of the bibliography/reference list.\n\n\nA final note:\nThe LINK and STYLESET elements are not available for selection using this utility. Trust me, you won't need them."; + "HELP TOPIC: Styles\n\nAs mentioned in help topic <RefDB> \"styles\" provide rules for RefDB to follow when formatting bibliographies and citations. Each style is defined in an XML document that conforms to the \"citestylex\" DTD (see help topic <XML> for the briefest of introductions to XML). It will be most advantageous to have some understanding of XML before attempting to use this utility.\n\nEach style file can be divided broadly into four sections.\n\nFIRST SECTION (STYLENAME element)\nThe first section specifies the xml version, the controlling DTD and the style name. It includes the STYLENAME element.\n\nSECOND SECTION (REFSTYLE and PUBSTYLE elements)\nThe second section contains formatting rules for bibliography references. The REFSTYLE element includes a number of PUBSTYLE elements. Each PUBSTYLE element contains a number of subsidiary elements. Each PUBSTYLE element and its children specify formatting rules for a particular type of publication. There are 35 possible publication types, including book, journal and electronic citation. The publication type each PUBTYPE applies to is determined by PUBTYPE's TYPE attribute.\n\nThere are two kinds of elements in each PUBTYPE. One type specifies a component of the reference, for example, the TITLE element signifies the title of each reference work and the AUTHORLIST signifies the list of authors of a given work. These elements have a one-to-one correspondence with reference record ris fields. For example, the VOLUME element corresponds to the ris VL field. (See help topic <Using this utility> for how to access this information while creating your style.) Their presence in the PUBTYPE signifies the presence of the associated component in the bibliography reference. Also, their location in the PUBTYPE signifies the location of the associated component in the bibliography reference. For example, if you put AUTHORLIST first in a PUBTYPE, then the authors will appear first in the reference. If you put REFNUMBER first, the reference will begin with a reference number.\n\nSome elements are simple -- VOLUME, for example, has only one attribute and two possible child elements. Other elements are complex -- AUTHORLIST, for example, has numerous possible child elements with many associated attributes. See help topic <Using this utility> for notes on the help available while using this utility.\n\nThe second type of element specifies formatting and punctuation. These elements include FOLLOWING, PRECEDING and SEPARATOR. FOLLOWING and PRECEDING are associated with parent elements. They appear in a reference only if their parent element does. For example, you may specify the VOLUME element with a PRECEDING element containing 'Vol. '. If a particular reference of that type contains a volume, for example '10', it will appear in the bibliography as 'Vol. 10'. If a particular reference of that type does not contain a volume, the text 'Vol. ' will not appear in the bibliography reference. SEPARATOR, on the other hand, is not associated with any parent elements and will always appear in the reference. It should be used carefully, especially if nearby reference components may be missing from some references.\n\nSome elements can occur an unlimited number of times in each PUBTYPE, for example, PRECEDING, FOLLOWING and even VOLUME and ISSUE. Others can occur a limited number of times: AUTHORLIST, for example, can occur no more than three times in a publication type, PUBDATE (publication date) no more than twice and TITLE no more than three times.\n\nAlthough there are 35 possible publication types you do not have to create a PUBTYPE for all of them. As mentioned above, if a publication type contains an element not found in a particular reference, that element (and associated elements) are simply \"dropped\" from the bibliography for that particular reference. PUBTYPE 'GEN' is the default publication type. You should create it first and then create PUBTYPES for any publication types whose requirements are not met by the 'GEN' PUBTYPE. For example, the 'GEN' PUBTYPE can be designed to meet the needs of an edited work -- it could contain two AUTHORLISTs and TITLEs, the first for the primary work and its authors and the second for the collection details and editors. It will then also serve the needs of books -- the secondary title and author/editor list will simply be left blank.\n\nWarning: Be careful assigning PRECEDING and FOLLOWING child elements to adjacent elements or you may end up with double punctuation in your references.\n\nTHIRD SECTION (CITSTYLE, INTEXTDEF, AUTHORONLY and YEARONLY elements)\nThese elements determine the formatting of in-text citations. RefDB provides for three types of citations: default (i.e., author-year), author-only and year only. The formatting of these citation types are handled, respectively, by the INTEXTDEF, AUTHORONLY and YEARONLY elements (and associated attributes and children elements). These elements follow a similar schema to that outlined for PUBTYPES: some elements specify the presence and order of citation components while other elements (and attributes) determine citation style.\n\nFOURTH SECTION (BIBSTYLE and BIBLIOTITLE elements)\nThe attributes associated with the BIBSTYLE element determine styling that affects the bibliography as a whole. The BIBLIOTITLE element determines the title of the bibliography/reference list.\n\n\nA final note:\nThe STYLESET element is not available for selection using this utility. Trust me, you won't need it."; $cache->{"4. Using this utility"} = "HELP TOPIC: Using this utility\n\nIn short, this utility consists of a loop in which you are asked to:\n\n - select an element from a list of elements allowed in that part of the style,\n - enter or select appropriate values for mandatory attributes,\n - select optional attributes for that element and enter their values,\n - select an element from a list of elements ...\n\nThis process ends when you have exhausted the DTD (see section <XML>).\n\nEvery time you are presented with a list of elements you have the option of selecting help. Doing so will present a screen with a summary of each element on the list. The same thing happens when you are presented with a list of attributes.\n\nWhen an attribute or element is required by the DTD this utility will select it automatically. For some objects you will not need to provide input and so this utility will create the object(s) automatically. This can be disconcerting at first. Please read the console feedback carefully.\n\nWhenever you are asked to enter or select a value for an attribute or element, you are given a brief prompt explaining the purpose of the element or attribute.\n\nAfter each element is added to the style you are presented with a \"progress report\" showing the (major) elements. It may take a little while to understand this feedback. As you add elements they will be appended to the report. When you complete a major element, such as a PUBTYPE or AUTHORLIST, however, its subsidiary elements are no longer displayed -- they are \"folded\". This saves space and makes it easier to quickly understand where in the style you are at that point in time. As you become more familiar with the structure of the style DTD this display will become increasingly useful.\n\nAt certain times within PUBTYPE, AUTHORONLY, YEARONLY and INTEXTDEF elements you are able to delete the previous \"major\" element. \"Major\" elements are those corresponding to ris fields. These elements may contain other elements. For example, deleting an AUTHORLIST element will delete all the children elements of that author list style. You can view the complete element before deletion occurs.\n\nWhen you select some elements (in general, those corresponding to ris fields) you will be given an opportunity to copy the most recently entered element of that type. If you choose to copy, all attributes and sub-elements will be copied. This can save you a lot of time if, for example, your author lists will always have the same formatting.\n\nAfter you have created your style this utility will save it to a disk file. It will also generate a brief summary of it in html format. This summary can be of great help when entering references in your reference database.\n\nDepending on the version of this utility and the configuration of your system, this utility may offer to upload the style to RefDB. There is no foreseeable way in which this operation could damage your reference data, but you use it at your own risk..."; @@ -5811,5 +5896,5 @@ while ( 1 ) { $choice = $self->_input_choice( "Select help topic:" , @topics ); - if ( $choice ) { last; } + if ( defined( $choice ) ) { last; } print "Invalid choice. Sorry, please try again.\n"; } @@ -5836,5 +5921,5 @@ while ( 1 ) { $choice = $self->_input_choice( "Select help topic:" , @topics ); - if ( $choice ) { last; } + if ( defined( $choice ) ) { last; } print "Invalid choice. Sorry, please try again.\n"; } @@ -6131,5 +6216,5 @@ while ( 1 ) { $choice = $self->_input_choice( "\nHas refdba been configured to know your username and password? ('No' if unsure)" , ( "Yes" , "No" , "Abort" ) ); - if ( $choice ) { last; } + if ( defined( $choice ) ) { last; } print "Invalid choice. Sorry, please try again.\n"; } |